40#include "HDF4RequestHandler.h"
42const char *_BACK_SLASH=
"/";
48#define ERR_LOC2(x) ERR_LOC1(x)
49#define ERR_LOC __FILE__ " : " ERR_LOC2(__LINE__)
51template <
typename T,
typename U,
typename V,
typename W,
typename X >
static void
52_throw5 (
const char *fname,
int line,
int numarg,
53 const T & a1,
const U & a2,
const V & a3,
const W & a4,
const X & a5)
55 std::ostringstream ss;
56 ss << fname <<
":" << line <<
":";
57 for (
int i = 0; i < numarg; ++i) {
77 ss <<
" Argument number is beyond 5";
86#define throw1(a1) _throw5(__FILE__, __LINE__, 1, a1, 0, 0, 0, 0)
87#define throw2(a1, a2) _throw5(__FILE__, __LINE__, 2, a1, a2, 0, 0, 0)
88#define throw3(a1, a2, a3) _throw5(__FILE__, __LINE__, 3, a1, a2, a3, 0, 0)
89#define throw4(a1, a2, a3, a4) _throw5(__FILE__, __LINE__, 4, a1, a2, a3, a4, 0)
90#define throw5(a1, a2, a3, a4, a5) _throw5(__FILE__, __LINE__, 5, a1, a2, a3, a4, a5)
92#define assert_throw0(e) do { if (!(e)) throw1("assertion failure"); } while (false)
93#define assert_range_throw0(e, ge, l) assert_throw0((ge) <= (e) && (e) < (l))
99 template <
typename T >
void operator () (T * ptr)
111 if (this->sdfd != -1) {
121 if (this->fileid != -1) {
123 for (vector < VDATA * >::const_iterator i = this->
vds.begin ();
124 i != this->vds.end (); ++i) {
128 for (vector < AttrContainer * >::const_iterator i = this->
vg_attrs.begin ();
129 i != this->vg_attrs.end (); ++i) {
144 std::for_each (this->
vdfields.begin (), this->vdfields.end (),
148 std::for_each (this->
attrs.begin (), this->attrs.end (), delete_elem ());
155 std::for_each (this->
attrs.begin (), this->attrs.end (), delete_elem ());
158 std::for_each (this->
sdfields.begin (), this->sdfields.end (),
167 std::for_each (this->dims.begin (), this->dims.end (), delete_elem ());
170 std::for_each (this->correcteddims.begin (), this->correcteddims.end (),
174 std::for_each (this->dims_info.begin (), this->dims_info.end (), delete_elem ());
189 std::for_each (this->
attrs.begin (), this->attrs.end (), delete_elem ());
193AttrContainer::~AttrContainer()
195 std::for_each (this->attrs.begin (), this->attrs.end (), delete_elem ());
214 SDstart (
const_cast < char *
>(file->
path.c_str ()),
215 DFACC_READ)) == -1) {
217 throw2 (
"SDstart", path);
226 file->fileid = myfileid;
230 int32 status = Vstart (file->fileid);
231 if (status == FAIL) {
233 throw2 (
"Cannot start vdata/vgroup interface", path);
239 file->
sd =
SD::Read (file->sdfd, file->fileid);
263 throw1(
"Memory allocation for file class failed. ");
270 SDstart (
const_cast < char *
>(file->
path.c_str ()),
271 DFACC_READ)) == -1) {
273 throw2 (
"SDstart", path);
282 file->fileid = myfileid;
285 int status = Vstart (file->fileid);
286 if (status == FAIL) {
288 throw2 (
"Cannot start vdata/vgroup interface", path);
320 int status = Vstart (file->fileid);
322 throw2 (
"Cannot start vdata/vgroup interface", path);
326 int num_lone_vdata = VSlone (file->fileid, NULL, 0);
328 if (num_lone_vdata == FAIL)
329 throw2 (
"Fail to obtain lone vdata number", path);
335 char vdata_class[VSNAMELENMAX];
336 char vdata_name[VSNAMELENMAX];
338 if (num_lone_vdata > 0) {
340 vector<int32>ref_array;
341 ref_array.resize(num_lone_vdata);
343 if (VSlone (file->fileid, &ref_array[0], num_lone_vdata) == FAIL) {
344 throw2 (
"cannot obtain lone vdata reference arrays", path);
347 for (
int i = 0; i < num_lone_vdata; i++) {
351 vdata_id = VSattach (file->fileid, ref_array[i],
"r");
352 if (vdata_id == FAIL) {
353 throw2 (
"Fail to attach Vdata", path);
355 status = VSgetclass (vdata_id, vdata_class);
356 if (status == FAIL) {
358 throw2 (
"Fail to obtain Vdata class", path);
361 if (VSgetname (vdata_id, vdata_name) == FAIL) {
363 throw3 (
"Fail to obtain Vdata name", path, vdata_name);
368 if (VSisattr (vdata_id) == TRUE
369 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
370 strlen (_HDF_CHK_TBL_CLASS))
371 || !strncmp (vdata_class, _HDF_SDSVAR, strlen (_HDF_SDSVAR))
372 || !strncmp (vdata_class, _HDF_CRDVAR, strlen (_HDF_CRDVAR))
373 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
374 || !strncmp (vdata_class, DIM_VALS01, strlen (DIM_VALS01))
375 || !strncmp (vdata_class, RIGATTRCLASS, strlen (RIGATTRCLASS))
376 || !strncmp (vdata_name, RIGATTRNAME, strlen (RIGATTRNAME))) {
378 status = VSdetach (vdata_id);
379 if (status == FAIL) {
380 throw3 (
"VSdetach failed ",
"Vdata name ", vdata_name);
385 VDATA*vdataobj = NULL;
399 for (std::vector < VDField * >::const_iterator it_vdf =
401 it_vdf != vdataobj->
getFields ().end (); it_vdf++) {
406 "vdata_" + vdataobj->
newname +
"_vdf_" +
415 file->vds.push_back (vdataobj);
429 (vdata_name, CERE_META_NAME, strlen (CERE_META_NAME))) {
431 char *fieldname = NULL;
434 int num_field = VFnfields (vdata_id);
435 if (num_field == FAIL) {
437 throw3 (
"number of fields at Vdata ", vdata_name,
" is -1");
441 for (
int j = 0; j < num_field; j++) {
443 fieldname = VFfieldname (vdata_id, j);
444 if (fieldname == NULL) {
446 throw5 (
"vdata ", vdata_name,
" field index ", j,
447 " field name is NULL.");
451 else if (!strcmp (fieldname, CERE_META_FIELD_NAME)) {
453 int32 fieldsize = -1;
457 fieldsize = VFfieldesize (vdata_id, j);
458 if (fieldsize == FAIL) {
460 throw5 (
"vdata ", vdata_name,
" field ",fieldname,
" size is wrong.");
464 nelms = VSelts (vdata_id);
467 throw5 (
"vdata ", vdata_name,
468 " number of field record ", nelms,
" is wrong.");
472 bool data_buf_err =
false;
473 bool VS_fun_err =
false;
476 char *databuf = (
char *) malloc (fieldsize * nelms);
477 if (databuf == NULL) {
478 err_msg = string(ERR_LOC) +
"No enough memory to allocate buffer.";
484 if (VSseek (vdata_id, 0) == FAIL) {
485 err_msg = string(ERR_LOC) +
"VSseek failed";
491 if (VSsetfields (vdata_id, CERE_META_FIELD_NAME) == FAIL) {
492 err_msg =
"VSsetfields failed";
498 if (VSread(vdata_id, (uint8 *) databuf, 1,FULL_INTERLACE)
500 err_msg =
"VSread failed";
506 if (!strncmp(databuf, CER_AVG_NAME,strlen (CER_AVG_NAME)))
507 file->sptype = CER_AVG;
509 (databuf, CER_ES4_NAME,strlen(CER_ES4_NAME)))
510 file->sptype = CER_ES4;
512 (databuf, CER_CDAY_NAME,strlen (CER_CDAY_NAME)))
513 file->sptype = CER_CDAY;
515 (databuf, CER_CGEO_NAME,strlen (CER_CGEO_NAME)))
516 file->sptype = CER_CGEO;
518 (databuf, CER_SRB_NAME,strlen (CER_SRB_NAME)))
519 file->sptype = CER_SRB;
521 (databuf, CER_SYN_NAME,strlen (CER_SYN_NAME)))
522 file->sptype = CER_SYN;
524 (databuf, CER_ZAVG_NAME,
525 strlen (CER_ZAVG_NAME)))
526 file->sptype = CER_ZAVG;
529 if(data_buf_err ==
true || VS_fun_err ==
true) {
531 if(data_buf_err ==
true)
535 throw5(
"vdata ",vdata_name,
"field ",
536 CERE_META_FIELD_NAME,err_msg);
558 int32 vgroup_id = -1;
566 int32 lone_vg_number = 0;
567 int32 num_of_lones = -1;
568 int32 num_gobjects = 0;
573 char vdata_name[VSNAMELENMAX];
574 char vdata_class[VSNAMELENMAX];
575 char vgroup_name[VGNAMELENMAX*4];
576 char vgroup_class[VGNAMELENMAX*4];
579 char *full_path = NULL;
582 char *cfull_path = NULL;
585 file_id = file->fileid;
590 status = Vstart (file_id);
592 throw2 (
"Cannot start vdata/vgroup interface", path);
598 num_of_lones = Vlone (file_id, NULL, 0);
599 if (num_of_lones == FAIL)
600 throw3 (
"Fail to obtain lone vgroup number",
"file id is", file_id);
603 if (num_of_lones > 0) {
609 vector<int32>ref_array;
610 ref_array.resize(num_of_lones);
614 num_of_lones = Vlone (file_id, &ref_array[0], num_of_lones);
615 if (num_of_lones == FAIL) {
616 throw3 (
"Cannot obtain lone vgroup reference arrays ",
617 "file id is ", file_id);
621 for (lone_vg_number = 0; lone_vg_number < num_of_lones;
625 vgroup_id = Vattach (file_id, ref_array[lone_vg_number],
"r");
626 if (vgroup_id == FAIL) {
627 throw3 (
"Vattach failed ",
"Reference number is ",
628 ref_array[lone_vg_number]);
632 status = Vgetname (vgroup_id, vgroup_name);
633 if (status == FAIL) {
635 throw3 (
"Vgetname failed ",
"vgroup_id is ", vgroup_id);
639 status = Vgetclass (vgroup_id, vgroup_class);
640 if (status == FAIL) {
642 throw3 (
"Vgetclass failed ",
"vgroup_name is ", vgroup_name);
646 if (strcmp (vgroup_class, _HDF_ATTRIBUTE) == 0
647 || strcmp (vgroup_class, _HDF_VARIABLE) == 0
648 || strcmp (vgroup_class, _HDF_DIMENSION) == 0
649 || strcmp (vgroup_class, _HDF_UDIMENSION) == 0
650 || strcmp (vgroup_class, _HDF_CDF) == 0
651 || strcmp (vgroup_class, GR_NAME) == 0
652 || strcmp (vgroup_class, RI_NAME) == 0) {
658 num_gobjects = Vntagrefs (vgroup_id);
659 if (num_gobjects < 0) {
661 throw3 (
"Vntagrefs failed ",
"vgroup_name is ", vgroup_name);
666 bool VS_or_mem_err =
false;
672 full_path = (
char *) malloc (MAX_FULL_PATH_LEN);
673 if (full_path == NULL) {
674 err_msg =
"No enough memory to allocate the buffer for full_path.";
675 VS_or_mem_err =
true;
682 memset(full_path,
'\0',MAX_FULL_PATH_LEN);
685 strncpy (full_path,_BACK_SLASH,strlen(_BACK_SLASH));
686 strncat(full_path,vgroup_name,strlen(vgroup_name));
687 strncat(full_path,_BACK_SLASH,strlen(_BACK_SLASH));
690 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
691 if (cfull_path == NULL) {
694 err_msg =
"No enough memory to allocate the buffer for cfull_path.";
695 VS_or_mem_err =
true;
701 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
702 strncpy(cfull_path,full_path,strlen(full_path));
706 for (
int i = 0; i < num_gobjects; i++) {
709 if (Vgettagref (vgroup_id, i, &obj_tag, &obj_ref) == FAIL) {
710 err_msg =
"Vgettagref failed";
711 VS_or_mem_err =
true;
722 if (Visvg (vgroup_id, obj_ref) == TRUE) {
723 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
724 full_path[strlen(cfull_path)]=
'\0';
725 obtain_vdata_path (file_id, full_path, obj_ref);
729 else if (Visvs (vgroup_id, obj_ref)) {
732 vdata_id = VSattach (file_id, obj_ref,
"r");
733 if (vdata_id == FAIL) {
734 err_msg =
"VSattach failed";
735 VS_or_mem_err =
true;
740 status = VSgetname (vdata_id, vdata_name);
741 if (status == FAIL) {
742 err_msg =
"VSgetname failed";
743 VS_or_mem_err =
true;
748 status = VSgetclass (vdata_id, vdata_class);
749 if (status == FAIL) {
750 err_msg =
"VSgetclass failed";
751 VS_or_mem_err =
true;
756 if (VSisattr (vdata_id) == TRUE
757 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
758 strlen (_HDF_CHK_TBL_CLASS))
759 || !strncmp (vdata_class, _HDF_SDSVAR,
760 strlen (_HDF_SDSVAR))
761 || !strncmp (vdata_class, _HDF_CRDVAR,
762 strlen (_HDF_CRDVAR))
763 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
764 || !strncmp (vdata_class, DIM_VALS01,
766 || !strncmp (vdata_class, RIGATTRCLASS,
767 strlen (RIGATTRCLASS))
768 || !strncmp (vdata_name, RIGATTRNAME,
769 strlen (RIGATTRNAME))) {
771 status = VSdetach (vdata_id);
772 if (status == FAIL) {
773 err_msg =
"VSdetach failed in the if block to ignore the HDF4 internal attributes.";
774 VS_or_mem_err =
true;
782 VDATA *vdataobj = NULL;
794 if(full_path != NULL)
800 for (std::vector <VDField * >::const_iterator it_vdf =
809 "vdata" + vdataobj->
newname +
"_vdf_" + (*it_vdf)->name;
821 this->vds.push_back (vdataobj);
823 status = VSdetach (vdata_id);
824 if (status == FAIL) {
825 err_msg =
"VSdetach failed in the user-defined vdata block";
826 VS_or_mem_err =
true;
839 if(full_path != NULL)
841 if(cfull_path != NULL)
844 status = Vdetach (vgroup_id);
845 if (status == FAIL) {
846 throw3 (
"Vdetach failed ",
"vgroup_name is ", vgroup_name);
848 if(
true == VS_or_mem_err)
849 throw3(err_msg,
"vgroup_name is ",vgroup_name);
866File::Check_update_special(
const string& grid_name)
throw(
Exception) {
868 set<string> dimnameset;
869 set<SDField*> fldset;
882 FullXDim= FullXDim+grid_name;
883 FullYDim =FullYDim+grid_name;
885 for (vector < SDField * >::const_iterator i =
886 this->sd->getFields ().begin ();
887 i != this->sd->getFields ().end (); ++i) {
889 for (vector < Dimension * >::const_iterator k =
890 (*i)->getDimensions ().begin ();
891 k != (*i)->getDimensions ().end (); ++k) {
892 if((*k)->getName() !=FullXDim && (*k)->getName()!=FullYDim)
893 dimnameset.insert((*k)->getName());
896 if (1==(*i)->getRank())
905 if (fldset.size() < (dimnameset.size()+2))
908 int total_num_dims = 0;
909 size_t grid_name_size = grid_name.size();
910 string reduced_dimname;
912 for(set<SDField*>::const_iterator j =
913 fldset.begin(); j!=fldset.end(); ++ j) {
915 size_t dim_size = ((*j)->getDimensions())[0]->getName().size();
916 if( dim_size > grid_name_size){
917 reduced_dimname = ((*j)->getDimensions())[0]->getName().substr(0,dim_size-grid_name_size-1);
918 if ((*j)->getName() == reduced_dimname)
923 if((
size_t)total_num_dims != (dimnameset.size()+2))
927 for (vector < SDField * >::const_iterator i =
928 this->sd->getFields ().begin ();
929 i != this->sd->getFields ().end (); ++i) {
931 for (vector < Dimension * >::const_iterator k =
932 (*i)->getDimensions ().begin ();
933 k != (*i)->getDimensions ().end (); ++k) {
935 size_t dim_size = (*k)->getName().size();
936 if( dim_size > grid_name_size){
937 reduced_dimname = (*k)->getName().substr(0,dim_size-grid_name_size-1);
938 (*k)->name = reduced_dimname;
947 for(std::set<SDField*>::const_iterator j =
948 fldset.begin(); j!=fldset.end(); ++ j) {
950 if ((*j)->getName() == ((*j)->getDimensions())[0]->getName()) {
952 if(
"XDim" == (*j)->getName()){
953 std::string tempunits =
"degrees_east";
954 (*j)->setUnits (tempunits);
958 else if(
"YDim" == (*j)->getName()){
959 std::string tempunits =
"degrees_north";
960 (*j)->setUnits (tempunits);
964 else if(
"Pressure_Level" == (*j)->getName()) {
965 std::string tempunits =
"hPa";
966 (*j)->setUnits (tempunits);
970 std::string tempunits =
"level";
971 (*j)->setUnits (tempunits);
989File::Check_if_special(
const string& grid_name)
throw(
Exception) {
992 bool xdim_is_lon =
false;
993 bool ydim_is_lat =
false;
994 bool pre_unit_hpa =
true;
995 for (vector < SDField * >::const_iterator i =
996 this->sd->getFields ().begin ();
997 i != this->sd->getFields ().end (); ++i) {
998 if (1==(*i)->getRank()) {
999 if(1 == ((*i)->fieldtype)) {
1000 if(
"YDim" == (*j)->getName()
1009File::Handle_AIRS_L23() throw(
Exception) {
1013 bool airs_l3 =
true;
1014 if(basename(file->
path).find(
".L2.")!=string::npos)
1018 set<string> scaled_dname_set;
1021 set<string> non_scaled_dname_set;
1022 pair<set<string>::iterator,
bool> ret;
1025 map<string,int> non_scaled_dname_to_size;
1029 for (std::vector < SDField * >::const_iterator i =
1032 string tempname = (*i)->name;
1033 size_t found_colon = tempname.find_first_of(
':');
1034 if(found_colon!=string::npos)
1035 (*i)->newname = tempname.substr(0,found_colon);
1037 for (vector < Dimension * >::const_iterator k =
1038 (*i)->getDimensions ().begin ();
1039 k != (*i)->getDimensions ().end (); ++k) {
1041 tempname = (*k)->name;
1042 found_colon = tempname.find_first_of(
':');
1043 if(found_colon!=string::npos)
1044 (*k)->name = tempname.substr(0,found_colon);
1046 if(0==(*k)->getType()) {
1047 ret = non_scaled_dname_set.insert((*k)->name);
1048 if (
true == ret.second)
1049 non_scaled_dname_to_size[(*k)->name] = (*k)->dimsize;
1052 scaled_dname_set.insert((*k)->name);
1059for(set<string>::const_iterator sdim_it = scaled_dname_set.begin();
1060 sdim_it !=scaled_dname_set.end();
1062cerr<<
"scaled dim. name "<<*sdim_it <<endl;
1074 if(
true == airs_l3) {
1075 set<string>scaled_dname_set_marker = scaled_dname_set;
1084 for (std::vector < SDField * >::iterator i =
1086 if(1 == (*i)->getRank()) {
1087 if(scaled_dname_set.find((*i)->getNewName())!=scaled_dname_set.end()) {
1088 if(scaled_dname_set_marker.find((*i)->getNewName())!=scaled_dname_set_marker.end()) {
1089 scaled_dname_set_marker.erase((*i)->getNewName());
1103 else if( 2 == (*i)->getRank()) {
1104 if (
"Latitude" == (*i)->getNewName() ||
"Longitude" == (*i)->getNewName()) {
1118for(set<string>::const_iterator sdim_it = scaled_dname_set.begin();
1119 sdim_it !=scaled_dname_set.end();
1121cerr<<
"new scaled dim. name "<<*sdim_it <<endl;
1129 set<string>final_non_scaled_dname_set;
1130 for(set<string>::const_iterator non_sdim_it = non_scaled_dname_set.begin();
1131 non_sdim_it !=non_scaled_dname_set.end();
1134 if(scaled_dname_set.find(*non_sdim_it)==scaled_dname_set.end())
1135 final_non_scaled_dname_set.insert(*non_sdim_it);
1139 for(set<string>::const_iterator non_sdim_it = final_non_scaled_dname_set.begin();
1140 non_sdim_it !=final_non_scaled_dname_set.end();
1147 missingfield->
type = DFNT_INT32;
1148 missingfield->
name = *non_sdim_it;
1149 missingfield->
newname = *non_sdim_it;
1150 missingfield->
rank = 1;
1151 missingfield->fieldtype = 4;
1152 missingfield->setUnits(
"level");
1153 Dimension *dim =
new Dimension (*non_sdim_it,non_scaled_dname_to_size[*non_sdim_it] , 0);
1155 missingfield->dims.push_back (dim);
1162 if(
true == airs_l3) {
1163 for (std::vector < SDField * >::const_iterator i =
1166 if(1 ==(*i)->getRank()){
1167 if (
"XDim" == (*i)->newname)
1168 (*i)->newname =
"Longitude";
1169 else if (
"YDim" == (*i)->newname)
1170 (*i)->newname =
"Latitude";
1173 for (vector < Dimension * >::const_iterator k =
1174 (*i)->getDimensions ().begin ();
1175 k != (*i)->getDimensions ().end (); ++k) {
1176 if(
"XDim" == (*k)->name)
1177 (*k)->name =
"Longitude";
1178 else if (
"YDim" == (*k)->name)
1179 (*k)->name =
"Latitude";
1186 if(
false == airs_l3) {
1188 bool change_lat_unit =
false;
1189 bool change_lon_unit =
false;
1190 string ll_dimname1 =
"";
1191 string ll_dimname2 =
"";
1195 for (std::vector < SDField * >::const_iterator i =
1198 if(2 == (*i)->getRank()) {
1199 if(
"Latitude" == (*i)->newname){
1200 (*i)->fieldtype = 1;
1201 change_lat_unit =
true;
1202 string tempunits =
"degrees_north";
1203 (*i)->setUnits(tempunits);
1204 ll_dimname1 = (*i)->getDimensions()[0]->getName();
1205 ll_dimname2 = (*i)->getDimensions()[1]->getName();
1208 else if(
"Longitude" == (*i)->newname) {
1209 (*i)->fieldtype = 2;
1210 change_lon_unit =
true;
1211 string tempunits =
"degrees_east";
1212 (*i)->setUnits(tempunits);
1214 if((
true == change_lat_unit) && (
true == change_lon_unit))
1220 string tempcoordinates =
"";
1221 string tempfieldname =
"";
1224 for (std::vector < SDField * >::const_iterator i =
1228 bool dimscale_var =
false;
1229 dimscale_var = ((*i)->rank == 1) & (((*i)->newname) == ((*i)->getDimensions()[0]->getName()));
1231 if((0 ==(*i)->fieldtype) && (
false == dimscale_var)) {
1234 tempcoordinates =
"";
1238 bool has_lldim1 =
false;
1239 bool has_lldim2 =
false;
1240 for (std::vector < Dimension * >::const_iterator j =
1241 (*i)->getDimensions ().begin ();
1242 j != (*i)->getDimensions ().end (); ++j) {
1243 if((*j)->name == ll_dimname1)
1245 else if ((*j)->name == ll_dimname2)
1247 if((
true == has_lldim1) && (
true == has_lldim2))
1253 if((
true == has_lldim1) && (
true == has_lldim2)) {
1254 for (std::vector < Dimension * >::const_iterator j =
1255 (*i)->getDimensions ().begin ();
1256 j != (*i)->getDimensions ().end (); ++j) {
1257 if((*j)->name == ll_dimname1)
1258 tempfieldname =
"Latitude";
1259 else if ((*j)->name == ll_dimname2)
1260 tempfieldname =
"Longitude";
1262 tempfieldname = (*j)->name;
1265 tempcoordinates = tempfieldname;
1267 tempcoordinates = tempcoordinates +
" " + tempfieldname;
1272 for (std::vector < Dimension * >::const_iterator j =
1273 (*i)->getDimensions ().begin ();
1274 j != (*i)->getDimensions ().end (); ++j) {
1276 tempcoordinates = (*j)->name;
1278 tempcoordinates = tempcoordinates +
" " + (*j)->name;
1283 (*i)->setCoordinates (tempcoordinates);
1301 if (this->sptype == OTHERHDF) {
1303 int trmm_multi_gridflag = 0;
1304 int trmm_single_gridflag = 0;
1305 int trmm_swathflag = 0;
1307 for (std::vector < Attribute * >::const_iterator i =
1309 i != this->sd->getAttributes ().end (); ++i) {
1310 if ((*i)->getName () ==
"FileHeader") {
1311 trmm_multi_gridflag++;
1312 trmm_single_gridflag++;
1315 if ((*i)->getName () ==
"FileInfo") {
1316 trmm_multi_gridflag++;
1317 trmm_single_gridflag++;
1320 if ((*i)->getName () ==
"SwathHeader")
1323 if ((*i)->getName () ==
"GridHeader")
1324 trmm_single_gridflag++;
1326 else if (((*i)->getName ().find (
"GridHeader") == 0) &&
1327 (((*i)->getName()).size() >10))
1328 trmm_multi_gridflag++;
1333 if(3 == trmm_single_gridflag)
1334 this->sptype = TRMML3S_V7;
1335 else if(3 == trmm_swathflag)
1336 this->sptype = TRMML2_V7;
1337 else if(trmm_multi_gridflag >3)
1338 this->sptype = TRMML3M_V7;
1344 if (this->sptype == OTHERHDF) {
1346 int metadataflag = 0;
1348 for (std::vector < Attribute * >::const_iterator i =
1350 i != this->sd->getAttributes ().end (); ++i) {
1351 if ((*i)->getName () ==
"CoreMetadata.0")
1353 if ((*i)->getName () ==
"ArchiveMetadata.0")
1355 if ((*i)->getName () ==
"StructMetadata.0")
1357 if ((*i)->getName ().find (
"SubsettingMethod") !=
1366 if (metadataflag == 4)
1367 this->sptype = MODISARNSS;
1371 if (metadataflag == 2) {
1373 for (std::vector < SDField * >::const_iterator i =
1375 i != this->sd->getFields ().end (); ++i) {
1376 if (((*i)->getName () ==
"geolocation")
1377 && (*i)->getNewName ().find (
"DATA_GRANULE") !=
1379 && (*i)->getNewName ().find (
"SwathData") !=
1380 std::string::npos && (*i)->getRank () == 3) {
1381 this->sptype = TRMML2_V6;
1394 if (this->sptype == OTHERHDF) {
1395 for (std::vector < SDField * >::const_iterator i =
1397 i != this->sd->getFields ().end (); ++i) {
1398 if ((*i)->getNewName ().find (
"DATA_GRANULE") !=
1399 std::string::npos) {
1400 bool l3b_v6_lonflag =
false;
1401 bool l3b_v6_latflag =
false;
1402 for (std::vector < Dimension * >::const_iterator k =
1403 (*i)->getDimensions ().begin ();
1404 k != (*i)->getDimensions ().end (); ++k) {
1405 if ((*k)->getSize () == 1440)
1406 l3b_v6_lonflag =
true;
1408 if ((*k)->getSize () == 400)
1409 l3b_v6_latflag =
true;
1411 if (l3b_v6_lonflag ==
true && l3b_v6_latflag ==
true) {
1412 this->sptype = TRMML3B_V6;
1417 bool l3a_v6_latflag =
false;
1418 bool l3a_v6_lonflag =
false;
1420 bool l3c_v6_lonflag =
false;
1421 bool l3c_v6_latflag =
false;
1423 if ((*i)->getRank()>2) {
1424 for (std::vector < Dimension * >::const_iterator k =
1425 (*i)->getDimensions ().begin ();
1426 k != (*i)->getDimensions ().end (); ++k) {
1427 if ((*k)->getSize () == 360)
1428 l3a_v6_lonflag =
true;
1430 if ((*k)->getSize () == 180)
1431 l3a_v6_latflag =
true;
1433 if ((*k)->getSize () == 720)
1434 l3c_v6_lonflag =
true;
1436 if ((*k)->getSize () == 148)
1437 l3c_v6_latflag =
true;
1442 if (
true == l3a_v6_latflag &&
true == l3a_v6_lonflag) {
1443 this->sptype = TRMML3A_V6;
1447 if (
true == l3c_v6_latflag &&
true == l3c_v6_lonflag) {
1448 this->sptype = TRMML3C_V6;
1459if(this->sptype == TRMML3A_V6)
1460cerr<<
"3A46 products "<<endl;
1461if(this->sptype == TRMML3C_V6)
1462cerr<<
"CSH products "<<endl;
1474 if (this->sptype == OTHERHDF) {
1477 int modisal2flag = 0;
1480 int modistl2flag = 0;
1486 int seawifsl2flag = 0;
1492 int modisal3mflag = 0;
1495 int modistl3mflag = 0;
1498 int octsl3mflag = 0;
1501 int seawifsl3mflag = 0;
1504 int czcsl3mflag = 0;
1509 for (std::vector < Attribute * >::const_iterator i =
1511 i != this->sd->getAttributes ().end (); ++i) {
1512 if ((*i)->getName () ==
"Product Name") {
1514 std::string attrvalue ((*i)->getValue ().begin (),
1515 (*i)->getValue ().end ());
1516 if ((attrvalue.find_first_of (
'A', 0) == 0)
1517 && (attrvalue.find (
".L2", 0) != std::string::npos))
1519 else if ((attrvalue.find_first_of (
'A', 0) == 0)
1520 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1522 else if ((attrvalue.find_first_of (
'T', 0) == 0)
1523 && (attrvalue.find (
".L2", 0) != std::string::npos))
1525 else if ((attrvalue.find_first_of (
'T', 0) == 0)
1526 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1528 else if ((attrvalue.find_first_of (
'O', 0) == 0)
1529 && (attrvalue.find (
".L2", 0) != std::string::npos))
1531 else if ((attrvalue.find_first_of (
'O', 0) == 0)
1532 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1534 else if ((attrvalue.find_first_of (
'S', 0) == 0)
1535 && (attrvalue.find (
".L2", 0) != std::string::npos))
1537 else if ((attrvalue.find_first_of (
'S', 0) == 0)
1538 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1540 else if ((attrvalue.find_first_of (
'C', 0) == 0)
1541 && ((attrvalue.find (
".L2", 0) != std::string::npos)
1543 (attrvalue.find (
".L1A", 0) != std::string::npos)))
1545 else if ((attrvalue.find_first_of (
'C', 0) == 0)
1546 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1552 if ((*i)->getName () ==
"Sensor Name") {
1554 std::string attrvalue ((*i)->getValue ().begin (),
1555 (*i)->getValue ().end ());
1556 if (attrvalue.find (
"MODISA", 0) != std::string::npos) {
1560 else if (attrvalue.find (
"MODIST", 0) != std::string::npos) {
1564 else if (attrvalue.find (
"OCTS", 0) != std::string::npos) {
1568 else if (attrvalue.find (
"SeaWiFS", 0) != std::string::npos) {
1572 else if (attrvalue.find (
"CZCS", 0) != std::string::npos) {
1581 if ((modisal2flag == 2) || (modisal3mflag == 2)
1582 || (modistl2flag == 2) || (modistl3mflag == 2)
1583 || (octsl2flag == 2) || (octsl3mflag == 2)
1584 || (seawifsl2flag == 2) || (seawifsl3mflag == 2)
1585 || (czcsl2flag == 2) || (czcsl3mflag == 2))
1591 if ((modisal2flag == 2) || (modistl2flag == 2) ||
1592 (octsl2flag == 2) || (seawifsl2flag == 2) || (czcsl2flag == 2))
1593 this->sptype = OBPGL2;
1595 if ((modisal3mflag == 2) ||
1596 (modistl3mflag == 2) || (octsl3mflag == 2) ||
1597 (seawifsl3mflag == 2) || (czcsl3mflag == 2))
1598 this->sptype = OBPGL3;
1616 int32 n_sd_attrs = 0;
1625 int32 dim_sizes[H4_MAX_VAR_DIMS];
1628 int32 n_sds_attrs = 0;
1634 char sds_name[H4_MAX_NC_NAME];
1637 char dim_name[H4_MAX_NC_NAME];
1640 char attr_name[H4_MAX_NC_NAME];
1656 int32 attr_value_count = 0;
1659 SD* sd =
new SD (sdfd, fileid);
1662 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL) {
1664 throw2 (
"SDfileinfo failed ", sdfd);
1668 for (sds_index = 0; sds_index < n_sds; sds_index++) {
1674 sds_id = SDselect (sdfd, sds_index);
1675 if (sds_id == FAIL) {
1679 SDendaccess (sds_id);
1680 throw3 (
"SDselect Failed ",
"SDS index ", sds_index);
1684 sds_ref = SDidtoref (sds_id);
1685 if (sds_ref == FAIL) {
1688 SDendaccess (sds_id);
1689 throw3 (
"Cannot obtain SDS reference number",
" SDS ID is ",
1694 status = SDgetinfo (sds_id, sds_name, &field->
rank, dim_sizes,
1695 &field->
type, &n_sds_attrs);
1696 if (status == FAIL) {
1699 SDendaccess (sds_id);
1700 throw2 (
"SDgetinfo failed ", sds_name);
1704 string tempname (sds_name);
1705 field->
name = tempname;
1707 field->fieldref = sds_ref;
1712 bool dim_no_dimscale =
false;
1713 vector <int> dimids;
1715 dimids.assign(field->
rank,0);
1718 vector <int>num_dim_attrs;
1720 num_dim_attrs.assign(field->
rank,0);
1723 for (
int dimindex = 0; dimindex < field->
rank; dimindex++) {
1726 int dimid = SDgetdimid (sds_id, dimindex);
1727 if (dimid == FAIL) {
1730 SDendaccess (sds_id);
1731 throw5 (
"SDgetdimid failed ",
"SDS name ", sds_name,
1732 "dim index= ", dimindex);
1736 int temp_num_dim_attrs = 0;
1738 SDdiminfo (dimid, dim_name, &dim_size, &dim_type,
1739 (int32*)&temp_num_dim_attrs);
1740 if (status == FAIL) {
1743 SDendaccess (sds_id);
1744 throw5 (
"SDdiminfo failed ",
"SDS name ", sds_name,
1745 "dim index= ", dimindex);
1748 num_dim_attrs[dimindex] = temp_num_dim_attrs;
1767 string dim_name_str (dim_name);
1772 new Dimension (dim_name_str, dim_sizes[dimindex], dim_type);
1775 field->dims.push_back (dim);
1779 dimids[dimindex] = dimid;
1780 if (0 == dim_type) {
1781 if (
false == dim_no_dimscale)
1782 dim_no_dimscale =
true;
1783 if ((dim_name_str == field->
name) && (1 == field->
rank))
1784 field->is_noscale_dim =
true;
1791 if(
true == dim_no_dimscale) {
1793 for (
int dimindex = 0; dimindex < field->
rank; dimindex++) {
1795 string dim_name_str = (field->dims)[dimindex]->name;
1798 stringstream out_index;
1799 out_index << dimindex;
1800 index_str = out_index.str();
1801 dim_info->name =
"_dim_" + index_str;
1805 bool dimname_flag =
false;
1807 int32 dummy_type = 0;
1808 int32 dummy_value_count = 0;
1811 for (
int attrindex = 0; attrindex < num_dim_attrs[dimindex]; attrindex++) {
1813 status = SDattrinfo(dimids[dimindex],attrindex,attr_name,
1814 &dummy_type,&dummy_value_count);
1815 if (status == FAIL) {
1818 SDendaccess (sds_id);
1819 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
1822 string tempname2(attr_name);
1823 if (
"name"==tempname2) {
1824 dimname_flag =
true;
1830 for (
int attrindex = 0; attrindex < num_dim_attrs[dimindex]; attrindex++) {
1833 status = SDattrinfo(dimids[dimindex],attrindex,attr_name,
1834 &attr->type,&attr_value_count);
1835 if (status == FAIL) {
1838 SDendaccess (sds_id);
1839 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
1841 string tempname3 (attr_name);
1842 attr->name = tempname3;
1845 attr->newname = tempname3;
1846 attr->count = attr_value_count;
1847 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
1848 if (SDreadattr (dimids[dimindex], attrindex, &attr->value[0]) == -1) {
1851 SDendaccess (sds_id);
1852 throw5 (
"read SDS attribute failed ",
"Field name ",
1853 field->
name,
" Attribute name ", attr->name);
1856 dim_info->attrs.push_back (attr);
1862 if (
false == dimname_flag) {
1865 attr->name =
"name";
1866 attr->newname =
"name";
1867 attr->type = DFNT_CHAR;
1868 attr->count = dim_name_str.size();
1869 attr->value.resize(attr->count);
1870 copy(dim_name_str.begin(),dim_name_str.end(),attr->value.begin());
1871 dim_info->attrs.push_back(attr);
1874 field->dims_info.push_back(dim_info);
1879 for (
int attrindex = 0; attrindex < n_sds_attrs; attrindex++) {
1882 SDattrinfo (sds_id, attrindex, attr_name, &attr->type,
1885 if (status == FAIL) {
1889 SDendaccess (sds_id);
1890 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
1894 string tempname4 (attr_name);
1895 attr->name = tempname4;
1898 attr->newname = tempname4;
1899 attr->count = attr_value_count;
1900 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
1901 if (SDreadattr (sds_id, attrindex, &attr->value[0]) == -1) {
1902 string temp_field_name = field->
name;
1903 string temp_attr_name = attr->name;
1907 SDendaccess (sds_id);
1908 throw5 (
"read SDS attribute failed ",
"Field name ",
1909 temp_field_name,
" Attribute name ", temp_attr_name);
1911 field->
attrs.push_back (attr);
1914 SDendaccess (sds_id);
1919 for (
int attrindex = 0; attrindex < n_sd_attrs; attrindex++) {
1922 status = SDattrinfo (sdfd, attrindex, attr_name, &attr->type,
1924 if (status == FAIL) {
1927 throw3 (
"SDattrinfo failed ",
"SD id ", sdfd);
1930 std::string tempname5 (attr_name);
1931 attr->name = tempname5;
1935 attr->newname = tempname5;
1936 attr->count = attr_value_count;
1937 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
1938 if (SDreadattr (sdfd, attrindex, &attr->value[0]) == -1) {
1941 throw3 (
"Cannot read SD attribute",
" Attribute name ",
1944 sd->
attrs.push_back (attr);
1964 int32 n_sd_attrs = 0;
1970 int extra_sds_index = 0;
1976 int32 dim_sizes[H4_MAX_VAR_DIMS];
1979 int32 n_sds_attrs = 0;
1985 char sds_name[H4_MAX_NC_NAME];
1988 char dim_name[H4_MAX_NC_NAME];
1991 char attr_name[H4_MAX_NC_NAME];
2004 int32 num_dim_attrs = 0;
2007 int32 attr_value_count = 0;
2011 int32 vgroup_id = 0;
2014 int32 lone_vg_number = 0;
2017 int32 num_of_lones = -1;
2019 int32 num_gobjects = 0;
2030 char vgroup_name[VGNAMELENMAX*4];
2031 char vgroup_class[VGNAMELENMAX*4];
2036 char *full_path = NULL;
2040 char *cfull_path = NULL;
2044 SD *sd =
new SD (sdfd, fileid);
2047 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL) {
2050 throw2 (
"SDfileinfo failed ", sdfd);
2055 for (sds_index = 0; sds_index < n_sds; sds_index++) {
2056 sds_id = SDselect (sdfd, sds_index);
2058 if (sds_id == FAIL) {
2063 SDendaccess (sds_id);
2064 throw3 (
"SDselect Failed ",
"SDS index ", sds_index);
2067 sds_ref = SDidtoref (sds_id);
2068 if (sds_ref == FAIL) {
2071 SDendaccess (sds_id);
2072 throw3 (
"Cannot obtain SDS reference number",
" SDS ID is ",
2076 SDendaccess(sds_id);
2085 num_of_lones = Vlone (fileid, NULL, 0);
2086 if (num_of_lones == FAIL){
2089 throw3 (
"Fail to obtain lone vgroup number",
"file id is", fileid);
2093 if (num_of_lones > 0) {
2097 vector<int32>ref_array;
2098 ref_array.resize(num_of_lones);
2102 num_of_lones = Vlone (fileid, &ref_array[0], num_of_lones);
2103 if (num_of_lones == FAIL) {
2106 throw3 (
"Cannot obtain lone vgroup reference arrays ",
2107 "file id is ", fileid);
2111 for (lone_vg_number = 0; lone_vg_number < num_of_lones;
2115 vgroup_id = Vattach (fileid, ref_array[lone_vg_number],
"r");
2116 if (vgroup_id == FAIL) {
2119 throw3 (
"Vattach failed ",
"Reference number is ",
2120 ref_array[lone_vg_number]);
2123 status = Vgetname (vgroup_id, vgroup_name);
2124 if (status == FAIL) {
2127 Vdetach (vgroup_id);
2128 throw3 (
"Vgetname failed ",
"vgroup_id is ", vgroup_id);
2131 status = Vgetclass (vgroup_id, vgroup_class);
2132 if (status == FAIL) {
2135 Vdetach (vgroup_id);
2136 throw3 (
"Vgetclass failed ",
"vgroup_name is ", vgroup_name);
2140 if (strcmp (vgroup_class, _HDF_ATTRIBUTE) == 0
2141 || strcmp (vgroup_class, _HDF_VARIABLE) == 0
2142 || strcmp (vgroup_class, _HDF_DIMENSION) == 0
2143 || strcmp (vgroup_class, _HDF_UDIMENSION) == 0
2144 || strcmp (vgroup_class, _HDF_CDF) == 0
2145 || strcmp (vgroup_class, GR_NAME) == 0
2146 || strcmp (vgroup_class, RI_NAME) == 0) {
2147 Vdetach (vgroup_id);
2152 num_gobjects = Vntagrefs (vgroup_id);
2153 if (num_gobjects < 0) {
2156 Vdetach (vgroup_id);
2157 throw3 (
"Vntagrefs failed ",
"vgroup_name is ", vgroup_name);
2170 full_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2171 if (full_path == NULL) {
2174 Vdetach (vgroup_id);
2176 throw1 (
"No enough memory to allocate the buffer.");
2179 memset(full_path,
'\0',MAX_FULL_PATH_LEN);
2180 strncpy(full_path,_BACK_SLASH,strlen(_BACK_SLASH));
2181 strncat(full_path, vgroup_name,strlen(vgroup_name));
2183 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2184 if (cfull_path == NULL) {
2187 Vdetach (vgroup_id);
2188 if(full_path != NULL)
2191 throw1 (
"No enough memory to allocate the buffer.");
2194 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
2195 strncpy (cfull_path, full_path,strlen(full_path));
2198 for (i = 0; i < num_gobjects; i++) {
2201 if (Vgettagref (vgroup_id, i, &obj_tag, &obj_ref) == FAIL) {
2204 Vdetach (vgroup_id);
2205 if(full_path != NULL)
2207 if(cfull_path != NULL)
2209 throw5 (
"Vgettagref failed ",
"vgroup_name is ",
2210 vgroup_name,
" reference number is ", obj_ref);
2214 if (Visvg (vgroup_id, obj_ref) == TRUE) {
2215 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
2216 full_path[strlen(cfull_path)]=
'\0';
2221 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
2222 || obj_tag == DFTAG_SD) {
2228 string temp_str = string(full_path);
2229 if((temp_str.find(
"Data Fields") != std::string::npos)||
2230 (temp_str.find(
"Geolocation Fields") != std::string::npos))
2244 status = Vdetach (vgroup_id);
2246 if (status == FAIL) {
2249 throw3 (
"Vdetach failed ",
"vgroup_name is ", vgroup_name);
2256 for(std::list<int32>::iterator sds_ref_it = sd->
sds_ref_list.begin();
2259 extra_sds_index = SDreftoindex(sdfd,*sds_ref_it);
2260 if(extra_sds_index == FAIL) {
2262 throw3(
"SDreftoindex Failed ",
"SDS reference number ", *sds_ref_it);
2266 sds_id = SDselect (sdfd, extra_sds_index);
2267 if (sds_id == FAIL) {
2271 SDendaccess (sds_id);
2272 throw3 (
"SDselect Failed ",
"SDS index ", extra_sds_index);
2276 status = SDgetinfo (sds_id, sds_name, &field->
rank, dim_sizes,
2277 &field->
type, &n_sds_attrs);
2278 if (status == FAIL) {
2281 SDendaccess (sds_id);
2282 throw2 (
"SDgetinfo failed ", sds_name);
2286 string tempname (sds_name);
2287 field->
name = tempname;
2289 field->
newname = tempname+
"_"+
"NONEOS";
2290 field->fieldref = *sds_ref_it;
2294 for (
int dimindex = 0; dimindex < field->
rank; dimindex++) {
2295 int dimid = SDgetdimid (sds_id, dimindex);
2296 if (dimid == FAIL) {
2299 SDendaccess (sds_id);
2300 throw5 (
"SDgetdimid failed ",
"SDS name ", sds_name,
2301 "dim index= ", dimindex);
2303 status = SDdiminfo (dimid, dim_name, &dim_size, &dim_type,
2306 if (status == FAIL) {
2309 SDendaccess (sds_id);
2310 throw5 (
"SDdiminfo failed ",
"SDS name ", sds_name,
2311 "dim index= ", dimindex);
2314 string dim_name_str (dim_name);
2319 new Dimension (dim_name_str, dim_sizes[dimindex], dim_type);
2321 field->dims.push_back (dim);
2341 new Dimension (cfdimname, dim_sizes[dimindex], dim_type);
2343 field->correcteddims.push_back (correcteddim);
2348 for (
int attrindex = 0; attrindex < n_sds_attrs; attrindex++) {
2352 status = SDattrinfo (sds_id, attrindex, attr_name, &attr->type,
2354 if (status == FAIL) {
2358 SDendaccess (sds_id);
2359 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
2362 string tempname (attr_name);
2363 attr->name = tempname;
2367 attr->newname = tempname;
2368 attr->count = attr_value_count;
2369 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
2370 if (SDreadattr (sds_id, attrindex, &attr->value[0]) == -1) {
2374 SDendaccess (sds_id);
2375 throw5 (
"read SDS attribute failed ",
"Field name ",
2376 field->
name,
" Attribute name ", attr->name);
2378 field->
attrs.push_back (attr);
2380 SDendaccess (sds_id);
2393 int32 fieldsize = 0;
2396 int32 fieldtype = 0;
2399 int32 fieldorder = 0;
2402 char *fieldname = NULL;
2406 char vdata_name[VSNAMELENMAX];
2408 VDATA *vdata =
new VDATA (vdata_id, obj_ref);
2410 vdata->
vdref = obj_ref;
2412 if (VSQueryname (vdata_id, vdata_name) == FAIL){
2414 throw3 (
"VSQueryname failed ",
"vdata id is ", vdata_id);
2417 string vdatanamestr (vdata_name);
2419 vdata->
name = vdatanamestr;
2421 int32 num_field = VFnfields (vdata_id);
2423 if (num_field == -1){
2425 throw3 (
"For vdata, VFnfields failed. ",
"vdata name is ",
2429 int32 num_record = VSelts (vdata_id);
2431 if (num_record == -1) {
2433 throw3 (
"For vdata, VSelts failed. ",
"vdata name is ", vdata->
name);
2441 string check_vdata_to_attr_key=
"H4.EnableVdata_to_Attr";
2442 bool turn_on_vdata_to_attr_key =
false;
2444 turn_on_vdata_to_attr_key = HDFCFUtil::check_beskeys(check_vdata_to_attr_key);
2452 if (num_record <= 10 &&
true == HDF4RequestHandler::get_enable_vdata_attr())
2458 for (
int i = 0; i < num_field; i++) {
2465 throw1(
"Memory allocation for field class failed.");
2468 fieldsize = VFfieldesize (vdata_id, i);
2469 if (fieldsize == FAIL) {
2470 string temp_vdata_name = vdata->
name;
2473 throw5 (
"For vdata field, VFfieldsize failed. ",
"vdata name is ",
2474 temp_vdata_name,
" index is ", i);
2477 fieldname = VFfieldname (vdata_id, i);
2478 if (fieldname == NULL) {
2479 string temp_vdata_name = vdata->
name;
2482 throw5 (
"For vdata field, VFfieldname failed. ",
"vdata name is ",
2483 temp_vdata_name,
" index is ", i);
2486 fieldtype = VFfieldtype (vdata_id, i);
2487 if (fieldtype == FAIL) {
2488 string temp_vdata_name = vdata->
name;
2491 throw5 (
"For vdata field, VFfieldtype failed. ",
"vdata name is ",
2492 temp_vdata_name,
" index is ", i);
2495 fieldorder = VFfieldorder (vdata_id, i);
2496 if (fieldorder == FAIL) {
2497 string temp_vdata_name = vdata->
name;
2500 throw5 (
"For vdata field, VFfieldtype failed. ",
"vdata name is ",
2501 temp_vdata_name,
" index is ", i);
2504 if(fieldname !=NULL)
2505 field->
name = fieldname;
2507 field->
type = fieldtype;
2508 field->order = fieldorder;
2509 field->size = fieldsize;
2511 field->numrec = num_record;
2518 field->value.resize (num_record * fieldsize);
2519 if (VSseek (vdata_id, 0) == FAIL) {
2524 throw5 (
"vdata ", vdata_name,
"field ", fieldname,
2528 if (VSsetfields (vdata_id, fieldname) == FAIL) {
2533 throw3 (
"vdata field ", fieldname,
" VSsetfields failed.");
2537 (vdata_id, (uint8 *) & field->value[0], num_record,
2538 FULL_INTERLACE) == FAIL){
2543 throw3 (
"vdata field ", fieldname,
" VSread failed.");
2582 char attr_name[H4_MAX_NC_NAME];
2594 nattrs = VSfnattrs (vdata_id, _HDF_VDATA);
2599 throw3 (
"VSfnattrs failed ",
"vdata id is ", vdata_id);
2605 for (
int i = 0; i < nattrs; i++) {
2609 status = VSattrinfo (vdata_id, _HDF_VDATA, i, attr_name,
2610 &attr->type, &attr->count, &attrsize);
2611 if (status == FAIL) {
2613 throw5 (
"VSattrinfo failed ",
"vdata id is ", vdata_id,
2614 " attr index is ", i);
2618 string tempname(attr_name);
2620 attr->name = tempname;
2622 attr->value.resize (attrsize);
2624 if (VSgetattr (vdata_id, _HDF_VDATA, i, &attr->value[0]) == FAIL) {
2626 throw5 (
"VSgetattr failed ",
"vdata id is ", vdata_id,
2627 " attr index is ", i);
2629 attrs.push_back (attr);
2644 char attr_name[H4_MAX_NC_NAME];
2656 nattrs = VSfnattrs (vdata_id, fieldindex);
2661 throw5 (
"VSfnattrs failed ",
"vdata id is ", vdata_id,
2662 "Field index is ", fieldindex);
2668 for (
int i = 0; i < nattrs; i++) {
2672 status = VSattrinfo (vdata_id, fieldindex, i, attr_name,
2673 &attr->type, &attr->count, &attrsize);
2675 if (status == FAIL) {
2677 throw5 (
"VSattrinfo failed ",
"vdata field index ",
2678 fieldindex,
" attr index is ", i);
2682 string tempname(attr_name);
2683 attr->name = tempname;
2688 attr->value.resize (attrsize);
2689 if (VSgetattr (vdata_id, fieldindex, i, &attr->value[0]) == FAIL) {
2691 throw5 (
"VSgetattr failed ",
"vdata field index is ",
2692 fieldindex,
" attr index is ", i);
2694 attrs.push_back (attr);
2705 char attr_name[H4_MAX_NC_NAME];
2708 intn n_attrs = Vnattrs(vgroup_id);
2710 throw1(
"Vnattrs failed");
2713 string temp_container_name(fullpath);
2717 for(
int attr_index = 0; attr_index <n_attrs; attr_index++) {
2720 int32 value_size_32 = 0;
2721 status_n = Vattrinfo(vgroup_id, (intn)attr_index, attr_name, &attr->type,
2722 &attr->count, &value_size_32);
2723 if(status_n == FAIL) {
2725 throw1(
"Vattrinfo failed.");
2727 int value_size = value_size_32;
2729 string tempname (attr_name);
2731 attr->name = tempname;
2733 attr->newname = tempname;
2734 attr->value.resize (value_size);
2736 status_n = Vgetattr(vgroup_id,(intn)attr_index,&attr->value[0]);
2737 if(status_n == FAIL) {
2740 throw3(
"Vgetattr failed. ",
"The attribute name is ",attr->name);
2742 vg_attr->attrs.push_back(attr);
2747 vg_attrs.push_back(vg_attr);
2767 int32 vgroup_id = 0;
2773 int32 lone_vg_number = 0;
2776 int32 num_of_lones = -1;
2779 int32 num_gobjects = 0;
2789 char vdata_name[VSNAMELENMAX];
2792 char vdata_class[VSNAMELENMAX];
2795 char vgroup_name[VGNAMELENMAX*4];
2798 char vgroup_class[VGNAMELENMAX*4];
2801 char *full_path = NULL;
2804 char *cfull_path = NULL;
2809 file_id = this->fileid;
2815 num_of_lones = Vlone (file_id, NULL, 0);
2816 if (num_of_lones == FAIL)
2817 throw3 (
"Fail to obtain lone vgroup number",
"file id is", file_id);
2820 if (num_of_lones > 0) {
2824 vector<int32>ref_array;
2825 ref_array.resize(num_of_lones);
2829 num_of_lones = Vlone (file_id, &ref_array[0], num_of_lones);
2830 if (num_of_lones == FAIL) {
2831 throw3 (
"Cannot obtain lone vgroup reference arrays ",
2832 "file id is ", file_id);
2836 for (lone_vg_number = 0; lone_vg_number < num_of_lones;
2840 vgroup_id = Vattach (file_id, ref_array[lone_vg_number],
"r");
2841 if (vgroup_id == FAIL) {
2842 throw3 (
"Vattach failed ",
"Reference number is ",
2843 ref_array[lone_vg_number]);
2846 status = Vgetname (vgroup_id, vgroup_name);
2847 if (status == FAIL) {
2848 Vdetach (vgroup_id);
2849 throw3 (
"Vgetname failed ",
"vgroup_id is ", vgroup_id);
2852 status = Vgetclass (vgroup_id, vgroup_class);
2853 if (status == FAIL) {
2854 Vdetach (vgroup_id);
2855 throw3 (
"Vgetclass failed ",
"vgroup_name is ", vgroup_name);
2859 if (strcmp (vgroup_class, _HDF_ATTRIBUTE) == 0
2860 || strcmp (vgroup_class, _HDF_VARIABLE) == 0
2861 || strcmp (vgroup_class, _HDF_DIMENSION) == 0
2862 || strcmp (vgroup_class, _HDF_UDIMENSION) == 0
2863 || strcmp (vgroup_class, _HDF_CDF) == 0
2864 || strcmp (vgroup_class, GR_NAME) == 0
2865 || strcmp (vgroup_class, RI_NAME) == 0) {
2870 num_gobjects = Vntagrefs (vgroup_id);
2871 if (num_gobjects < 0) {
2872 Vdetach (vgroup_id);
2873 throw3 (
"Vntagrefs failed ",
"vgroup_name is ", vgroup_name);
2881 full_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2882 if (full_path == NULL) {
2883 Vdetach (vgroup_id);
2885 throw1 (
"No enough memory to allocate the buffer.");
2888 memset(full_path,
'\0',MAX_FULL_PATH_LEN);
2889 strncpy (full_path,_BACK_SLASH,strlen(_BACK_SLASH));
2890 strncat(full_path,vgroup_name,strlen(vgroup_name));
2897 Vdetach (vgroup_id);
2899 throw1 (
"ReadVgattrs failed ");
2901 strncat(full_path,_BACK_SLASH,strlen(_BACK_SLASH));
2903 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2904 if (cfull_path == NULL) {
2905 Vdetach (vgroup_id);
2908 throw1 (
"No enough memory to allocate the buffer.");
2911 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
2912 strncpy (cfull_path, full_path,strlen(full_path));
2916 for (
int i = 0; i < num_gobjects; i++) {
2917 if (Vgettagref (vgroup_id, i, &obj_tag, &obj_ref) == FAIL) {
2918 Vdetach (vgroup_id);
2921 throw5 (
"Vgettagref failed ",
"vgroup_name is ",
2922 vgroup_name,
" reference number is ", obj_ref);
2926 if (Visvg (vgroup_id, obj_ref) == TRUE) {
2927 strncpy (full_path, cfull_path,strlen(cfull_path)+1);
2928 full_path[strlen(cfull_path)]=
'\0';
2932 else if (Visvs (vgroup_id, obj_ref)) {
2934 vdata_id = VSattach (file_id, obj_ref,
"r");
2935 if (vdata_id == FAIL) {
2936 Vdetach (vgroup_id);
2939 throw5 (
"VSattach failed ",
"vgroup_name is ",
2940 vgroup_name,
" reference number is ",
2943 status = VSgetname (vdata_id, vdata_name);
2944 if (status == FAIL) {
2945 Vdetach (vgroup_id);
2948 throw5 (
"VSgetclass failed ",
"vgroup_name is ",
2949 vgroup_name,
" reference number is ",
2953 status = VSgetclass (vdata_id, vdata_class);
2954 if (status == FAIL) {
2955 Vdetach (vgroup_id);
2958 throw5 (
"VSgetclass failed ",
"vgroup_name is ",
2959 vgroup_name,
" reference number is ",
2972 if (VSisattr (vdata_id) == TRUE
2973 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
2974 strlen (_HDF_CHK_TBL_CLASS))
2975 || !strncmp (vdata_class, _HDF_SDSVAR,
2976 strlen (_HDF_SDSVAR))
2977 || !strncmp (vdata_class, _HDF_CRDVAR,
2978 strlen (_HDF_CRDVAR))
2979 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
2980 || !strncmp (vdata_class, DIM_VALS01,
2981 strlen (DIM_VALS01))
2982 || !strncmp (vdata_class, RIGATTRCLASS,
2983 strlen (RIGATTRCLASS))
2984 || !strncmp (vdata_name, RIGATTRNAME,
2985 strlen (RIGATTRNAME))) {
2987 status = VSdetach (vdata_id);
2988 if (status == FAIL) {
2989 Vdetach (vgroup_id);
2992 throw3 (
"VSdetach failed ",
2993 "Vdata is under vgroup ", vgroup_name);
2999 VDATA*vdataobj = NULL;
3007 Vdetach (vgroup_id);
3017 for (std::vector <VDField * >::const_iterator it_vdf =
3019 it_vdf != vdataobj->
getFields ().end ();
3025 (*it_vdf)->newname =
3026 "vdata" + vdataobj->
newname +
"_vdf_" + (*it_vdf)->name;
3036 this->
vds.push_back (vdataobj);
3038 status = VSdetach (vdata_id);
3039 if (status == FAIL) {
3040 Vdetach (vgroup_id);
3043 throw3 (
"VSdetach failed ",
3044 "Vdata is under vgroup ", vgroup_name);
3050 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
3051 || obj_tag == DFTAG_SD) {
3059 if(full_path != NULL) {
3066 Vdetach (vgroup_id);
3069 throw3 (
"SDS with the reference number ", obj_ref,
3082 status = Vdetach (vgroup_id);
3083 if (status == FAIL) {
3084 throw3 (
"Vdetach failed ",
"vgroup_name is ", vgroup_name);
3100 int32 vgroup_pid = -1;
3109 int num_gobjects = 0;
3117 char cvgroup_name[VGNAMELENMAX*4];
3120 char vdata_name[VSNAMELENMAX];
3123 char vdata_class[VSNAMELENMAX];
3126 int32 vdata_id = -1;
3135 char *cfull_path = NULL;
3137 bool unexpected_fail =
false;
3140 vgroup_pid = Vattach (file_id, pobj_ref,
"r");
3141 if (vgroup_pid == FAIL)
3142 throw3 (
"Vattach failed ",
"Object reference number is ", pobj_ref);
3145 if (Vgetname (vgroup_pid, cvgroup_name) == FAIL) {
3146 Vdetach (vgroup_pid);
3147 throw3 (
"Vgetname failed ",
"Object reference number is ", pobj_ref);
3149 num_gobjects = Vntagrefs (vgroup_pid);
3150 if (num_gobjects < 0) {
3151 Vdetach (vgroup_pid);
3152 throw3 (
"Vntagrefs failed ",
"Object reference number is ", pobj_ref);
3163 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
3164 if (cfull_path == NULL)
3165 throw1 (
"No enough memory to allocate the buffer");
3167 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
3169 strncpy(cfull_path,full_path,strlen(full_path));
3170 strncat(cfull_path,cvgroup_name,strlen(cvgroup_name));
3172 ReadVgattrs(vgroup_pid,cfull_path);
3176 Vdetach (vgroup_pid);
3178 throw1 (
"ReadVgattrs failed ");
3181 strncat(cfull_path,_BACK_SLASH,strlen(_BACK_SLASH));
3187 for (i = 0; i < num_gobjects; i++) {
3189 if (Vgettagref (vgroup_pid, i, &obj_tag, &obj_ref) == FAIL) {
3190 unexpected_fail =
true;
3191 err_msg = string(ERR_LOC) +
" Vgettagref failed. ";
3195 if (Visvg (vgroup_pid, obj_ref) == TRUE) {
3196 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
3197 full_path[strlen(cfull_path)]=
'\0';
3198 obtain_path (file_id, sd_id, full_path, obj_ref);
3200 else if (Visvs (vgroup_pid, obj_ref)) {
3202 vdata_id = VSattach (file_id, obj_ref,
"r");
3203 if (vdata_id == FAIL) {
3204 unexpected_fail =
true;
3205 err_msg = string(ERR_LOC) +
" VSattach failed. ";
3209 status = VSQueryname (vdata_id, vdata_name);
3210 if (status == FAIL) {
3211 unexpected_fail =
true;
3212 err_msg = string(ERR_LOC) +
" VSQueryname failed. ";
3216 status = VSgetclass (vdata_id, vdata_class);
3217 if (status == FAIL) {
3218 unexpected_fail =
true;
3219 err_msg = string(ERR_LOC) +
" VSgetclass failed. ";
3223 if (VSisattr (vdata_id) != TRUE) {
3225 (vdata_class, _HDF_CHK_TBL_CLASS,
3226 strlen (_HDF_CHK_TBL_CLASS))) {
3228 VDATA *vdataobj = NULL;
3236 Vdetach (vgroup_pid);
3246 for (std::vector <VDField * >::const_iterator it_vdf =
3248 it_vdf != vdataobj->
getFields ().end ();
3253 (*it_vdf)->newname =
3254 "vdata" + vdataobj->
newname +
"_vdf_" +
3262 this->vds.push_back (vdataobj);
3265 status = VSdetach (vdata_id);
3266 if (status == FAIL) {
3267 unexpected_fail =
true;
3268 err_msg = string(ERR_LOC) +
" VSdetach failed. ";
3272 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
3273 || obj_tag == DFTAG_SD) {
3274 if (this->sd->refindexlist.find (obj_ref) !=
3275 this->sd->refindexlist.end ())
3276 this->sd->sdfields[this->sd->refindexlist[obj_ref]]->newname =
3278 cfull_path + this->sd->sdfields[this->sd->refindexlist[obj_ref]]->name;
3280 unexpected_fail =
true;
3281 stringstream temp_ss;
3283 err_msg = string(ERR_LOC) +
"SDS with the reference number"
3284 + temp_ss.str() +
" is not found.";
3295 if(vdata_id != -1) {
3296 status = VSdetach(vdata_id);
3297 if (status == FAIL) {
3298 Vdetach(vgroup_pid);
3299 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" VSdetached failed. ";
3300 err_msg = err_msg + err_msg2;
3303 else if(
true == unexpected_fail)
3308 if(vgroup_pid != -1) {
3309 status = Vdetach(vgroup_pid);
3310 if (status == FAIL) {
3311 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" VSdetached failed. ";
3312 err_msg = err_msg + err_msg2;
3315 else if(
true == unexpected_fail)
3332 int32 vgroup_cid = -1;
3335 int num_gobjects = 0;
3340 char cvgroup_name[VGNAMELENMAX*4];
3344 char *cfull_path = NULL;
3346 bool unexpected_fail =
false;
3348 vgroup_cid = Vattach (file_id, pobj_ref,
"r");
3349 if (vgroup_cid == FAIL)
3350 throw3 (
"Vattach failed ",
"Object reference number is ", pobj_ref);
3352 if (Vgetname (vgroup_cid, cvgroup_name) == FAIL) {
3353 Vdetach (vgroup_cid);
3354 throw3 (
"Vgetname failed ",
"Object reference number is ", pobj_ref);
3356 num_gobjects = Vntagrefs (vgroup_cid);
3357 if (num_gobjects < 0) {
3358 Vdetach (vgroup_cid);
3359 throw3 (
"Vntagrefs failed ",
"Object reference number is ", pobj_ref);
3371 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
3372 if (cfull_path == NULL)
3373 throw1 (
"No enough memory to allocate the buffer");
3375 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
3379 strncpy(cfull_path,full_path,strlen(full_path));
3380 strncat(cfull_path,cvgroup_name,strlen(cvgroup_name));
3381 strncat(cfull_path,_BACK_SLASH,strlen(_BACK_SLASH));
3385 for (i = 0; i < num_gobjects; i++) {
3387 if (Vgettagref (vgroup_cid, i, &obj_tag, &obj_ref) == FAIL) {
3388 unexpected_fail =
true;
3389 err_msg = string(ERR_LOC) +
" Vgettagref failed. ";
3393 if (Visvg (vgroup_cid, obj_ref) == TRUE) {
3394 strncpy (full_path, cfull_path,strlen(cfull_path)+1);
3395 full_path[strlen(cfull_path)]=
'\0';
3396 obtain_noneos2_sds_path (file_id, full_path, obj_ref);
3398 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
3399 || obj_tag == DFTAG_SD) {
3405 string temp_str = string(cfull_path);
3406 if((temp_str.find(
"Data Fields") != std::string::npos)||
3407 (temp_str.find(
"Geolocation Fields") != std::string::npos))
3408 sds_ref_list.remove(obj_ref);
3416 if(vgroup_cid != -1) {
3417 status = Vdetach(vgroup_cid);
3418 if (status == FAIL) {
3419 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" Vdetached failed. ";
3420 err_msg = err_msg + err_msg2;
3423 else if(
true == unexpected_fail)
3441 int32 vgroup_cid = -1;
3444 int num_gobjects = -1;
3449 char cvgroup_name[VGNAMELENMAX*4];
3450 char vdata_name[VSNAMELENMAX];
3451 char vdata_class[VSNAMELENMAX];
3452 int32 vdata_id = -1;
3455 char *cfull_path = NULL;
3458 bool unexpected_fail =
false;
3469 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
3470 if (cfull_path == NULL)
3471 throw1 (
"No enough memory to allocate the buffer");
3473 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
3475 vgroup_cid = Vattach (file_id, pobj_ref,
"r");
3476 if (vgroup_cid == FAIL) {
3477 unexpected_fail =
true;
3478 err_msg = string(ERR_LOC)+
"Vattach failed";
3483 if (Vgetname (vgroup_cid, cvgroup_name) == FAIL) {
3484 unexpected_fail =
true;
3485 err_msg = string(ERR_LOC)+
"Vgetname failed";
3488 num_gobjects = Vntagrefs (vgroup_cid);
3489 if (num_gobjects < 0) {
3490 unexpected_fail =
true;
3491 err_msg = string(ERR_LOC)+
"Vntagrefs failed";
3495 strncpy(cfull_path,full_path,strlen(full_path));
3496 strncat(cfull_path,cvgroup_name,strlen(cvgroup_name));
3497 strncat(cfull_path,_BACK_SLASH,strlen(_BACK_SLASH));
3501 temp_str = string(cfull_path);
3503 if (temp_str.find(
"Geolocation Fields") != string::npos) {
3504 if(
false == this->EOS2Swathflag)
3505 this->EOS2Swathflag =
true;
3508 for (i = 0; i < num_gobjects; i++) {
3510 if (Vgettagref (vgroup_cid, i, &obj_tag, &obj_ref) == FAIL) {
3511 unexpected_fail =
true;
3512 err_msg = string(ERR_LOC)+
"Vgettagref failed";
3516 if (Visvg (vgroup_cid, obj_ref) == TRUE) {
3517 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
3518 full_path[strlen(cfull_path)] =
'\0';
3519 obtain_vdata_path (file_id, full_path, obj_ref);
3521 else if (Visvs (vgroup_cid, obj_ref)) {
3523 vdata_id = VSattach (file_id, obj_ref,
"r");
3524 if (vdata_id == FAIL) {
3525 unexpected_fail =
true;
3526 err_msg = string(ERR_LOC)+
"VSattach failed";
3530 status = VSQueryname (vdata_id, vdata_name);
3531 if (status == FAIL) {
3532 unexpected_fail =
true;
3533 err_msg = string(ERR_LOC)+
"VSQueryname failed";
3537 status = VSgetclass (vdata_id, vdata_class);
3538 if (status == FAIL) {
3539 unexpected_fail =
true;
3540 err_msg = string(ERR_LOC)+
"VSgetclass failed";
3545 string temp_str2 = string(cfull_path);
3555 bool ignore_eos2_geo_vdata =
false;
3556 bool ignore_eos2_data_vdata =
false;
3557 if (temp_str2.find(
"Geolocation Fields") != string::npos) {
3558 ignore_eos2_geo_vdata =
true;
3562 if (temp_str2.find(
"Data Fields") != string::npos) {
3563 if (
true == this->EOS2Swathflag)
3564 ignore_eos2_data_vdata =
true;
3566 if ((
true == ignore_eos2_data_vdata)
3567 ||(
true == ignore_eos2_geo_vdata)
3568 || VSisattr (vdata_id) == TRUE
3569 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
3570 strlen (_HDF_CHK_TBL_CLASS))
3571 || !strncmp (vdata_class, _HDF_SDSVAR,
3572 strlen (_HDF_SDSVAR))
3573 || !strncmp (vdata_class, _HDF_CRDVAR,
3574 strlen (_HDF_CRDVAR))
3575 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
3576 || !strncmp (vdata_class, DIM_VALS01,
3577 strlen (DIM_VALS01))
3578 || !strncmp (vdata_class, RIGATTRCLASS,
3579 strlen (RIGATTRCLASS))
3580 || !strncmp (vdata_name, RIGATTRNAME,
3581 strlen (RIGATTRNAME))) {
3583 status = VSdetach (vdata_id);
3584 if (status == FAIL) {
3585 unexpected_fail =
true;
3586 err_msg = string(ERR_LOC)+
"VSdetach failed";
3592 VDATA *vdataobj = NULL;
3599 Vdetach (vgroup_cid);
3608 for (std::vector <VDField * >::const_iterator it_vdf =
3610 it_vdf != vdataobj->
getFields ().end ();
3615 (*it_vdf)->newname =
3616 "vdata" + vdataobj->
newname +
"_vdf_" +
3624 this->vds.push_back (vdataobj);
3625 status = VSdetach (vdata_id);
3626 if (status == FAIL) {
3627 unexpected_fail =
true;
3628 err_msg = string(ERR_LOC)+
"VSdetach failed";
3640 if(vgroup_cid != -1) {
3641 status = Vdetach(vgroup_cid);
3642 if (status == FAIL) {
3643 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" Vdetached failed. ";
3644 err_msg = err_msg + err_msg2;
3645 throw3(err_msg,
"vgroup name is ",cvgroup_name);
3647 else if(
true == unexpected_fail)
3648 throw3(err_msg,
"vgroup name is ",cvgroup_name);
3672 std::string tempdimname;
3673 std::pair < std::set < std::string >::iterator,
bool > ret;
3674 std::string temppath;
3675 std::set < int32 > fakedimsizeset;
3676 std::pair < std::set < int32 >::iterator,
bool > fakedimsizeit;
3677 std::map < int32, std::string > fakedimsizenamelist;
3678 std::map < int32, std::string >::iterator fakedimsizenamelistit;
3680 for (std::vector < SDField * >::const_iterator i =
3683 for (std::vector < Dimension * >::const_iterator j =
3684 (*i)->getDimensions ().begin ();
3685 j != (*i)->getDimensions ().end (); ++j) {
3688 if (file->sptype != OTHERHDF)
3689 tempdimname = (*j)->getName ();
3691 tempdimname = (*j)->getName () + temppath;
3694 new Dimension (tempdimname, (*j)->getSize (),
3696 (*i)->correcteddims.push_back (dim);
3697 if (tempdimname.find (
"fakeDim") != std::string::npos) {
3698 fakedimsizeit = fakedimsizeset.insert ((*j)->getSize ());
3699 if (fakedimsizeit.second ==
true) {
3700 fakedimsizenamelist[(*j)->getSize ()] = (*j)->getName ();
3710 if (file->sptype != OTHERHDF) {
3711 for (std::vector < SDField * >::const_iterator i =
3713 for (std::vector < Dimension * >::const_iterator j =
3714 (*i)->getCorrectedDimensions ().begin ();
3715 j != (*i)->getCorrectedDimensions ().end (); ++j) {
3716 if ((*j)->getName ().find (
"fakeDim") != std::string::npos) {
3717 if (fakedimsizenamelist.find ((*j)->getSize ()) !=
3718 fakedimsizenamelist.end ()) {
3719 (*j)->name = fakedimsizenamelist[(*j)->getSize ()];
3722 throw5 (
"The fakeDim name ", (*j)->getName (),
3723 "with the size", (*j)->getSize (),
3724 "does not in the fakedimsize list");
3737 for (std::vector < SDField * >::const_iterator i =
3739 for (std::vector < Dimension * >::const_iterator j =
3740 (*i)->getCorrectedDimensions ().begin ();
3741 j != (*i)->getCorrectedDimensions ().end (); ++j) {
3742 std::pair < std::set < std::string >::iterator,
bool > ret;
3746 if (ret.second ==
true) {
3764 for (std::map < std::string, int32 >::const_iterator i =
3775 missingfield->
type = DFNT_INT32;
3776 missingfield->
name = (*i).first;
3777 missingfield->
newname = (*i).first;
3778 missingfield->
rank = 1;
3779 missingfield->fieldtype = 4;
3782 missingfield->dims.push_back (dim);
3783 dim =
new Dimension ((*i).first, (*i).second, 0);
3784 missingfield->correcteddims.push_back (dim);
3800 vector<string>tempfulldimnamelist;
3801 for (std::set < std::string >::const_iterator i =
3809 int total_dcounter = 0;
3810 for (std::set < std::string >::const_iterator i =
3818 std::map < std::string, std::string >::iterator tempmapit;
3819 for (std::vector < SDField * >::const_iterator i =
3821 for (std::vector < Dimension * >::const_iterator j =
3822 (*i)->getCorrectedDimensions ().begin ();
3823 j != (*i)->getCorrectedDimensions ().end (); ++j) {
3826 (*j)->name = tempmapit->second;
3828 throw5 (
"This dimension with the name ", (*j)->name,
3829 "and the field name ", (*i)->name,
3830 " is not found in the dimension list.");
3854 string check_ceres_short_name_key=
"H4.EnableCERESMERRAShortName";
3855 bool turn_on_ceres_short_name_key=
false;
3857 turn_on_ceres_short_name_key = HDFCFUtil::check_beskeys(check_ceres_short_name_key);
3861 if (
true == HDF4RequestHandler::get_enable_ceres_merra_short_name() && (file->sptype == CER_ES4 || file->sptype == CER_SRB
3862 || file->sptype == CER_CDAY || file->sptype == CER_CGEO
3863 || file->sptype == CER_SYN || file->sptype == CER_ZAVG
3864 || file->sptype == CER_AVG)) {
3866 for (
unsigned int i = 0; i < file->
sd->
sdfields.size (); ++i) {
3873 vector<string>sd_data_fieldnamelist;
3874 vector<string>sd_latlon_fieldnamelist;
3875 vector<string>sd_nollcv_fieldnamelist;
3877 set<string>sd_fieldnamelist;
3879 for (std::vector < SDField * >::const_iterator i =
3881 if ((*i)->fieldtype ==0)
3883 else if ((*i)->fieldtype == 1 || (*i)->fieldtype == 2)
3896 int total_data_counter = 0;
3897 int total_latlon_counter = 0;
3898 int total_nollcv_counter = 0;
3905 std::map < std::string, std::string >::iterator tempmapit;
3908 for (std::vector < SDField * >::const_iterator i =
3924 if ((*i)->fieldtype != 0) {
3925 if ((*i)->fieldtype == 1 || (*i)->fieldtype == 2) {
3927 (*i)->newname = sd_latlon_fieldnamelist[total_latlon_counter];
3928 total_latlon_counter++;
3930 if ((*i)->getRank () > 2)
3931 throw3 (
"the lat/lon rank should NOT be greater than 2",
3932 (*i)->name, (*i)->getRank ());
3933 else if ((*i)->getRank () == 2) {
3934 for (std::vector < Dimension * >::const_iterator j =
3935 (*i)->getCorrectedDimensions ().begin ();
3936 j != (*i)->getCorrectedDimensions ().end (); ++j) {
3943 if (lldimname1 ==
"")
3944 lldimname1 =(*j)->name;
3946 lldimname2 = (*j)->name;
3957 (*i)->getCorrectedDimensions ()[0]->getName ();
3965 (*i)->newname = sd_data_fieldnamelist[total_data_counter];
3966 total_data_counter++;
3971 for (std::vector < SDField * >::const_iterator i =
3988 if ((*i)->fieldtype != 0) {
3989 if ((*i)->fieldtype != 1 && (*i)->fieldtype != 2) {
3992 (*i)->newname = sd_nollcv_fieldnamelist[total_nollcv_counter];
3993 total_nollcv_counter++;
3995 if ((*i)->getRank () > 1)
3996 throw3 (
"The lat/lon rank should be 1", (*i)->name,
4003 if (COARDFLAG || file->sptype == OTHERHDF)
4005 (*i)->getCorrectedDimensions ()[0]->getName ();
4009 (*i)->getCorrectedDimensions ()[0]->getName ();
4013 (*i)->newname = (*i)->getCorrectedDimensions ()[0]->getName ();
4030 std::map < std::string, std::string >::iterator tempmapit;
4033 std::string tempcoordinates;
4034 std::string tempfieldname;
4035 for (std::vector < SDField * >::const_iterator i =
4037 if ((*i)->fieldtype == 0) {
4039 tempcoordinates =
"";
4042 for (std::vector < Dimension * >::const_iterator j =
4043 (*i)->getCorrectedDimensions ().begin ();
4044 j != (*i)->getCorrectedDimensions ().end (); ++j) {
4045 tempmapit = (file->
sd->
dimcvarlist).find ((*j)->getName ());
4047 tempfieldname = tempmapit->second;
4049 throw3 (
"The dimension with the name ", (*j)->getName (),
4050 "must have corresponding coordinate variables.");
4052 tempcoordinates = tempfieldname;
4054 tempcoordinates = tempcoordinates +
" " + tempfieldname;
4057 (*i)->setCoordinates (tempcoordinates);
4061 if ((*i)->fieldtype == 1) {
4062 std::string tempunits =
"degrees_north";
4063 (*i)->setUnits (tempunits);
4066 if ((*i)->fieldtype == 2) {
4067 std::string tempunits =
"degrees_east";
4068 (*i)->setUnits (tempunits);
4072 if (((*i)->fieldtype == 3) || ((*i)->fieldtype == 4)) {
4073 std::string tempunits =
"level";
4074 (*i)->setUnits (tempunits);
4082 if (
false == COARDFLAG) {
4083 for (std::vector < SDField * >::const_iterator i =
4085 if ((*i)->fieldtype == 0) {
4086 bool has_lldim1 =
false;
4087 bool has_lldim2 =
false;
4088 for (std::vector < Dimension * >::const_iterator j =
4089 (*i)->getCorrectedDimensions ().begin ();
4090 j != (*i)->getCorrectedDimensions ().end (); ++j) {
4091 if(lldimname1 == (*j)->name)
4093 else if(lldimname2 == (*j)->name)
4098 if (has_lldim1^has_lldim2)
4099 (*i)->coordinates =
"";
4120 string check_disable_vdata_nameclashing_key=
"H4.DisableVdataNameclashingCheck";
4121 bool turn_on_disable_vdata_nameclashing_key =
false;
4123 turn_on_disable_vdata_nameclashing_key = HDFCFUtil::check_beskeys(check_disable_vdata_nameclashing_key);
4128 if (
false == HDF4RequestHandler::get_disable_vdata_nameclashing_check()) {
4130 vector<string> tempvdatafieldnamelist;
4132 for (std::vector < VDATA * >::const_iterator i = file->
vds.begin ();
4133 i != file->
vds.end (); ++i) {
4134 for (std::vector < VDField * >::const_iterator j =
4135 (*i)->getFields ().begin (); j != (*i)->getFields ().end ();
4137 tempvdatafieldnamelist.push_back((*j)->newname);
4142 int total_vfd_counter = 0;
4144 for (std::vector < VDATA * >::const_iterator i = file->
vds.begin ();
4145 i != file->
vds.end (); ++i) {
4146 for (std::vector < VDField * >::const_iterator j =
4147 (*i)->getFields ().begin (); j != (*i)->getFields ().end ();
4149 (*j)->newname = tempvdatafieldnamelist[total_vfd_counter];
4150 total_vfd_counter++;
4174 if (file->sptype != OTHERHDF) {
4176 for (std::vector < SDField * >::const_iterator i =
4178 for (vector<AttrContainer *>::iterator j = (*i)->dims_info.begin();
4179 j!= (*i)->dims_info.end(); ) {
4181 j = (*i)->dims_info.erase(j);
4184 if ((*i)->dims_info.size() != 0)
4185 throw1(
"Not totally erase the dimension container ");
4195 switch (file->sptype) {
4290 throw3 (
"No such SP datatype ",
"sptype is ", sptype);
4305 bool COARDFLAG =
false;
4323 for (std::vector < Attribute * >::const_iterator i =
4325 i != this->sd->getAttributes ().end (); ++i) {
4327 if ((*i)->getName () ==
"GridHeader") {
4328 float lat_start = 0.;
4329 float lon_start = 0.;
4333 HDFCFUtil::parser_trmm_v7_gridheader((*i)->getValue(),latsize,lonsize,
4334 lat_start,lon_start,
4335 lat_res,lon_res,
false);
4346bool File:: Obtain_TRMM_V7_latlon_name(
const SDField* sdfield,
const int latsize,
4347 const int lonsize,
string& latname,
string& lonname)
throw(
Exception) {
4352 int latname_index = -1;
4353 int lonname_index = -1;
4354 for (
int temp_index = 0; temp_index <sdfield->getRank(); ++temp_index) {
4355 if(-1==latname_index && sdfield->getCorrectedDimensions()[temp_index]->getSize() == latsize) {
4356 latname_index = temp_index;
4358 latname = sdfield->getCorrectedDimensions()[temp_index]->getName();
4360 else if (-1 == lonname_index && sdfield->getCorrectedDimensions()[temp_index]->getSize() == lonsize) {
4361 lonname_index = temp_index;
4363 lonname = sdfield->getCorrectedDimensions()[temp_index]->getName();
4367 return (latname_index + lonname_index == 1);
4376 std::string tempdimname1;
4377 std::string tempdimname2;
4378 std::string tempnewdimname1;
4379 std::string tempnewdimname2;
4380 std::string temppath;
4387 std::set < int32 > tempdimsizeset;
4388 std::map < int32, std::string > tempdimsizenamelist;
4389 std::map < int32, std::string >::iterator tempsizemapit;
4390 std::pair < std::set < int32 >::iterator,
bool > tempsetit;
4393 for (std::vector < SDField * >::const_iterator i =
4395 for (std::vector < Dimension * >::const_iterator j =
4396 (*i)->getCorrectedDimensions ().begin ();
4397 j != (*i)->getCorrectedDimensions ().end (); ++j) {
4398 if (((*j)->getName ()).find (
"fakeDim") == std::string::npos) {
4399 tempsetit = tempdimsizeset.insert ((*j)->getSize ());
4400 if (tempsetit.second ==
true)
4401 tempdimsizenamelist[(*j)->getSize ()] = (*j)->getName ();
4407 for (std::vector < SDField * >::const_iterator i =
4410 string temp_name = (*i)->newname.substr(1) ;
4411 size_t temp_pos = temp_name.find_first_of(
'/');
4412 if (temp_pos !=string::npos)
4413 (*i)->newname = temp_name.substr(temp_pos+1);
4418 for (std::vector < SDField * >::const_iterator i =
4421 if((*i)->getName() ==
"Latitude") {
4422 if((*i)->getRank() ==2) {
4425 ((*i)->getCorrectedDimensions ())[0]->getName ();
4427 ((*i)->getCorrectedDimensions ())[1]->getName ();
4430 (*i)->fieldtype = 1;
4433 else if ((*i)->getName() ==
"Longitude") {
4434 (*i)->fieldtype = 2;
4441 for (std::vector < Dimension * >::const_iterator k =
4442 (*i)->getCorrectedDimensions ().begin ();
4443 k != (*i)->getCorrectedDimensions ().end (); ++k) {
4444 size_t fakeDimpos = ((*k)->getName ()).find (
"fakeDim");
4446 if (fakeDimpos != std::string::npos) {
4448 tempdimsizenamelist.find ((*k)->getSize ());
4449 if (tempsizemapit != tempdimsizenamelist.end ())
4450 (*k)->name = tempdimsizenamelist[(*k)->getSize ()];
4458 if(tempnewdimname1.empty()!=
true)
4461 if(tempnewdimname2.empty()!=
true)
4464 string base_filename;
4465 size_t last_slash_pos = file->
getPath().find_last_of(
"/");
4466 if(last_slash_pos != string::npos)
4467 base_filename = file->
getPath().substr(last_slash_pos+1);
4468 if(
""==base_filename)
4469 base_filename = file->
getPath();
4472 if(base_filename.find(
"2A12")!=string::npos) {
4474 string nlayer_name =
"nlayer";
4476 for (vector < SDField * >::iterator i =
4479 bool has_nlayer =
false;
4481 for (vector < Dimension * >::const_iterator k =
4482 (*i)->getDimensions ().begin ();
4483 k != (*i)->getDimensions ().end (); ++k) {
4485 if((*k)->getSize() == 28 && (*k)->name == nlayer_name) {
4488 nlayer->
name = nlayer_name;
4490 nlayer->
type = DFNT_FLOAT32;
4491 nlayer->fieldtype = 6;
4496 nlayer->dims.push_back(dim);
4499 nlayer->correcteddims.push_back(dim);
4507 if(
true == has_nlayer)
4523 for (std::vector < SDField * >::iterator i =
4527 if((*i)->name ==
"InputFileNames") {
4531 else if((*i)->name ==
"InputAlgorithmVersions") {
4535 else if((*i)->name ==
"InputGenerationDateTimes") {
4540 (*i)->newname = (*i)->name;
4547 string nlayer_name =
"nlayer";
4549 for (vector < SDField * >::iterator i =
4552 bool has_nlayer =
false;
4554 for (vector < Dimension * >::const_iterator k =
4555 (*i)->getDimensions ().begin ();
4556 k != (*i)->getDimensions ().end (); ++k) {
4558 if((*k)->getSize() == 28 && (*k)->name == nlayer_name) {
4561 nlayer->
name = nlayer_name;
4563 nlayer->
type = DFNT_FLOAT32;
4564 nlayer->fieldtype = 6;
4569 nlayer->dims.push_back(dim);
4572 nlayer->correcteddims.push_back(dim);
4580 if(
true == has_nlayer)
4599 bool llname_found =
false;
4600 for (std::vector < SDField * >::iterator i =
4603 if(2 == (*i)->getRank()) {
4605 llname_found = Obtain_TRMM_V7_latlon_name((*i),latsize,lonsize,latname,lonname);
4606 if (
true == llname_found)
4616 longitude->
name = lonname;
4617 longitude->
rank = 1;
4618 longitude->
type = DFNT_FLOAT32;
4619 longitude->fieldtype = 2;
4624 longitude->dims.push_back (dim);
4626 dim =
new Dimension (lonname, lonsize, 0);
4627 longitude->correcteddims.push_back (dim);
4631 latitude->
name = latname;
4633 latitude->
type = DFNT_FLOAT32;
4634 latitude->fieldtype = 1;
4637 dim =
new Dimension (latname, latsize, 0);
4638 latitude->dims.push_back (dim);
4640 dim =
new Dimension (latname, latsize, 0);
4641 latitude->correcteddims.push_back (dim);
4651 string base_filename;
4652 if(
path.find_last_of(
"/") != string::npos)
4653 base_filename =
path.substr(
path.find_last_of(
"/")+1);
4654 if(base_filename.find(
"3A26")!=string::npos) {
4656 bool ZOflag =
false;
4657 bool SRTflag =
false;
4658 bool HBflag =
false;
4659 string nthrsh_base_name =
"nthrsh";
4660 string nthrsh_zo_name =
"nthrshZO";
4661 string nthrsh_hb_name =
"nthrshHB";
4662 string nthrsh_srt_name =
"nthrshSRT";
4668 for (vector < SDField * >::iterator i =
4671 if(ZOflag !=
true) {
4672 if((*i)->name.find(
"Order")!=string::npos) {
4673 for (vector < Dimension * >::const_iterator k =
4674 (*i)->getDimensions ().begin ();
4675 k != (*i)->getDimensions ().end (); ++k) {
4677 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4678 if(nthrsh_zo == NULL) {
4680 nthrsh_zo->
name = nthrsh_zo_name;
4681 nthrsh_zo->
rank = 1;
4682 nthrsh_zo->
type = DFNT_FLOAT32;
4683 nthrsh_zo->fieldtype = 6;
4688 nthrsh_zo->dims.push_back(dim);
4691 nthrsh_zo->correcteddims.push_back(dim);
4702 else if(SRTflag !=
true) {
4703 if((*i)->name.find(
"2A25")!=string::npos) {
4705 for (vector < Dimension * >::const_iterator k =
4706 (*i)->getDimensions ().begin ();
4707 k != (*i)->getDimensions ().end (); ++k) {
4709 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4710 if(nthrsh_srt == NULL) {
4712 nthrsh_srt->
name = nthrsh_srt_name;
4713 nthrsh_srt->
rank = 1;
4714 nthrsh_srt->
type = DFNT_FLOAT32;
4715 nthrsh_srt->fieldtype = 6;
4720 nthrsh_srt->dims.push_back(dim);
4723 nthrsh_srt->correcteddims.push_back(dim);
4732 else if(HBflag !=
true) {
4733 if((*i)->name.find(
"hb")!=string::npos || (*i)->name.find(
"HB")!=string::npos) {
4735 for (vector < Dimension * >::const_iterator k =
4736 (*i)->getDimensions ().begin ();
4737 k != (*i)->getDimensions ().end (); ++k) {
4739 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4741 if(nthrsh_hb == NULL) {
4743 nthrsh_hb->
name = nthrsh_hb_name;
4744 nthrsh_hb->
rank = 1;
4745 nthrsh_hb->
type = DFNT_FLOAT32;
4746 nthrsh_hb->fieldtype = 6;
4751 nthrsh_hb->dims.push_back(dim);
4754 nthrsh_hb->correcteddims.push_back(dim);
4765 for (vector < SDField * >::iterator i =
4768 if((*i)->name.find(
"Order")!=string::npos && ZOflag ==
true) {
4769 for (vector < Dimension * >::const_iterator k =
4770 (*i)->getDimensions ().begin ();
4771 k != (*i)->getDimensions ().end (); ++k) {
4773 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4774 (*k)->name = nthrsh_zo_name;
4779 for (std::vector < Dimension * >::const_iterator k =
4780 (*i)->getCorrectedDimensions ().begin ();
4781 k != (*i)->getCorrectedDimensions ().end (); ++k) {
4782 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4783 (*k)->name = nthrsh_zo_name;
4790 else if(((*i)->name.find(
"hb")!=string::npos || (*i)->name.find(
"HB")!=string::npos)&& HBflag ==
true) {
4791 for (vector < Dimension * >::const_iterator k =
4792 (*i)->getDimensions ().begin ();
4793 k != (*i)->getDimensions ().end (); ++k) {
4795 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4796 (*k)->name = nthrsh_hb_name;
4801 for (std::vector < Dimension * >::const_iterator k =
4802 (*i)->getCorrectedDimensions ().begin ();
4803 k != (*i)->getCorrectedDimensions ().end (); ++k) {
4804 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4805 (*k)->name = nthrsh_hb_name;
4811 else if(((*i)->name.find(
"2A25")!=string::npos) && SRTflag ==
true) {
4812 for (vector < Dimension * >::const_iterator k =
4813 (*i)->getDimensions ().begin ();
4814 k != (*i)->getDimensions ().end (); ++k) {
4816 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4817 (*k)->name = nthrsh_srt_name;
4822 for (std::vector < Dimension * >::const_iterator k =
4823 (*i)->getCorrectedDimensions ().begin ();
4824 k != (*i)->getCorrectedDimensions ().end (); ++k) {
4825 if((*k)->getSize() == 6 && (*k)->name == nthrsh_base_name) {
4826 (*k)->name = nthrsh_srt_name;
4836 if(nthrsh_zo !=NULL) {
4841 if(nthrsh_hb !=NULL) {
4846 if(nthrsh_srt !=NULL) {
4859 for (std::vector < SDField * >::iterator i =
4862 if((*i)->name ==
"InputFileNames") {
4867 else if((*i)->name ==
"InputAlgorithmVersions") {
4872 else if((*i)->name ==
"InputGenerationDateTimes") {
4885 NOTE
for programming:
4886 1. Outer loop: loop global attribute
for GridHeader?. Retrieve ? as a number
for index.
4887 1.5. Obtain the lat/lon sizes
for this grid.
4888 The following steps are to retrieve lat/lon names
for this grid.
4889 2. Inner loop: Then loop through the field
4890 3. Check the field rank,
4891 3.1
if the rank is not 2, (
if the index is the first index, change the newname to name )
4894 3.2.1 Retrieve the index from the field
new name(retrieve last
path Grid1 then retrieve 1)
4895 3.2.2 If the index from the field is the same as that from the GridHeader,
continue checking
4896 the lat/lon name
for this grid as the single grid.
4897 change the newname to name.
4904 int first_index = -1;
4905 for (vector < Attribute * >::const_iterator i =
4907 i != this->sd->getAttributes ().end (); ++i) {
4909 if ((*i)->getName ().find(
"GridHeader")==0) {
4910 string temp_name = (*i)->getName();
4913 string str_num = temp_name.substr(10);
4914 stringstream ss_num(str_num);
4917 ss_num >> grid_index;
4919 if ( -1 == first_index)
4920 first_index = grid_index;
4922 float lat_start = 0.;
4923 float lon_start = 0.;
4930 HDFCFUtil::parser_trmm_v7_gridheader((*i)->getValue(),latsize,lonsize,
4931 lat_start,lon_start,
4932 lat_res, lon_res,
false);
4941 bool llname_found =
false;
4942 for (std::vector < SDField * >::iterator i =
4946 if(2 == (*i)->getRank()) {
4949 if ((*i)->newname !=(*i)->name) {
4951 string temp_field_full_path = (*i)->getNewName();
4952 size_t last_path_pos = temp_field_full_path.find_last_of(
'/');
4953 char str_index = temp_field_full_path[last_path_pos-1];
4954 if(grid_index ==(
int)(str_index -
'0')) {
4955 if(llname_found !=
true)
4956 llname_found = Obtain_TRMM_V7_latlon_name((*i),latsize,lonsize,latname,lonname);
4957 (*i)->newname = (*i)->name;
4961 else if (first_index == grid_index)
4962 (*i)->newname = (*i)->name;
4967 longitude->
name = lonname;
4968 longitude->
rank = 1;
4969 longitude->
type = DFNT_FLOAT32;
4970 longitude->fieldtype = 2;
4971 longitude->fieldref = grid_index;
4976 longitude->dims.push_back (dim);
4978 dim =
new Dimension (lonname, lonsize, 0);
4979 longitude->correcteddims.push_back (dim);
4983 latitude->
name = latname;
4985 latitude->
type = DFNT_FLOAT32;
4986 latitude->fieldtype = 1;
4987 latitude->fieldref = grid_index;
4990 dim =
new Dimension (latname, latsize, 0);
4991 latitude->dims.push_back (dim);
4993 dim =
new Dimension (latname, latsize, 0);
4994 latitude->correcteddims.push_back (dim);
5016 std::string tempdimname1;
5017 std::string tempdimname2;
5018 std::string tempnewdimname1;
5019 std::string tempnewdimname2;
5020 std::string temppath;
5028 std::set < int32 > tempdimsizeset;
5029 std::map < int32, std::string > tempdimsizenamelist;
5030 std::map < int32, std::string >::iterator tempsizemapit;
5031 std::pair < std::set < int32 >::iterator,
bool > tempsetit;
5034 for (std::vector < SDField * >::const_iterator i =
5036 for (std::vector < Dimension * >::const_iterator j =
5037 (*i)->getCorrectedDimensions ().begin ();
5038 j != (*i)->getCorrectedDimensions ().end (); ++j) {
5039 if (((*j)->getName ()).find (
"fakeDim") == std::string::npos) {
5040 tempsetit = tempdimsizeset.insert ((*j)->getSize ());
5041 if (tempsetit.second ==
true)
5042 tempdimsizenamelist[(*j)->getSize ()] = (*j)->
getName ();
5047 for (std::vector < SDField * >::const_iterator i =
5050 if ((*i)->getName () ==
"geolocation") {
5054 tempdimname1 = ((*i)->getDimensions ())[0]->getName ();
5055 tempdimsize1 = ((*i)->getDimensions ())[0]->getSize ();
5056 tempdimname2 = ((*i)->getDimensions ())[1]->getName ();
5057 tempdimsize2 = ((*i)->getDimensions ())[1]->getSize ();
5060 ((*i)->getCorrectedDimensions ())[0]->getName ();
5062 ((*i)->getCorrectedDimensions ())[1]->getName ();
5069 if(latitude == NULL) {
5072 latitude->
name =
"latitude";
5074 latitude->fieldref = (*i)->fieldref;
5075 latitude->
type = (*i)->getType ();
5076 temppath = (*i)->newname.substr ((*i)->name.size ());
5078 latitude->fieldtype = 1;
5079 latitude->rootfieldname =
"geolocation";
5083 latitude->dims.push_back (dim);
5085 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
5086 latitude->dims.push_back (dim);
5088 dim =
new Dimension (tempnewdimname1, tempdimsize1, 0);
5089 latitude->correcteddims.push_back (dim);
5091 dim =
new Dimension (tempnewdimname2, tempdimsize2, 0);
5092 latitude->correcteddims.push_back (dim);
5095 if(longitude == NULL) {
5097 longitude->
name =
"longitude";
5098 longitude->
rank = 2;
5099 longitude->fieldref = (*i)->fieldref;
5100 longitude->
type = (*i)->getType ();
5102 longitude->fieldtype = 2;
5103 longitude->rootfieldname =
"geolocation";
5106 longitude->dims.push_back (dim);
5107 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
5108 longitude->dims.push_back (dim);
5110 dim =
new Dimension (tempnewdimname1, tempdimsize1, 0);
5111 longitude->correcteddims.push_back (dim);
5113 dim =
new Dimension (tempnewdimname2, tempdimsize2, 0);
5114 longitude->correcteddims.push_back (dim);
5122 for (std::vector < Dimension * >::const_iterator k =
5123 (*i)->getCorrectedDimensions ().begin ();
5124 k != (*i)->getCorrectedDimensions ().end (); ++k) {
5125 size_t fakeDimpos = ((*k)->getName ()).find (
"fakeDim");
5127 if (fakeDimpos != std::string::npos) {
5129 tempdimsizenamelist.find ((*k)->getSize ());
5130 if (tempsizemapit != tempdimsizenamelist.end ())
5131 (*k)->name = tempdimsizenamelist[(*k)->getSize ()];
5143 std::vector < SDField * >::iterator toeraseit;
5144 for (std::vector < SDField * >::iterator i = file->
sd->
sdfields.begin ();
5146 if ((*i)->getName () ==
"geolocation") {
5169 std::string tempnewdimname1, tempnewdimname2;
5173 std::string temppath;
5178 for (std::vector < SDField * >::const_iterator i =
5181 for (std::vector < Dimension * >::const_iterator k =
5182 (*i)->getDimensions ().begin ();
5183 k != (*i)->getDimensions ().end (); ++k) {
5186 if ((((*k)->getName ()).find (
"fakeDim")) == std::string::npos) {
5188 temppath = (*i)->newname.substr ((*i)->name.size ());
5191 if ((*k)->getSize () == 1440 && (*k)->getType () == 0) {
5193 if(longitude == NULL) {
5195 longitude->
name =
"longitude";
5196 longitude->
rank = 1;
5197 longitude->
type = DFNT_FLOAT32;
5198 longitude->fieldtype = 2;
5202 new Dimension ((*k)->getName (), (*k)->getSize (), 0);
5203 longitude->dims.push_back (dim);
5204 tempnewdimname2 = (*k)->getName ();
5207 new Dimension ((*k)->getName (), (*k)->getSize (), 0);
5208 longitude->correcteddims.push_back (dim);
5213 if ((*k)->getSize () == 400 && (*k)->getType () == 0) {
5215 if(latitude == NULL) {
5217 latitude->
name =
"latitude";
5219 latitude->
type = DFNT_FLOAT32;
5220 latitude->fieldtype = 1;
5223 new Dimension ((*k)->getName (), (*k)->getSize (), 0);
5224 latitude->dims.push_back (dim);
5225 tempnewdimname1 = (*k)->getName ();
5233 new Dimension ((*k)->getName (), (*k)->getSize (), 0);
5234 latitude->correcteddims.push_back (dim);
5240 if (latflag == 1 && lonflag == 1)
5244 if (latflag == 1 && lonflag == 1)
5253 if (latflag != 1 || lonflag != 1) {
5254 if(latitude != NULL)
5256 if(longitude != NULL)
5258 throw5 (
"Either latitude or longitude doesn't exist.",
"lat. flag= ",
5259 latflag,
"lon. flag= ", lonflag);
5276 std::string tempnewdimname1;
5277 std::string tempnewdimname2;
5278 bool latflag =
false;
5279 bool lonflag =
false;
5285 for (std::vector < SDField * >::const_iterator i =
5288 for (std::vector < Dimension * >::const_iterator k =
5289 (*i)->getDimensions ().begin ();
5290 k != (*i)->getDimensions ().end (); ++k) {
5291 if ((((*k)->getName ()).find (
"latitude")) == 0)
5292 (*k)->name =
"fakeDim1";
5293 if ((((*k)->getName()).find (
"longitude")) == 0)
5294 (*k)->name =
"fakeDim2";
5300 for (std::vector < Dimension * >::const_iterator k =
5301 (*i)->getCorrectedDimensions ().begin ();
5302 k != (*i)->getCorrectedDimensions ().end (); ++k) {
5303 if ((((*k)->getName ()).find (
"latitude")) == 0)
5304 (*k)->name =
"fakeDim1";
5305 if ((((*k)->getName()).find (
"longitude")) == 0)
5306 (*k)->name =
"fakeDim2";
5311 for (std::vector < SDField * >::const_iterator i =
5315 for (std::vector < Dimension * >::const_iterator k =
5316 (*i)->getDimensions ().begin ();
5317 k != (*i)->getDimensions ().end (); ++k) {
5325 if ((*k)->getSize () == 360 && (*k)->getType () == 0) {
5327 if(longitude == NULL) {
5329 longitude->
name =
"longitude";
5330 longitude->
rank = 1;
5331 longitude->
type = DFNT_FLOAT32;
5332 longitude->fieldtype = 2;
5337 longitude->dims.push_back (dim);
5338 tempnewdimname2 = longitude->
name;
5342 longitude->correcteddims.push_back (dim);
5347 if ((*k)->getSize () == 180 && (*k)->getType () == 0) {
5349 if(latitude == NULL) {
5351 latitude->
name =
"latitude";
5353 latitude->
type = DFNT_FLOAT32;
5354 latitude->fieldtype = 1;
5359 latitude->dims.push_back (dim);
5360 tempnewdimname1 = latitude->
getName ();
5369 latitude->correcteddims.push_back (dim);
5375 if (latflag ==
true && lonflag ==
true)
5379 if (latflag ==
true && lonflag ==
true)
5388 if (latflag !=
true || lonflag !=
true) {
5389 if(latitude != NULL)
5391 if(longitude != NULL)
5393 throw5 (
"Either latitude or longitude doesn't exist.",
"lat. flag= ",
5394 latflag,
"lon. flag= ", lonflag);
5398 for (std::vector < SDField * >::const_iterator i =
5402 for (std::vector < Dimension * >::const_iterator k =
5403 (*i)->getDimensions ().begin ();
5404 k != (*i)->getDimensions ().end (); ++k) {
5406 if ((*k)->getSize () == 360 )
5407 (*k)->name = longitude->
name;
5409 if ((*k)->getSize () == 180 )
5410 (*k)->name = latitude->
name;
5414 for (std::vector < Dimension * >::const_iterator k =
5415 (*i)->getCorrectedDimensions ().begin ();
5416 k != (*i)->getCorrectedDimensions ().end (); ++k) {
5418 if ((*k)->getSize () == 360 )
5419 (*k)->name = longitude->
name;
5421 if ((*k)->getSize () == 180 )
5422 (*k)->name = latitude->
name;
5447 std::string tempnewdimname1;
5448 std::string tempnewdimname2;
5449 std::string tempnewdimname3;
5450 bool latflag =
false;
5451 bool lonflag =
false;
5452 bool heiflag =
false;
5460 for (std::vector < SDField * >::const_iterator i =
5464 for (std::vector < Dimension * >::const_iterator k =
5465 (*i)->getDimensions ().begin ();
5466 k != (*i)->getDimensions ().end (); ++k) {
5474 if ((*k)->getSize () == 720 && (*k)->getType () == 0) {
5477 if(longitude == NULL) {
5479 longitude->
name =
"longitude";
5480 longitude->
rank = 1;
5481 longitude->
type = DFNT_FLOAT32;
5482 longitude->fieldtype = 2;
5487 longitude->dims.push_back (dim);
5488 tempnewdimname2 = longitude->
name;
5492 longitude->correcteddims.push_back (dim);
5497 if ((*k)->getSize () == 148 && (*k)->getType () == 0) {
5499 if(latitude == NULL) {
5501 latitude->
name =
"latitude";
5503 latitude->
type = DFNT_FLOAT32;
5504 latitude->fieldtype = 1;
5509 latitude->dims.push_back (dim);
5510 tempnewdimname1 = latitude->
getName ();
5519 latitude->correcteddims.push_back (dim);
5524 if ((*k)->getSize () == 19 && (*k)->getType () == 0) {
5526 if(height == NULL) {
5528 height->
name =
"height";
5530 height->
type = DFNT_FLOAT32;
5531 height->fieldtype = 6;
5536 height->dims.push_back (dim);
5537 tempnewdimname3 = height->
getName ();
5546 height->correcteddims.push_back (dim);
5554 if (latflag ==
true && lonflag ==
true)
5564 if (latflag !=
true || lonflag !=
true) {
5565 if(latitude != NULL)
5567 if(longitude != NULL)
5569 throw5 (
"Either latitude or longitude doesn't exist.",
"lat. flag= ",
5570 latflag,
"lon. flag= ", lonflag);
5573 if(height!=NULL && heiflag !=
true) {
5575 throw1(
"Height is allocated but the flag is not true");
5584 if(heiflag !=
true) {
5586 throw1(
"Height is allocated but the flag is not true");
5605 int pixels_per_scan_line = 0;
5607 std::string pixels_per_scan_line_name =
"Pixels per Scan Line";
5608 std::string number_pixels_control_points =
"Number of Pixel Control Points";
5609 std::string tempnewdimname1, tempnewdimname2;
5614 for (std::vector < Attribute * >::const_iterator i =
5617 if ((*i)->getName () == pixels_per_scan_line_name) {
5618 int *attrvalueptr = (
int *) (&((*i)->getValue ()[0]));
5619 pixels_per_scan_line = *attrvalueptr;
5624 if ( 0 == pixels_per_scan_line)
5625 throw1(
"The attribute 'Pixels per Scan Line' doesn't exist");
5630 int tempcountllflag = 0;
5632 for (std::vector < SDField * >::const_iterator i =
5635 if ((*i)->getName () ==
"longitude" || (*i)->getName () ==
"latitude") {
5636 if ((*i)->getName () ==
"longitude")
5637 (*i)->fieldtype = 2;
5638 if ((*i)->getName () ==
"latitude")
5639 (*i)->fieldtype = 1;
5642 if ((*i)->getRank () != 2)
5643 throw3 (
"The lat/lon rank must be 2", (*i)->getName (),
5645 for (std::vector < Dimension * >::const_iterator k =
5646 (*i)->getDimensions ().begin ();
5647 k != (*i)->getDimensions ().end (); ++k) {
5648 if ((*k)->getName () == number_pixels_control_points) {
5649 (*k)->name = pixels_per_scan_line_name;
5650 (*k)->dimsize = pixels_per_scan_line;
5655 for (std::vector < Dimension * >::const_iterator k =
5656 (*i)->getCorrectedDimensions ().begin ();
5657 k != (*i)->getCorrectedDimensions ().end (); ++k) {
5658 if ((*k)->getName ().find (number_pixels_control_points) !=
5659 std::string::npos) {
5660 (*k)->name = pixels_per_scan_line_name;
5661 (*k)->dimsize = pixels_per_scan_line;
5662 if (tempcountllflag == 1)
5663 tempnewdimname2 = (*k)->name;
5666 if (tempcountllflag == 1)
5667 tempnewdimname1 = (*k)->name;
5671 if (tempcountllflag == 2)
5691 std::string num_lat_name =
"Number of Lines";
5692 std::string num_lon_name =
"Number of Columns";
5698 int tempcountllflag = 0;
5700 for (std::vector < Attribute * >::const_iterator i =
5704 if ((*i)->getName () == num_lon_name) {
5707 int *attrvalue = (
int *) (&((*i)->getValue ()[0]));
5709 num_lon = *attrvalue;
5713 if ((*i)->getName () == num_lat_name) {
5715 int *attrvalue = (
int *) (&((*i)->getValue ()[0]));
5717 num_lat = *attrvalue;
5720 if (tempcountllflag == 2)
5726 if(longitude == NULL)
5727 throw1(
"Allocate memory for longitude failed .");
5729 longitude->
name =
"longitude";
5730 longitude->
rank = 1;
5731 longitude->
type = DFNT_FLOAT32;
5732 longitude->fieldtype = 2;
5738 throw3(
"The size of the dimension of the longitude ",longitude->
name,
" is 0.");
5744 throw1(
"Allocate memory for dim failed .");
5749 longitude->dims.push_back (dim);
5753 dim =
new Dimension (num_lon_name, num_lon, 0);
5756 throw1(
"Allocate memory for dim failed .");
5759 longitude->correcteddims.push_back (dim);
5763 if(latitude == NULL) {
5765 throw1(
"Allocate memory for dim failed .");
5767 latitude->
name =
"latitude";
5769 latitude->
type = DFNT_FLOAT32;
5770 latitude->fieldtype = 1;
5777 throw3(
"The size of the dimension of the latitude ",latitude->
name,
" is 0.");
5781 dim =
new Dimension (num_lat_name, num_lat, 0);
5785 throw1(
"Allocate memory for dim failed .");
5788 if(latitude != NULL)
5789 latitude->dims.push_back (dim);
5793 dim =
new Dimension (num_lat_name, num_lat, 0);
5797 throw1(
"Allocate memory for dim failed .");
5800 latitude->correcteddims.push_back (dim);
5803 for (std::vector < SDField * >::const_iterator i =
5805 if ((*i)->getRank () != 2) {
5810 throw3 (
"The lat/lon rank must be 2", (*i)->getName (),
5813 for (std::vector < Dimension * >::const_iterator k =
5814 (*i)->getDimensions ().begin ();
5815 k != (*i)->getDimensions ().end (); ++k) {
5816 if ((((*k)->getName ()).find (
"fakeDim")) != std::string::npos) {
5817 if ((*k)->getSize () == num_lon)
5818 (*k)->name = num_lon_name;
5819 if ((*k)->getSize () == num_lat)
5820 (*k)->name = num_lat_name;
5823 for (std::vector < Dimension * >::const_iterator k =
5824 (*i)->getCorrectedDimensions ().begin ();
5825 k != (*i)->getCorrectedDimensions ().end (); ++k) {
5826 if ((((*k)->getName ()).find (
"fakeDim")) != std::string::npos) {
5827 if ((*k)->getSize () == num_lon)
5828 (*k)->name = num_lon_name;
5829 if ((*k)->getSize () == num_lat)
5830 (*k)->name = num_lat_name;
5850 bool colatflag =
false;
5851 bool lonflag =
false;
5853 std::string tempnewdimname1;
5854 std::string tempnewdimname2;
5855 std::string tempcvarname1;
5856 std::string tempcvarname2;
5860 std::vector < SDField * >::iterator beerasedit;
5864 for (std::vector < SDField * >::iterator i = file->
sd->
sdfields.begin ();
5868 if (((*i)->getName ()).find (
"Colatitude") != std::string::npos) {
5870 if ((*i)->getRank () != 2)
5871 throw3 (
"The lat/lon rank must be 2", (*i)->getName (),
5873 int dimsize0 = (*i)->getDimensions ()[0]->getSize ();
5874 int dimsize1 = (*i)->getDimensions ()[1]->getSize ();
5879 if (dimsize0 < dimsize1) {
5880 tempnewdimname1 = (*i)->getDimensions ()[0]->getName ();
5881 tempnewdimname2 = (*i)->getDimensions ()[1]->getName ();
5884 tempnewdimname1 = (*i)->getDimensions ()[1]->getName ();
5885 tempnewdimname2 = (*i)->getDimensions ()[0]->getName ();
5890 (*i)->fieldtype = 1;
5891 tempcvarname1 = (*i)->getName ();
5905 else if (((*i)->getName ()).find (
"Longitude") != std::string::npos) {
5908 (*i)->fieldtype = 2;
5909 tempcvarname2 = (*i)->getName ();
5937 std::string tempdimname1;
5938 std::string tempdimname2;
5939 int tempdimsize1 = 0;
5940 int tempdimsize2 = 0;
5941 std::string tempcvarname1;
5942 std::string tempcvarname2;
5943 std::string temppath;
5944 std::set < std::string > tempdimnameset;
5945 std::pair < std::set < std::string >::iterator,
bool > tempsetit;
5948 bool cvflag =
false;
5953 for (std::vector < SDField * >::iterator i = file->
sd->
sdfields.begin ();
5955 std::string tempfieldname = (*i)->getName ();
5956 if (tempfieldname.find (
"Colatitude") != std::string::npos) {
5958 for (std::vector < Dimension * >::const_iterator j =
5959 (*i)->getDimensions ().begin ();
5960 j != (*i)->getDimensions ().end (); ++j) {
5961 if (((*j)->getName ()).find (
"regional colat") !=
5962 std::string::npos) {
5963 tempsetit = tempdimnameset.insert ((*j)->getName ());
5964 if (tempsetit.second ==
true) {
5965 tempdimname1 = (*j)->getName ();
5966 tempdimsize1 = (*j)->getSize ();
5967 (*i)->fieldtype = 1;
5977 for (std::vector < Dimension * >::const_iterator j =
5978 (*i)->getDimensions ().begin ();
5979 j != (*i)->getDimensions ().end (); ++j)
5981 for (std::vector < Dimension * >::const_iterator j =
5982 (*i)->getCorrectedDimensions ().begin ();
5983 j != (*i)->getCorrectedDimensions ().end (); ++j)
5985 (*i)->dims.clear ();
5986 (*i)->correcteddims.clear ();
5989 new Dimension (tempdimname1, tempdimsize1, 0);
5990 (*i)->dims.push_back (dim);
5991 dim =
new Dimension (tempdimname1, tempdimsize1, 0);
5992 (*i)->correcteddims.push_back (dim);
6008 else if (tempfieldname.find (
"Longitude") != std::string::npos) {
6009 for (std::vector < Dimension * >::const_iterator j =
6010 (*i)->getDimensions ().begin ();
6011 j != (*i)->getDimensions ().end (); ++j) {
6012 if (((*j)->getName ()).find (
"regional long") !=
6013 std::string::npos) {
6014 tempsetit = tempdimnameset.insert ((*j)->getName ());
6015 if (tempsetit.second ==
true) {
6016 tempdimname2 = (*j)->getName ();
6017 tempdimsize2 = (*j)->getSize ();
6018 (*i)->fieldtype = 2;
6027 for (std::vector < Dimension * >::const_iterator j =
6028 (*i)->getDimensions ().begin ();
6029 j != (*i)->getDimensions ().end (); ++j) {
6032 for (std::vector < Dimension * >::const_iterator j =
6033 (*i)->getCorrectedDimensions ().begin ();
6034 j != (*i)->getCorrectedDimensions ().end (); ++j) {
6037 (*i)->dims.clear ();
6038 (*i)->correcteddims.clear ();
6041 new Dimension (tempdimname2, tempdimsize2, 0);
6042 (*i)->dims.push_back (dim);
6043 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
6044 (*i)->correcteddims.push_back (dim);
6080 std::string tempdimname1 =
"1.0 deg. regional colat. zones";
6081 std::string tempdimname2 =
"1.0 deg. regional long. zones";
6082 std::string tempdimname3 =
"1.0 deg. zonal colat. zones";
6083 std::string tempdimname4 =
"1.0 deg. zonal long. zones";
6084 int tempdimsize1 = 180;
6085 int tempdimsize2 = 360;
6086 int tempdimsize3 = 180;
6087 int tempdimsize4 = 1;
6089 std::string tempnewdimname1;
6090 std::string tempnewdimname2;
6091 std::string tempcvarname1;
6092 std::string tempcvarname2;
6099 latitude->
name =
"latitude";
6101 latitude->
type = DFNT_FLOAT32;
6102 latitude->fieldtype = 1;
6109 latitude->dims.push_back (dim);
6111 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
6112 latitude->dims.push_back (dim);
6114 dim =
new Dimension (tempdimname1, tempdimsize1, 0);
6115 latitude->correcteddims.push_back (dim);
6117 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
6118 latitude->correcteddims.push_back (dim);
6123 longitude->
name =
"longitude";
6124 longitude->
rank = 2;
6125 longitude->
type = DFNT_FLOAT32;
6126 longitude->fieldtype = 2;
6131 dim =
new Dimension (tempdimname1, tempdimsize1, 0);
6132 longitude->dims.push_back (dim);
6134 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
6135 longitude->dims.push_back (dim);
6137 dim =
new Dimension (tempdimname1, tempdimsize1, 0);
6138 longitude->correcteddims.push_back (dim);
6140 dim =
new Dimension (tempdimname2, tempdimsize2, 0);
6141 longitude->correcteddims.push_back (dim);
6146 if (file->sptype == CER_SRB) {
6150 latitudez->
name =
"latitudez";
6151 latitudez->
rank = 1;
6152 latitudez->
type = DFNT_FLOAT32;
6153 latitudez->fieldtype = 1;
6156 dim =
new Dimension (tempdimname3, tempdimsize3, 0);
6157 latitudez->dims.push_back (dim);
6159 dim =
new Dimension (tempdimname3, tempdimsize3, 0);
6160 latitudez->correcteddims.push_back (dim);
6164 longitudez->
name =
"longitudez";
6165 longitudez->
rank = 1;
6166 longitudez->
type = DFNT_FLOAT32;
6167 longitudez->fieldtype = 2;
6170 dim =
new Dimension (tempdimname4, tempdimsize4, 0);
6171 longitudez->dims.push_back (dim);
6173 dim =
new Dimension (tempdimname4, tempdimsize4, 0);
6174 longitudez->correcteddims.push_back (dim);
6178 if (file->sptype == CER_SRB) {
6186 if(file->sptype == CER_CDAY) {
6188 string odddimname1=
"1.0 deg. regional Colat. zones";
6189 string odddimname2 =
"1.0 deg. regional Long. zones";
6192 for (std::vector < SDField * >::const_iterator i =
6194 for (std::vector < Dimension * >::const_iterator j =
6195 (*i)->getDimensions ().begin ();
6196 j != (*i)->getDimensions ().end (); ++j) {
6197 if (odddimname1 == (*j)->name)
6198 (*j)->name = tempdimname1;
6199 if (odddimname2 == (*j)->name)
6200 (*j)->name = tempdimname2;
6202 for (std::vector < Dimension * >::const_iterator j =
6203 (*i)->getCorrectedDimensions ().begin ();
6204 j != (*i)->getCorrectedDimensions ().end (); ++j) {
6205 if (odddimname1 == (*j)->name)
6206 (*j)->name = tempdimname1;
6207 if (odddimname2 == (*j)->name)
6208 (*j)->name = tempdimname2;
6222 std::string tempdimname3 =
"1.0 deg. zonal colat. zones";
6223 std::string tempdimname4 =
"1.0 deg. zonal long. zones";
6224 int tempdimsize3 = 180;
6225 int tempdimsize4 = 1;
6230 latitudez->
name =
"latitudez";
6231 latitudez->
rank = 1;
6232 latitudez->
type = DFNT_FLOAT32;
6233 latitudez->fieldtype = 1;
6238 latitudez->dims.push_back (dim);
6240 dim =
new Dimension (tempdimname3, tempdimsize3, 0);
6241 latitudez->correcteddims.push_back (dim);
6246 longitudez->
name =
"longitudez";
6247 longitudez->
rank = 1;
6248 longitudez->
type = DFNT_FLOAT32;
6249 longitudez->fieldtype = 2;
6252 dim =
new Dimension (tempdimname4, tempdimsize4, 0);
6253 longitudez->dims.push_back (dim);
6255 dim =
new Dimension (tempdimname4, tempdimsize4, 0);
6256 longitudez->correcteddims.push_back (dim);
6273 std::set < std::string > tempfulldimnamelist;
6274 std::pair < std::set < std::string >::iterator,
bool > ret;
6276 std::map < int, std::string > tempsizedimnamelist;
6280 for (std::vector < SDField * >::const_iterator i =
6282 if ((*i)->getName () ==
"Latitude")
6283 (*i)->fieldtype = 1;
6284 if ((*i)->getName () ==
"Longitude") {
6285 (*i)->fieldtype = 2;
6290 for (std::vector < Dimension * >::const_iterator j =
6291 (*i)->getCorrectedDimensions ().begin ();
6292 j != (*i)->getCorrectedDimensions ().end (); ++j) {
6293 tempsizedimnamelist[(*j)->getSize ()] = (*j)->getName ();
6299 for (std::vector < SDField * >::const_iterator i =
6301 for (std::vector < Dimension * >::const_iterator j =
6302 (*i)->getCorrectedDimensions ().begin ();
6303 j != (*i)->getCorrectedDimensions ().end (); ++j) {
6307 if ((*i)->fieldtype == 0) {
6308 if ((tempsizedimnamelist.find ((*j)->getSize ())) !=
6309 tempsizedimnamelist.end ())
6310 (*j)->name = tempsizedimnamelist[(*j)->getSize ()];
6325 std::set < std::string > tempfulldimnamelist;
6326 std::pair < std::set < std::string >::iterator,
bool > ret;
6336 bool merra_is_eos2 =
false;
6337 size_t found_forward_slash = file->
path.find_last_of(
"/");
6338 if ((found_forward_slash != string::npos) &&
6339 (((file->
path).substr(found_forward_slash+1).compare(0,5,
"MERRA"))==0)){
6341 for (std::vector < Attribute * >::const_iterator i =
6346 if(((*i)->getName().compare(0, 14,
"StructMetadata" )== 0) ||
6347 ((*i)->getName().compare(0, 14,
"structmetadata" )== 0)) {
6348 merra_is_eos2 =
true;
6355 if(
true == merra_is_eos2) {
6356 vector <string> noneos_newnamelist;
6359 for (std::vector < SDField * >::const_iterator i =
6361 (*i)->special_product_fullpath = (*i)->newname;
6363 string EOSGRIDstring=
":EOSGRID";
6364 size_t found = ((*i)->name).rfind(EOSGRIDstring);
6366 if (found !=string::npos && (((*i)->name).size() == (found + EOSGRIDstring.size()))) {
6368 (*i)->newname = (*i)->name.substr(0,found);
6369 noneos_newnamelist.push_back((*i)->newname);
6372 (*i)->newname = (*i)->name;
6379 for (std::vector < SDField * >::const_iterator i =
6382 for(vector<string>::const_iterator j =
6383 noneos_newnamelist.begin(); j !=noneos_newnamelist.end();++j) {
6385 if ((*i)->newname == (*j) && (*i)->name == (*j)) {
6387 (*i)->newname = (*i)->newname +
"_EOS";
6394 map<string,string> dimname_to_newdimname;
6395 for (std::vector < SDField * >::const_iterator i =
6397 for (std::vector < Dimension * >::const_iterator j =
6398 (*i)->getCorrectedDimensions ().begin ();
6399 j != (*i)->getCorrectedDimensions ().end (); ++j) {
6401 if ((*j)->getType () != 0) {
6402 if ((*i)->name == (*j)->getName () && (*i)->getRank () == 1){
6403 (*i)->fieldtype = 3;
6404 (*i)->is_dim_scale =
true;
6405 (*j)->name = (*i)->newname;
6416 map<string,string>::iterator itmap;
6417 for (std::vector < SDField * >::const_iterator i =
6420 if (0 == (*i)->fieldtype) {
6421 for (std::vector < Dimension * >::const_iterator j =
6422 (*i)->getCorrectedDimensions ().begin ();
6423 j != (*i)->getCorrectedDimensions ().end (); ++j) {
6424 itmap = dimname_to_newdimname.find((*j)->name);
6425 if (itmap == dimname_to_newdimname.end())
6426 throw2(
"Cannot find the corresponding new dim. name for dim. name ",(*j)->name);
6428 (*j)->name = (*itmap).second;
6436 for (std::vector < SDField * >::const_iterator i =
6437 file->
sd->
sdfields.begin (); i != file->
sd->
sdfields.end () && (
false == this->OTHERHDF_Has_Dim_NoScale_Field); ++i) {
6438 for (std::vector < Dimension * >::const_iterator j =
6439 (*i)->getCorrectedDimensions ().begin ();
6440 j != (*i)->getCorrectedDimensions ().end () && (
false == this->OTHERHDF_Has_Dim_NoScale_Field); ++j) {
6442 if ((*j)->getType () != 0) {
6443 if ((*i)->name == (*j)->getName () && (*i)->getRank () == 1)
6444 (*i)->fieldtype = 3;
6448 this->OTHERHDF_Has_Dim_NoScale_Field =
true;
6456 if (
true == this->OTHERHDF_Has_Dim_NoScale_Field)
#define throw1(a1)
The followings are convenient functions to throw exceptions with different.
Representing one attribute in grid or swath.
int32 rank
The rank of this field.
std::vector< Attribute * > attrs
The attributes of this field.
std::string newname
The CF full path(special characters replaced by underscores) of this field.
int32 type
The datatype of this field.
std::string name
The original name of this field.
const std::string & getName() const
Get the name of this field.
static File * Read(const char *path, int32 sdid, int32 fileid)
Retrieve SDS and Vdata information from the HDF4 file.
void handle_sds_final_dim_names()
Create the final CF-compliant dimension name list for each field.
std::vector< AttrContainer * > vg_attrs
Vgroup attribute information. See the description of the class AttrContainer.
void PrepareTRMML3M_V7()
Special method to prepare TRMM multiple grid Level 3 geolocation fields(latitude,longitude,...
void handle_sds_coords(bool &COARDFLAG, std::string &lldimname1, std::string &lldimname2)
Create "coordinates", "units" CF attributes.
std::vector< VDATA * > vds
Vdata objects in this file.
void handle_vdata()
Handle Vdata.
SD * sd
Pointer to the SD instance. There is only one SD instance in an HDF4 file.
void handle_sds_missing_fields()
Add the missing coordinate variables based on the corrected dimension name list.
void PrepareTRMML3S_V7()
Special method to prepare TRMM single grid Level 3 geolocation fields(latitude,longitude,...
void CheckSDType()
This method will check if the HDF4 file is one of TRMM or OBPG products we supported.
void PrepareTRMML2_V7()
Latitude and longitude are stored in different fields. Need to separate.
void Obtain_TRMML3S_V7_latlon_size(int &latsize, int &lonsize)
void Obtain_TRMML3S_V7_latlon_size(int &latsize, int&lonsize) throw(Exception);
void PrepareTRMML3C_V6()
Special method to prepare TRMM Level 3 CSH latitude,longitude and Height information.
std::string path
The absolute path of the file.
static File * Read_Hybrid(const char *path, int32 sdid, int32 fileid)
void handle_sds_fakedim_names()
void PrepareOBPGL3()
Special method to prepare OBPG Level 3 latitude and longitude information. The latitude and longitude...
void ReadHybridNonLoneVdatas(File *)
void obtain_vdata_path(int32 file_id, char *full_path, int32 pobj_ref)
The internal function used to obtain the path for hybrid non-lone vdata.
void handle_sds_names(bool &COARDFLAG, std::string &lldimname1, std::string &lldimname2)
Create the final CF-compliant field name list.
void PrepareOTHERHDF()
We still provide a hook for other HDF data product although no CF compliant is followed.
void ReadLoneVdatas(File *)
Handle non-attribute lone vdatas.
void PrepareTRMML3A_V6()
Special method to prepare TRMM Level 3A46 latitude and longitude information.
void PrepareTRMML3B_V6()
Special method to prepare TRMM Level 3B latitude and longitude information.
void InsertOrigFieldPath_ReadVgVdata()
The full path of SDS and Vdata will be obtained.
void PrepareOBPGL2()
Special method to prepare OBPG Level 2 latitude and longitude information. The latitude and longitude...
void create_sds_dim_name_list()
Create the new dimension name set and the dimension name to size map.
void ReadVgattrs(int32 vgroup_id, char *fullpath)
Obtain vgroup attributes.
void obtain_path(int32 file_id, int32 sd_id, char *full_path, int32 pobj_ref)
The internal function used by InsertOrigFieldPath_ReadVgVdata.
void PrepareCERZAVG()
Special method to prepare CERES Zonal Average latitude and longitude information.
void PrepareTRMML2_V6()
Latitude and longitude are stored in one array(geolocation). Need to separate.
const std::string & getPath() const
Obtain the path of the file.
One instance of this class represents one SDS object.
This class retrieves all SDS objects and SD file attributes.
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain the SD(file) attributes.
std::map< int32, int > refindexlist
SDS reference number to index map, use to quickly obtain the SDS id.
std::map< std::string, std::string > dimcvarlist
dimension name to coordinate variable name list: the key list to generate CF "coordinates" attributes...
static SD * Read_Hybrid(int32 sdfileid, int32 hfileid)
Read the information of all hybrid SDS objects from the HDF4 file.
std::map< std::string, int32 > n1dimnamelist
std::vector< Attribute * > attrs
SD attributes stored in vectors.
const std::vector< SDField * > & getFields() const
Redundant member function.
std::set< std::string > fulldimnamelist
Full dimension name list set.
std::list< int32 > sds_ref_list
SDS reference number list.
std::vector< SDField * > sdfields
SDS objects stored in vectors.
std::set< std::string > nonmisscvdimnamelist
static SD * Read(int32 sdfileid, int32 hfileid)
Read the information of all SDS objects from the HDF4 file.
void obtain_noneos2_sds_path(int32, char *, int32)
Obtain SDS path, this is like a clone of obtain_path in File class, except the Vdata and some minor p...
std::map< std::string, std::string > n2dimnamelist
Original dimension name to corrected dimension name map.
This class retrieves all information of one Vdata.
bool getTreatAsAttrFlag() const
std::string name
Original vdata name.
bool TreatAsAttrFlag
Flag to map vdata fields to DAP variables or DAP attributes.
const std::vector< VDField * > & getFields() const
Obtain Vdata fields.
int32 vdref
Vdata reference number.
void ReadAttributes(int32 vdata_id)
Retrieve all attributes of this Vdata.
std::vector< VDField * > vdfields
Vdata field vectors.
std::vector< Attribute * > attrs
Vdata attribute vectors.
std::string newname
New name with path and CF compliant(no special characters and name clashing).
static VDATA * Read(int32 vdata_id, int32 obj_ref)
Retrieve all information of this Vdata.
One instance of this class represents one Vdata field.
void ReadAttributes(int32 vdata_id, int32 fieldindex)
Read vdata field attributes.
static bool insert_map(std::map< std::string, std::string > &m, std::string key, std::string val)
static void Handle_NameClashing(std::vector< std::string > &newobjnamelist)
General routines to handle name clashings.
static std::string get_CF_string(std::string s)
Change special characters to "_".