40#include "HDF4RequestHandler.h"
42const char *_BACK_SLASH=
"/";
48#define ERR_LOC2(x) ERR_LOC1(x)
49#define ERR_LOC __FILE__ " : " ERR_LOC2(__LINE__)
52template <
typename T,
typename U,
typename V,
typename W,
typename X >
static void
53_throw5 (
const char *fname,
int line,
int numarg,
54 const T & a1,
const U & a2,
const V & a3,
const W & a4,
const X & a5)
56 std::ostringstream ss;
57 ss << fname <<
":" << line <<
":";
58 for (
int i = 0; i < numarg; ++i) {
78 ss <<
" Argument number is beyond 5";
87#define throw1(a1) _throw5(__FILE__, __LINE__, 1, a1, 0, 0, 0, 0)
88#define throw2(a1, a2) _throw5(__FILE__, __LINE__, 2, a1, a2, 0, 0, 0)
89#define throw3(a1, a2, a3) _throw5(__FILE__, __LINE__, 3, a1, a2, a3, 0, 0)
90#define throw4(a1, a2, a3, a4) _throw5(__FILE__, __LINE__, 4, a1, a2, a3, a4, 0)
91#define throw5(a1, a2, a3, a4, a5) _throw5(__FILE__, __LINE__, 5, a1, a2, a3, a4, a5)
93#define assert_throw0(e) do { if (!(e)) throw1("assertion failure"); } while (false)
94#define assert_range_throw0(e, ge, l) assert_throw0((ge) <= (e) && (e) < (l))
100 template <
typename T >
void operator () (T * ptr)
112 if (this->sdfd != -1) {
121 if (this->fileid != -1) {
123 std::for_each (this->vds.begin (), this->vds.end (), delete_elem ());
124 std::for_each (this->vg_attrs.begin (), this->vg_attrs.end (), delete_elem ());
136 std::for_each (this->vdfields.begin (), this->vdfields.end (),
140 std::for_each (this->attrs.begin (), this->attrs.end (), delete_elem ());
147 std::for_each (this->attrs.begin (), this->attrs.end (), delete_elem ());
150 std::for_each (this->sdfields.begin (), this->sdfields.end (),
159 std::for_each (this->dims.begin (), this->dims.end (), delete_elem ());
162 std::for_each (this->correcteddims.begin (), this->correcteddims.end (),
166 std::for_each (this->dims_info.begin (), this->dims_info.end (), delete_elem ());
178 std::for_each (this->
attrs.begin (), this->attrs.end (), delete_elem ());
182AttrContainer::~AttrContainer()
184 std::for_each (this->attrs.begin (), this->attrs.end (), delete_elem ());
195 auto file =
new File (path);
203 file->fileid = myfileid;
205 if (myfileid != -1) {
207 int32 status = Vstart (file->fileid);
208 if (status == FAIL) {
210 throw2 (
"Cannot start vdata/vgroup interface", path);
216 file->sd =
SD::Read (file->sdfd, file->fileid);
221 file->ReadLoneVdatas(file);
237 auto file =
new File (path);
239 throw1(
"Memory allocation for file class failed. ");
246 file->fileid = myfileid;
249 int status = Vstart (file->fileid);
250 if (status == FAIL) {
252 throw2 (
"Cannot start vdata/vgroup interface", path);
261 file->ReadLoneVdatas(file);
264 file->ReadHybridNonLoneVdatas(file);
281 int num_lone_vdata = VSlone (file->fileid,
nullptr, 0);
283 if (num_lone_vdata == FAIL)
284 throw2 (
"Fail to obtain lone vdata number", path);
290 char vdata_class[VSNAMELENMAX];
291 char vdata_name[VSNAMELENMAX];
293 if (num_lone_vdata > 0) {
295 vector<int32>ref_array;
296 ref_array.resize(num_lone_vdata);
298 if (VSlone (file->fileid, ref_array.data(), num_lone_vdata) == FAIL) {
299 throw2 (
"cannot obtain lone vdata reference arrays", path);
302 for (
int i = 0; i < num_lone_vdata; i++) {
306 vdata_id = VSattach (file->fileid, ref_array[i],
"r");
307 if (vdata_id == FAIL) {
308 throw2 (
"Fail to attach Vdata", path);
310 status = VSgetclass (vdata_id, vdata_class);
311 if (status == FAIL) {
313 throw2 (
"Fail to obtain Vdata class", path);
316 if (VSgetname (vdata_id, vdata_name) == FAIL) {
318 throw3 (
"Fail to obtain Vdata name", path, vdata_name);
323 if (VSisattr (vdata_id) == TRUE
324 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
325 strlen (_HDF_CHK_TBL_CLASS))
326 || !strncmp (vdata_class, _HDF_SDSVAR, strlen (_HDF_SDSVAR))
327 || !strncmp (vdata_class, _HDF_CRDVAR, strlen (_HDF_CRDVAR))
328 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
329 || !strncmp (vdata_class, DIM_VALS01, strlen (DIM_VALS01))
330 || !strncmp (vdata_class, RIGATTRCLASS, strlen (RIGATTRCLASS))
331 || !strncmp (vdata_name, RIGATTRNAME, strlen (RIGATTRNAME))) {
333 status = VSdetach (vdata_id);
334 if (status == FAIL) {
335 throw3 (
"VSdetach failed ",
"Vdata name ", vdata_name);
340 VDATA*vdataobj =
nullptr;
354 for (
const auto &vdf:vdataobj->
getFields ()) {
358 vdf->newname =
"vdata_" + vdataobj->newname +
"_vdf_" + vdf->name;
366 file->vds.push_back (vdataobj);
380 (vdata_name, CERE_META_NAME, strlen (CERE_META_NAME))) {
382 char *fieldname =
nullptr;
385 int num_field = VFnfields (vdata_id);
386 if (num_field == FAIL) {
388 throw3 (
"number of fields at Vdata ", vdata_name,
" is -1");
392 for (
int j = 0; j < num_field; j++) {
394 fieldname = VFfieldname (vdata_id, j);
395 if (fieldname ==
nullptr) {
397 throw5 (
"vdata ", vdata_name,
" field index ", j,
398 " field name is nullptr.");
402 else if (!strcmp (fieldname, CERE_META_FIELD_NAME)) {
404 int32 fieldsize = -1;
408 fieldsize = VFfieldesize (vdata_id, j);
409 if (fieldsize == FAIL) {
411 throw5 (
"vdata ", vdata_name,
" field ",fieldname,
" size is wrong.");
415 nelms = VSelts (vdata_id);
418 throw5 (
"vdata ", vdata_name,
419 " number of field record ", nelms,
" is wrong.");
423 bool data_buf_err =
false;
424 bool VS_fun_err =
false;
427 auto databuf = (
char *) malloc (fieldsize * nelms);
428 if (databuf ==
nullptr) {
429 err_msg = string(ERR_LOC) +
"No enough memory to allocate buffer.";
435 if (VSseek (vdata_id, 0) == FAIL) {
436 err_msg = string(ERR_LOC) +
"VSseek failed";
442 if (VSsetfields (vdata_id, CERE_META_FIELD_NAME) == FAIL) {
443 err_msg =
"VSsetfields failed";
449 if (VSread(vdata_id, (uint8 *) databuf, 1,FULL_INTERLACE)
451 err_msg =
"VSread failed";
457 if (!strncmp(databuf, CER_AVG_NAME,strlen (CER_AVG_NAME)))
458 file->sptype = CER_AVG;
460 (databuf, CER_ES4_NAME,strlen(CER_ES4_NAME)))
461 file->sptype = CER_ES4;
463 (databuf, CER_CDAY_NAME,strlen (CER_CDAY_NAME)))
464 file->sptype = CER_CDAY;
466 (databuf, CER_CGEO_NAME,strlen (CER_CGEO_NAME)))
467 file->sptype = CER_CGEO;
469 (databuf, CER_SRB_NAME,strlen (CER_SRB_NAME)))
470 file->sptype = CER_SRB;
472 (databuf, CER_SYN_NAME,strlen (CER_SYN_NAME)))
473 file->sptype = CER_SYN;
475 (databuf, CER_ZAVG_NAME,
476 strlen (CER_ZAVG_NAME)))
477 file->sptype = CER_ZAVG;
480 if (data_buf_err ==
true || VS_fun_err ==
true) {
482 if (data_buf_err ==
true)
486 throw5(
"vdata ",vdata_name,
"field ",
487 CERE_META_FIELD_NAME,err_msg);
509 int32 vgroup_id = -1;
515 int32 lone_vg_number = 0;
516 int32 num_of_lones = -1;
517 int32 num_gobjects = 0;
522 char vdata_name[VSNAMELENMAX];
523 char vdata_class[VSNAMELENMAX];
524 char vgroup_name[VGNAMELENMAX*4];
525 char vgroup_class[VGNAMELENMAX*4];
528 char *full_path =
nullptr;
531 char *cfull_path =
nullptr;
534 file_id = file->fileid;
539 num_of_lones = Vlone (file_id,
nullptr, 0);
540 if (num_of_lones == FAIL)
541 throw3 (
"Fail to obtain lone vgroup number",
"file id is", file_id);
544 if (num_of_lones > 0) {
550 vector<int32>ref_array;
551 ref_array.resize(num_of_lones);
555 num_of_lones = Vlone (file_id, ref_array.data(), num_of_lones);
556 if (num_of_lones == FAIL) {
557 throw3 (
"Cannot obtain lone vgroup reference arrays ",
558 "file id is ", file_id);
562 for (lone_vg_number = 0; lone_vg_number < num_of_lones;
566 vgroup_id = Vattach (file_id, ref_array[lone_vg_number],
"r");
567 if (vgroup_id == FAIL) {
568 throw3 (
"Vattach failed ",
"Reference number is ",
569 ref_array[lone_vg_number]);
573 status = Vgetname (vgroup_id, vgroup_name);
574 if (status == FAIL) {
576 throw3 (
"Vgetname failed ",
"vgroup_id is ", vgroup_id);
580 status = Vgetclass (vgroup_id, vgroup_class);
581 if (status == FAIL) {
583 throw3 (
"Vgetclass failed ",
"vgroup_name is ", vgroup_name);
587 if (strcmp (vgroup_class, _HDF_ATTRIBUTE) == 0
588 || strcmp (vgroup_class, _HDF_VARIABLE) == 0
589 || strcmp (vgroup_class, _HDF_DIMENSION) == 0
590 || strcmp (vgroup_class, _HDF_UDIMENSION) == 0
591 || strcmp (vgroup_class, _HDF_CDF) == 0
592 || strcmp (vgroup_class, GR_NAME) == 0
593 || strcmp (vgroup_class, RI_NAME) == 0) {
599 num_gobjects = Vntagrefs (vgroup_id);
600 if (num_gobjects < 0) {
602 throw3 (
"Vntagrefs failed ",
"vgroup_name is ", vgroup_name);
607 bool VS_or_mem_err =
false;
613 full_path = (
char *) malloc (MAX_FULL_PATH_LEN);
614 if (full_path ==
nullptr) {
615 err_msg =
"No enough memory to allocate the buffer for full_path.";
616 VS_or_mem_err =
true;
620 memset(full_path,
'\0',MAX_FULL_PATH_LEN);
623 strncpy (full_path,_BACK_SLASH,strlen(_BACK_SLASH));
624 strncat(full_path,vgroup_name,strlen(vgroup_name));
625 strncat(full_path,_BACK_SLASH,strlen(_BACK_SLASH));
628 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
629 if (cfull_path ==
nullptr) {
632 err_msg =
"No enough memory to allocate the buffer for cfull_path.";
633 VS_or_mem_err =
true;
637 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
638 strncpy(cfull_path,full_path,strlen(full_path));
642 for (
int i = 0; i < num_gobjects; i++) {
645 if (Vgettagref (vgroup_id, i, &obj_tag, &obj_ref) == FAIL) {
646 err_msg =
"Vgettagref failed";
647 VS_or_mem_err =
true;
653 if (Visvg (vgroup_id, obj_ref) == TRUE) {
654 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
655 full_path[strlen(cfull_path)]=
'\0';
660 else if (Visvs (vgroup_id, obj_ref)) {
663 vdata_id = VSattach (file_id, obj_ref,
"r");
664 if (vdata_id == FAIL) {
665 err_msg =
"VSattach failed";
666 VS_or_mem_err =
true;
671 status = VSgetname (vdata_id, vdata_name);
672 if (status == FAIL) {
673 err_msg =
"VSgetname failed";
674 VS_or_mem_err =
true;
679 status = VSgetclass (vdata_id, vdata_class);
680 if (status == FAIL) {
681 err_msg =
"VSgetclass failed";
682 VS_or_mem_err =
true;
687 if (VSisattr (vdata_id) == TRUE
688 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
689 strlen (_HDF_CHK_TBL_CLASS))
690 || !strncmp (vdata_class, _HDF_SDSVAR,
691 strlen (_HDF_SDSVAR))
692 || !strncmp (vdata_class, _HDF_CRDVAR,
693 strlen (_HDF_CRDVAR))
694 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
695 || !strncmp (vdata_class, DIM_VALS01,
697 || !strncmp (vdata_class, RIGATTRCLASS,
698 strlen (RIGATTRCLASS))
699 || !strncmp (vdata_name, RIGATTRNAME,
700 strlen (RIGATTRNAME))) {
702 status = VSdetach (vdata_id);
703 if (status == FAIL) {
704 err_msg =
"VSdetach failed in the if block to ignore the HDF4 internal attributes.";
705 VS_or_mem_err =
true;
713 VDATA *vdataobj =
nullptr;
725 if (full_path !=
nullptr)
726 vdataobj->newname = full_path +vdataobj->name;
731 for (
const auto &vdf:vdataobj->
getFields ()) {
737 "vdata" + vdataobj->newname +
"_vdf_" + vdf->name;
749 this->vds.push_back (vdataobj);
751 status = VSdetach (vdata_id);
752 if (status == FAIL) {
753 err_msg =
"VSdetach failed in the user-defined vdata block";
754 VS_or_mem_err =
true;
764 if (full_path !=
nullptr)
766 if (cfull_path !=
nullptr)
769 status = Vdetach (vgroup_id);
770 if (status == FAIL) {
771 throw3 (
"Vdetach failed ",
"vgroup_name is ", vgroup_name);
773 if (
true == VS_or_mem_err)
774 throw3(err_msg,
"vgroup_name is ",vgroup_name);
791File::Check_update_special(
const string& grid_name)
const {
793 set<string> dimnameset;
794 set<SDField*> fldset;
807 FullXDim= FullXDim+grid_name;
808 FullYDim =FullYDim+grid_name;
810 for (
const auto &sdf:this->sd->
getFields ()) {
812 for (
const auto &dim:sdf->getDimensions()) {
813 if (dim->getName() !=FullXDim && dim->getName()!=FullYDim)
814 dimnameset.insert(dim->getName());
817 if (1==sdf->getRank())
826 if (fldset.size() < (dimnameset.size()+2))
829 int total_num_dims = 0;
830 size_t grid_name_size = grid_name.size();
831 string reduced_dimname;
833 for (
const auto &fld:fldset) {
834 size_t dim_size = (fld->getDimensions())[0]->getName().size();
835 if ( dim_size > grid_name_size){
836 reduced_dimname = (fld->getDimensions())[0]->getName().substr(0,dim_size-grid_name_size-1);
837 if (fld->getName() == reduced_dimname)
842 if ((
size_t)total_num_dims != (dimnameset.size()+2))
846 for (
const auto &sdf:this->sd->getFields()) {
848 for (
const auto &dim:sdf->getDimensions ()) {
850 size_t dim_size = dim->getName().size();
851 if ( dim_size > grid_name_size){
852 reduced_dimname = dim->getName().substr(0,dim_size-grid_name_size-1);
853 dim->name = reduced_dimname;
862 for (
const auto &fld:fldset) {
864 if (fld->getName() == (fld->getDimensions())[0]->getName()) {
866 if (
"XDim" == fld->getName()){
867 std::string tempunits =
"degrees_east";
868 fld->setUnits (tempunits);
872 else if (
"YDim" == fld->getName()){
873 std::string tempunits =
"degrees_north";
874 fld->setUnits (tempunits);
878 else if (
"Pressure_Level" == fld->getName()) {
879 std::string tempunits =
"hPa";
880 fld->setUnits (tempunits);
884 std::string tempunits =
"level";
885 fld->setUnits (tempunits);
896File::Handle_AIRS_L23() {
901 if (basename(file->path).find(
".L2.")!=string::npos)
905 set<string> scaled_dname_set;
908 set<string> non_scaled_dname_set;
909 pair<set<string>::iterator,
bool> ret;
912 map<string,int> non_scaled_dname_to_size;
916 for (
const auto &sdf:file->sd->sdfields) {
918 string tempname = sdf->name;
919 size_t found_colon = tempname.find_first_of(
':');
920 if (found_colon!=string::npos)
921 sdf->newname = tempname.substr(0,found_colon);
923 for (
const auto &dim:sdf->getDimensions()) {
925 tempname = dim->name;
926 found_colon = tempname.find_first_of(
':');
927 if (found_colon!=string::npos)
928 dim->name = tempname.substr(0,found_colon);
930 if (0==dim->getType()) {
931 ret = non_scaled_dname_set.insert(dim->name);
932 if (
true == ret.second)
933 non_scaled_dname_to_size[dim->name] = dim->dimsize;
936 scaled_dname_set.insert(dim->name);
950 if (
true == airs_l3) {
952 set<string>scaled_dname_set_marker = scaled_dname_set;
961 for (std::vector < SDField * >::iterator i =
962 file->sd->sdfields.begin (); i != file->sd->sdfields.end (); ) {
963 if (1 == (*i)->getRank()) {
964 if (scaled_dname_set.find((*i)->getNewName())!=scaled_dname_set.end()) {
965 if (scaled_dname_set_marker.find((*i)->getNewName())!=scaled_dname_set_marker.end()) {
966 scaled_dname_set_marker.erase((*i)->getNewName());
972 i= file->sd->sdfields.erase(i);
980 else if ( 2 == (*i)->getRank()) {
981 if (
"Latitude" == (*i)->getNewName() ||
"Longitude" == (*i)->getNewName()) {
983 i = file->sd->sdfields.erase(i);
997 set<string>final_non_scaled_dname_set;
998 for (
const auto &non_sdim:non_scaled_dname_set) {
999 if (scaled_dname_set.find(non_sdim)==scaled_dname_set.end())
1000 final_non_scaled_dname_set.insert(non_sdim);
1004 for (
const auto &non_sdim:final_non_scaled_dname_set) {
1006 auto missingfield =
new SDField ();
1010 missingfield->type = DFNT_INT32;
1011 missingfield->name = non_sdim;
1012 missingfield->newname = non_sdim;
1013 missingfield->rank = 1;
1014 missingfield->fieldtype = 4;
1015 missingfield->setUnits(
"level");
1016 auto dim =
new Dimension (non_sdim,non_scaled_dname_to_size[non_sdim] , 0);
1018 missingfield->dims.push_back (dim);
1019 file->sd->sdfields.push_back (missingfield);
1025 if (
true == airs_l3) {
1026 for (
const auto &sdf:file->sd->sdfields) {
1028 if (1 ==sdf->getRank()){
1029 if (
"XDim" == sdf->newname)
1030 sdf->newname =
"Longitude";
1031 else if (
"YDim" == sdf->newname)
1032 sdf->newname =
"Latitude";
1035 for (
const auto &dim:sdf->getDimensions()) {
1036 if (
"XDim" == dim->name)
1037 dim->name =
"Longitude";
1038 else if (
"YDim" == dim->name)
1039 dim->name =
"Latitude";
1046 if (
false == airs_l3) {
1048 bool change_lat_unit =
false;
1049 bool change_lon_unit =
false;
1050 string ll_dimname1 =
"";
1051 string ll_dimname2 =
"";
1055 for (
const auto &sdf:file->sd->sdfields) {
1057 if (2 == sdf->getRank()) {
1058 if (
"Latitude" == sdf->newname){
1060 change_lat_unit =
true;
1061 string tempunits =
"degrees_north";
1062 sdf->setUnits(tempunits);
1063 ll_dimname1 = sdf->getDimensions()[0]->getName();
1064 ll_dimname2 = sdf->getDimensions()[1]->getName();
1067 else if (
"Longitude" == sdf->newname) {
1069 change_lon_unit =
true;
1070 string tempunits =
"degrees_east";
1071 sdf->setUnits(tempunits);
1073 if ((
true == change_lat_unit) && (
true == change_lon_unit))
1079 string tempcoordinates =
"";
1080 string tempfieldname =
"";
1083 for (
const auto &sdf:file->sd->sdfields) {
1086 bool dimscale_var =
false;
1087 dimscale_var = (sdf->rank == 1) & ((sdf->newname) == (sdf->getDimensions()[0]->getName()));
1089 if ((0 ==sdf->fieldtype) && (
false == dimscale_var)) {
1092 tempcoordinates =
"";
1096 bool has_lldim1 =
false;
1097 bool has_lldim2 =
false;
1098 for (
const auto &dim:sdf->getDimensions ()) {
1099 if (dim->name == ll_dimname1)
1101 else if (dim->name == ll_dimname2)
1103 if ((
true == has_lldim1) && (
true == has_lldim2))
1108 if ((
true == has_lldim1) && (
true == has_lldim2)) {
1109 for (
const auto &dim:sdf->getDimensions ()) {
1110 if (dim->name == ll_dimname1)
1111 tempfieldname =
"Latitude";
1112 else if (dim->name == ll_dimname2)
1113 tempfieldname =
"Longitude";
1115 tempfieldname = dim->name;
1118 tempcoordinates = tempfieldname;
1120 tempcoordinates = tempcoordinates +
" " + tempfieldname;
1125 for (
const auto &dim:sdf->getDimensions()) {
1127 tempcoordinates = dim->name;
1129 tempcoordinates = tempcoordinates +
" " + dim->name;
1133 sdf->setCoordinates (tempcoordinates);
1150 if (this->sptype == OTHERHDF) {
1152 int trmm_multi_gridflag = 0;
1153 int trmm_single_gridflag = 0;
1154 int trmm_swathflag = 0;
1156 for (
const auto &attr:this->sd->getAttributes ()) {
1157 if (attr->getName () ==
"FileHeader") {
1158 trmm_multi_gridflag++;
1159 trmm_single_gridflag++;
1162 if (attr->getName () ==
"FileInfo") {
1163 trmm_multi_gridflag++;
1164 trmm_single_gridflag++;
1167 if (attr->getName () ==
"SwathHeader")
1170 if (attr->getName () ==
"GridHeader")
1171 trmm_single_gridflag++;
1173 else if ((attr->getName ().find (
"GridHeader") == 0) &&
1174 ((attr->getName()).size() >10))
1175 trmm_multi_gridflag++;
1180 if (3 == trmm_single_gridflag)
1181 this->sptype = TRMML3S_V7;
1182 else if (3 == trmm_swathflag)
1183 this->sptype = TRMML2_V7;
1184 else if (trmm_multi_gridflag >3)
1185 this->sptype = TRMML3M_V7;
1191 if (this->sptype == OTHERHDF) {
1193 int metadataflag = 0;
1195 for (
const auto &attr:this->sd->getAttributes ()) {
1196 if (attr->getName () ==
"CoreMetadata.0")
1198 if (attr->getName () ==
"ArchiveMetadata.0")
1200 if (attr->getName () ==
"StructMetadata.0")
1202 if (attr->getName ().find (
"SubsettingMethod") !=
1211 if (metadataflag == 4)
1212 this->sptype = MODISARNSS;
1216 if (metadataflag == 2) {
1218 for (
const auto &sdf:this->sd->getFields ()) {
1219 if ((sdf->getName () ==
"geolocation")
1220 && sdf->getNewName ().find (
"DATA_GRANULE") != string::npos
1221 && sdf->getNewName ().find (
"SwathData") != string::npos
1222 && sdf->getRank () == 3) {
1223 this->sptype = TRMML2_V6;
1236 if (this->sptype == OTHERHDF) {
1237 for (
const auto &sdf:this->sd->getFields ()) {
1238 if (sdf->getNewName ().find (
"DATA_GRANULE") != string::npos) {
1239 bool l3b_v6_lonflag =
false;
1240 bool l3b_v6_latflag =
false;
1241 for (std::vector < Dimension * >::const_iterator k =
1242 sdf->getDimensions ().begin ();
1243 k != sdf->getDimensions ().end (); ++k) {
1244 if ((*k)->getSize () == 1440)
1245 l3b_v6_lonflag =
true;
1247 if ((*k)->getSize () == 400)
1248 l3b_v6_latflag =
true;
1250 if (l3b_v6_lonflag ==
true && l3b_v6_latflag ==
true) {
1251 this->sptype = TRMML3B_V6;
1255 bool l3a_v6_latflag =
false;
1256 bool l3a_v6_lonflag =
false;
1258 bool l3c_v6_lonflag =
false;
1259 bool l3c_v6_latflag =
false;
1261 if (sdf->getRank()>2) {
1262 for (
const auto &dim:sdf->getDimensions()) {
1263 if (dim->getSize () == 360)
1264 l3a_v6_lonflag =
true;
1266 if (dim->getSize () == 180)
1267 l3a_v6_latflag =
true;
1269 if (dim->getSize () == 720)
1270 l3c_v6_lonflag =
true;
1272 if (dim->getSize () == 148)
1273 l3c_v6_latflag =
true;
1278 if (
true == l3a_v6_latflag &&
true == l3a_v6_lonflag) {
1279 this->sptype = TRMML3A_V6;
1283 if (
true == l3c_v6_latflag &&
true == l3c_v6_lonflag) {
1284 this->sptype = TRMML3C_V6;
1300 if (this->sptype == OTHERHDF) {
1303 int modisal2flag = 0;
1306 int modistl2flag = 0;
1312 int seawifsl2flag = 0;
1318 int modisal3mflag = 0;
1321 int modistl3mflag = 0;
1324 int octsl3mflag = 0;
1327 int seawifsl3mflag = 0;
1330 int czcsl3mflag = 0;
1336 for (
const auto &attr:this->sd->getAttributes ()) {
1338 if (attr->getName () ==
"Product Name") {
1340 std::string attrvalue (attr->getValue ().begin (),
1341 attr->getValue ().end ());
1342 if ((attrvalue.find_first_of (
'A', 0) == 0)
1343 && (attrvalue.find (
".L2", 0) != std::string::npos))
1345 else if ((attrvalue.find_first_of (
'A', 0) == 0)
1346 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1348 else if ((attrvalue.find_first_of (
'T', 0) == 0)
1349 && (attrvalue.find (
".L2", 0) != std::string::npos))
1351 else if ((attrvalue.find_first_of (
'T', 0) == 0)
1352 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1354 else if ((attrvalue.find_first_of (
'O', 0) == 0)
1355 && (attrvalue.find (
".L2", 0) != std::string::npos))
1357 else if ((attrvalue.find_first_of (
'O', 0) == 0)
1358 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1360 else if ((attrvalue.find_first_of (
'S', 0) == 0)
1361 && (attrvalue.find (
".L2", 0) != std::string::npos))
1363 else if ((attrvalue.find_first_of (
'S', 0) == 0)
1364 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1366 else if ((attrvalue.find_first_of (
'C', 0) == 0)
1367 && ((attrvalue.find (
".L2", 0) != std::string::npos)
1369 (attrvalue.find (
".L1A", 0) != std::string::npos)))
1371 else if ((attrvalue.find_first_of (
'C', 0) == 0)
1372 && (attrvalue.find (
".L3m", 0) != std::string::npos))
1375 if (attr->getName () ==
"Sensor Name") {
1377 std::string attrvalue (attr->getValue ().begin (),
1378 attr->getValue ().end ());
1379 if (attrvalue.find (
"MODISA", 0) != std::string::npos) {
1383 else if (attrvalue.find (
"MODIST", 0) != std::string::npos) {
1387 else if (attrvalue.find (
"OCTS", 0) != std::string::npos) {
1391 else if (attrvalue.find (
"SeaWiFS", 0) != std::string::npos) {
1395 else if (attrvalue.find (
"CZCS", 0) != std::string::npos) {
1401 if ((modisal2flag == 2) || (modisal3mflag == 2)
1402 || (modistl2flag == 2) || (modistl3mflag == 2)
1403 || (octsl2flag == 2) || (octsl3mflag == 2)
1404 || (seawifsl2flag == 2) || (seawifsl3mflag == 2)
1405 || (czcsl2flag == 2) || (czcsl3mflag == 2))
1412 if ((modisal2flag == 2) || (modistl2flag == 2) ||
1413 (octsl2flag == 2) || (seawifsl2flag == 2) || (czcsl2flag == 2))
1414 this->sptype = OBPGL2;
1416 if ((modisal3mflag == 2) ||
1417 (modistl3mflag == 2) || (octsl3mflag == 2) ||
1418 (seawifsl3mflag == 2) || (czcsl3mflag == 2))
1419 this->sptype = OBPGL3;
1436 int32 n_sd_attrs = 0;
1442 int32 dim_sizes[H4_MAX_VAR_DIMS];
1445 int32 n_sds_attrs = 0;
1451 char sds_name[H4_MAX_NC_NAME];
1454 char dim_name[H4_MAX_NC_NAME];
1457 char attr_name[H4_MAX_NC_NAME];
1470 int32 attr_value_count = 0;
1473 auto sd =
new SD ();
1476 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL) {
1478 throw2 (
"SDfileinfo failed ", sdfd);
1482 for (
int sds_index = 0; sds_index < n_sds; sds_index++) {
1488 sds_id = SDselect (sdfd, sds_index);
1489 if (sds_id == FAIL) {
1493 SDendaccess (sds_id);
1494 throw3 (
"SDselect Failed ",
"SDS index ", sds_index);
1498 sds_ref = SDidtoref (sds_id);
1499 if (sds_ref == FAIL) {
1502 SDendaccess (sds_id);
1503 throw3 (
"Cannot obtain SDS reference number",
" SDS ID is ",
1508 status = SDgetinfo (sds_id, sds_name, &field->rank, dim_sizes,
1509 &field->type, &n_sds_attrs);
1510 if (status == FAIL) {
1513 SDendaccess (sds_id);
1514 throw2 (
"SDgetinfo failed ", sds_name);
1518 string tempname (sds_name);
1519 field->name = tempname;
1520 field->newname = field->name;
1521 field->fieldref = sds_ref;
1523 sd->refindexlist[sds_ref] = sds_index;
1526 bool dim_no_dimscale =
false;
1527 vector <int> dimids;
1529 dimids.assign(field->rank,0);
1532 vector <int>num_dim_attrs;
1534 num_dim_attrs.assign(field->rank,0);
1537 for (
int dimindex = 0; dimindex < field->rank; dimindex++) {
1540 int dimid = SDgetdimid (sds_id, dimindex);
1541 if (dimid == FAIL) {
1544 SDendaccess (sds_id);
1545 throw5 (
"SDgetdimid failed ",
"SDS name ", sds_name,
1546 "dim index= ", dimindex);
1550 int32 temp_num_dim_attrs = 0;
1551 status = SDdiminfo (dimid, dim_name, &dim_size, &dim_type, &temp_num_dim_attrs);
1552 if (status == FAIL) {
1555 SDendaccess (sds_id);
1556 throw5 (
"SDdiminfo failed ",
"SDS name ", sds_name,
1557 "dim index= ", dimindex);
1560 num_dim_attrs[dimindex] = temp_num_dim_attrs;
1579 string dim_name_str (dim_name);
1583 auto dim =
new Dimension (dim_name_str, dim_sizes[dimindex], dim_type);
1586 field->dims.push_back (dim);
1590 dimids[dimindex] = dimid;
1591 if (0 == dim_type) {
1592 if (
false == dim_no_dimscale)
1593 dim_no_dimscale =
true;
1594 if ((dim_name_str == field->name) && (1 == field->rank))
1595 field->is_noscale_dim =
true;
1602 if (
true == dim_no_dimscale) {
1604 for (
int dimindex = 0; dimindex < field->rank; dimindex++) {
1606 string dim_name_str = (field->dims)[dimindex]->name;
1609 stringstream out_index;
1610 out_index << dimindex;
1611 index_str = out_index.str();
1612 dim_info->name =
"_dim_" + index_str;
1616 bool dimname_flag =
false;
1618 int32 dummy_type = 0;
1619 int32 dummy_value_count = 0;
1622 for (
int attrindex = 0; attrindex < num_dim_attrs[dimindex]; attrindex++) {
1624 status = SDattrinfo(dimids[dimindex],attrindex,attr_name,
1625 &dummy_type,&dummy_value_count);
1626 if (status == FAIL) {
1629 SDendaccess (sds_id);
1630 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
1633 string tempname2(attr_name);
1634 if (
"name"==tempname2) {
1635 dimname_flag =
true;
1641 for (
int attrindex = 0; attrindex < num_dim_attrs[dimindex]; attrindex++) {
1644 status = SDattrinfo(dimids[dimindex],attrindex,attr_name,
1645 &attr->type,&attr_value_count);
1646 if (status == FAIL) {
1649 SDendaccess (sds_id);
1650 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
1652 string tempname3 (attr_name);
1653 attr->name = tempname3;
1656 attr->newname = tempname3;
1657 attr->count = attr_value_count;
1658 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
1659 if (SDreadattr (dimids[dimindex], attrindex, &attr->value[0]) == -1) {
1662 SDendaccess (sds_id);
1663 throw5 (
"read SDS attribute failed ",
"Field name ",
1664 field->name,
" Attribute name ", attr->name);
1667 dim_info->attrs.push_back (attr);
1673 if (
false == dimname_flag) {
1676 attr->name =
"name";
1677 attr->newname =
"name";
1678 attr->type = DFNT_CHAR;
1679 attr->count = dim_name_str.size();
1680 attr->value.resize(attr->count);
1681 copy(dim_name_str.begin(),dim_name_str.end(),attr->value.begin());
1682 dim_info->attrs.push_back(attr);
1685 field->dims_info.push_back(dim_info);
1690 for (
int attrindex = 0; attrindex < n_sds_attrs; attrindex++) {
1693 SDattrinfo (sds_id, attrindex, attr_name, &attr->type,
1696 if (status == FAIL) {
1700 SDendaccess (sds_id);
1701 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
1704 if (attr !=
nullptr) {
1705 string tempname4 (attr_name);
1706 attr->name = tempname4;
1709 attr->newname = tempname4;
1710 attr->count = attr_value_count;
1711 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
1712 if (SDreadattr (sds_id, attrindex, &attr->value[0]) == -1) {
1713 string temp_field_name = field->name;
1714 string temp_attr_name = attr->name;
1718 SDendaccess (sds_id);
1719 throw5 (
"read SDS attribute failed ",
"Field name ",
1720 temp_field_name,
" Attribute name ", temp_attr_name);
1722 field->attrs.push_back (attr);
1725 SDendaccess (sds_id);
1726 sd->sdfields.push_back (field);
1730 for (
int attrindex = 0; attrindex < n_sd_attrs; attrindex++) {
1733 status = SDattrinfo (sdfd, attrindex, attr_name, &attr->type,
1735 if (status == FAIL) {
1738 throw3 (
"SDattrinfo failed ",
"SD id ", sdfd);
1741 if (attr !=
nullptr) {
1743 std::string tempname5 (attr_name);
1744 attr->name = tempname5;
1748 attr->newname = tempname5;
1749 attr->count = attr_value_count;
1750 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
1751 if (SDreadattr (sdfd, attrindex, &attr->value[0]) == -1) {
1754 throw3 (
"Cannot read SD attribute",
" Attribute name ",
1757 sd->attrs.push_back (attr);
1776 int32 n_sd_attrs = 0;
1782 int extra_sds_index = 0;
1788 int32 dim_sizes[H4_MAX_VAR_DIMS];
1791 int32 n_sds_attrs = 0;
1797 char sds_name[H4_MAX_NC_NAME];
1800 char dim_name[H4_MAX_NC_NAME];
1803 char attr_name[H4_MAX_NC_NAME];
1816 int32 num_dim_attrs = 0;
1819 int32 attr_value_count = 0;
1823 int32 vgroup_id = 0;
1826 int32 lone_vg_number = 0;
1829 int32 num_of_lones = -1;
1831 int32 num_gobjects = 0;
1840 char vgroup_name[VGNAMELENMAX*4];
1841 char vgroup_class[VGNAMELENMAX*4];
1844 char *full_path =
nullptr;
1847 char *cfull_path =
nullptr;
1853 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL) {
1856 throw2 (
"SDfileinfo failed ", sdfd);
1861 for (sds_index = 0; sds_index < n_sds; sds_index++) {
1863 sds_id = SDselect (sdfd, sds_index);
1865 if (sds_id == FAIL) {
1871 SDendaccess (sds_id);
1872 throw3 (
"SDselect Failed ",
"SDS index ", sds_index);
1875 sds_ref = SDidtoref (sds_id);
1876 if (sds_ref == FAIL) {
1879 SDendaccess (sds_id);
1880 throw3 (
"Cannot obtain SDS reference number",
" SDS ID is ",
1883 sd->sds_ref_list.push_back(sds_ref);
1884 SDendaccess(sds_id);
1893 num_of_lones = Vlone (fileid,
nullptr, 0);
1894 if (num_of_lones == FAIL){
1897 throw3 (
"Fail to obtain lone vgroup number",
"file id is", fileid);
1901 if (num_of_lones > 0) {
1905 vector<int32>ref_array;
1906 ref_array.resize(num_of_lones);
1910 num_of_lones = Vlone (fileid, ref_array.data(), num_of_lones);
1911 if (num_of_lones == FAIL) {
1914 throw3 (
"Cannot obtain lone vgroup reference arrays ",
1915 "file id is ", fileid);
1919 for (lone_vg_number = 0; lone_vg_number < num_of_lones;
1923 vgroup_id = Vattach (fileid, ref_array[lone_vg_number],
"r");
1924 if (vgroup_id == FAIL) {
1927 throw3 (
"Vattach failed ",
"Reference number is ",
1928 ref_array[lone_vg_number]);
1931 status = Vgetname (vgroup_id, vgroup_name);
1932 if (status == FAIL) {
1935 Vdetach (vgroup_id);
1936 throw3 (
"Vgetname failed ",
"vgroup_id is ", vgroup_id);
1939 status = Vgetclass (vgroup_id, vgroup_class);
1940 if (status == FAIL) {
1943 Vdetach (vgroup_id);
1944 throw3 (
"Vgetclass failed ",
"vgroup_name is ", vgroup_name);
1948 if (strcmp (vgroup_class, _HDF_ATTRIBUTE) == 0
1949 || strcmp (vgroup_class, _HDF_VARIABLE) == 0
1950 || strcmp (vgroup_class, _HDF_DIMENSION) == 0
1951 || strcmp (vgroup_class, _HDF_UDIMENSION) == 0
1952 || strcmp (vgroup_class, _HDF_CDF) == 0
1953 || strcmp (vgroup_class, GR_NAME) == 0
1954 || strcmp (vgroup_class, RI_NAME) == 0) {
1955 Vdetach (vgroup_id);
1960 num_gobjects = Vntagrefs (vgroup_id);
1961 if (num_gobjects < 0) {
1964 Vdetach (vgroup_id);
1965 throw3 (
"Vntagrefs failed ",
"vgroup_name is ", vgroup_name);
1978 full_path = (
char *) malloc (MAX_FULL_PATH_LEN);
1979 if (full_path ==
nullptr) {
1982 Vdetach (vgroup_id);
1983 throw1 (
"No enough memory to allocate the buffer.");
1986 memset(full_path,
'\0',MAX_FULL_PATH_LEN);
1988 strncpy(full_path,_BACK_SLASH,strlen(_BACK_SLASH));
1989 strncat(full_path, vgroup_name,strlen(vgroup_name));
1991 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
1992 if (cfull_path ==
nullptr) {
1995 Vdetach (vgroup_id);
1996 if (full_path !=
nullptr)
1998 throw1 (
"No enough memory to allocate the buffer.");
2001 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
2002 strncpy (cfull_path, full_path,strlen(full_path));
2005 for (
int i = 0; i < num_gobjects; i++) {
2008 if (Vgettagref (vgroup_id, i, &obj_tag, &obj_ref) == FAIL) {
2011 Vdetach (vgroup_id);
2012 if (full_path !=
nullptr)
2014 if (cfull_path !=
nullptr)
2016 throw5 (
"Vgettagref failed ",
"vgroup_name is ",
2017 vgroup_name,
" reference number is ", obj_ref);
2021 if (Visvg (vgroup_id, obj_ref) == TRUE) {
2022 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
2023 full_path[strlen(cfull_path)]=
'\0';
2028 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
2029 || obj_tag == DFTAG_SD) {
2035 auto temp_str = string(full_path);
2036 if ((temp_str.find(
"Data Fields") != std::string::npos)||
2037 (temp_str.find(
"Geolocation Fields") != std::string::npos))
2038 sd->sds_ref_list.remove(obj_ref);
2046 status = Vdetach (vgroup_id);
2048 if (status == FAIL) {
2051 throw3 (
"Vdetach failed ",
"vgroup_name is ", vgroup_name);
2058 for (
const auto &sds_ref:sd->sds_ref_list) {
2060 extra_sds_index = SDreftoindex(sdfd,sds_ref);
2061 if (extra_sds_index == FAIL) {
2063 throw3(
"SDreftoindex Failed ",
"SDS reference number ", sds_ref);
2067 sds_id = SDselect (sdfd, extra_sds_index);
2068 if (sds_id == FAIL) {
2072 SDendaccess (sds_id);
2073 throw3 (
"SDselect Failed ",
"SDS index ", extra_sds_index);
2077 status = SDgetinfo (sds_id, sds_name, &field->rank, dim_sizes,
2078 &field->type, &n_sds_attrs);
2079 if (status == FAIL) {
2082 SDendaccess (sds_id);
2083 throw2 (
"SDgetinfo failed ", sds_name);
2087 string tempname (sds_name);
2088 field->name = tempname;
2090 field->newname = tempname+
"_"+
"NONEOS";
2091 field->fieldref = sds_ref;
2092 sd->refindexlist[sds_ref] = extra_sds_index;
2095 for (
int dimindex = 0; dimindex < field->rank; dimindex++) {
2097 int dimid = SDgetdimid (sds_id, dimindex);
2098 if (dimid == FAIL) {
2101 SDendaccess (sds_id);
2102 throw5 (
"SDgetdimid failed ",
"SDS name ", sds_name,
2103 "dim index= ", dimindex);
2105 status = SDdiminfo (dimid, dim_name, &dim_size, &dim_type,
2108 if (status == FAIL) {
2111 SDendaccess (sds_id);
2112 throw5 (
"SDdiminfo failed ",
"SDS name ", sds_name,
2113 "dim index= ", dimindex);
2116 string dim_name_str (dim_name);
2120 auto dim =
new Dimension (dim_name_str, dim_sizes[dimindex], dim_type);
2122 field->dims.push_back (dim);
2142 new Dimension (cfdimname, dim_sizes[dimindex], dim_type);
2144 field->correcteddims.push_back (correcteddim);
2149 for (
int attrindex = 0; attrindex < n_sds_attrs; attrindex++) {
2153 status = SDattrinfo (sds_id, attrindex, attr_name, &attr->type,
2155 if (status == FAIL) {
2159 SDendaccess (sds_id);
2160 throw3 (
"SDattrinfo failed ",
"SDS name ", sds_name);
2163 string temp_attrname (attr_name);
2164 attr->name = temp_attrname;
2168 attr->newname = temp_attrname;
2169 attr->count = attr_value_count;
2170 attr->value.resize (attr_value_count * DFKNTsize (attr->type));
2171 if (SDreadattr (sds_id, attrindex, &attr->value[0]) == -1) {
2175 SDendaccess (sds_id);
2176 throw5 (
"read SDS attribute failed ",
"Field name ",
2177 field->name,
" Attribute name ", attr->name);
2179 field->attrs.push_back (attr);
2181 SDendaccess (sds_id);
2182 sd->sdfields.push_back (field);
2193 int32 fieldsize = 0;
2196 int32 fieldtype = 0;
2199 int32 fieldorder = 0;
2202 char *fieldname =
nullptr;
2206 char vdata_name[VSNAMELENMAX];
2208 auto vdata =
new VDATA (obj_ref);
2210 vdata->vdref = obj_ref;
2212 if (VSQueryname (vdata_id, vdata_name) == FAIL){
2214 throw3 (
"VSQueryname failed ",
"vdata id is ", vdata_id);
2217 string vdatanamestr (vdata_name);
2219 vdata->name = vdatanamestr;
2221 int32 num_field = VFnfields (vdata_id);
2223 if (num_field == -1){
2225 throw3 (
"For vdata, VFnfields failed. ",
"vdata name is ",
2229 int32 num_record = VSelts (vdata_id);
2231 if (num_record == -1) {
2233 throw3 (
"For vdata, VSelts failed. ",
"vdata name is ", vdata->name);
2244 if (num_record <= 10 &&
true == HDF4RequestHandler::get_enable_vdata_attr())
2245 vdata->TreatAsAttrFlag =
true;
2247 vdata->TreatAsAttrFlag =
false;
2250 for (
int i = 0; i < num_field; i++) {
2254 if (field ==
nullptr) {
2256 throw1(
"Memory allocation for field class failed.");
2259 fieldsize = VFfieldesize (vdata_id, i);
2260 if (fieldsize == FAIL) {
2261 string temp_vdata_name = vdata->name;
2264 throw5 (
"For vdata field, VFfieldsize failed. ",
"vdata name is ",
2265 temp_vdata_name,
" index is ", i);
2268 fieldname = VFfieldname (vdata_id, i);
2269 if (fieldname ==
nullptr) {
2270 string temp_vdata_name = vdata->name;
2273 throw5 (
"For vdata field, VFfieldname failed. ",
"vdata name is ",
2274 temp_vdata_name,
" index is ", i);
2277 fieldtype = VFfieldtype (vdata_id, i);
2278 if (fieldtype == FAIL) {
2279 string temp_vdata_name = vdata->name;
2282 throw5 (
"For vdata field, VFfieldtype failed. ",
"vdata name is ",
2283 temp_vdata_name,
" index is ", i);
2286 fieldorder = VFfieldorder (vdata_id, i);
2287 if (fieldorder == FAIL) {
2288 string temp_vdata_name = vdata->name;
2291 throw5 (
"For vdata field, VFfieldtype failed. ",
"vdata name is ",
2292 temp_vdata_name,
" index is ", i);
2295 if (fieldname !=
nullptr)
2296 field->name = fieldname;
2298 field->type = fieldtype;
2299 field->order = fieldorder;
2300 field->size = fieldsize;
2302 field->numrec = num_record;
2305 if (vdata->getTreatAsAttrFlag () && num_record > 0) {
2307 field->value.resize (num_record * fieldsize);
2308 if (VSseek (vdata_id, 0) == FAIL) {
2309 if (field !=
nullptr)
2311 if (vdata !=
nullptr)
2313 throw5 (
"vdata ", vdata_name,
"field ", fieldname,
2317 if (VSsetfields (vdata_id, fieldname) == FAIL) {
2318 if (field !=
nullptr)
2320 if (vdata !=
nullptr)
2322 throw3 (
"vdata field ", fieldname,
" VSsetfields failed.");
2326 (vdata_id, (uint8 *) & field->value[0], num_record,
2327 FULL_INTERLACE) == FAIL){
2328 if (field !=
nullptr)
2330 if (vdata !=
nullptr)
2332 throw3 (
"vdata field ", fieldname,
" VSread failed.");
2337 if (field !=
nullptr) {
2340 field->ReadAttributes (vdata_id, i);
2347 vdata->vdfields.push_back (field);
2353 vdata->ReadAttributes (vdata_id);
2370 char attr_name[H4_MAX_NC_NAME];
2382 nattrs = VSfnattrs (vdata_id, _HDF_VDATA);
2387 for (
int i = 0; i < nattrs; i++) {
2391 status = VSattrinfo (vdata_id, _HDF_VDATA, i, attr_name,
2392 &attr->type, &attr->count, &attrsize);
2393 if (status == FAIL) {
2395 throw5 (
"VSattrinfo failed ",
"vdata id is ", vdata_id,
2396 " attr index is ", i);
2400 string tempname(attr_name);
2401 if (attr !=
nullptr) {
2402 attr->name = tempname;
2404 attr->value.resize (attrsize);
2406 if (VSgetattr (vdata_id, _HDF_VDATA, i, &attr->value[0]) == FAIL) {
2408 throw5 (
"VSgetattr failed ",
"vdata id is ", vdata_id,
2409 " attr index is ", i);
2411 attrs.push_back (attr);
2425 char attr_name[H4_MAX_NC_NAME];
2437 nattrs = VSfnattrs (vdata_id, fieldindex);
2442 for (
int i = 0; i < nattrs; i++) {
2446 status = VSattrinfo (vdata_id, fieldindex, i, attr_name,
2447 &attr->type, &attr->count, &attrsize);
2449 if (status == FAIL) {
2451 throw5 (
"VSattrinfo failed ",
"vdata field index ",
2452 fieldindex,
" attr index is ", i);
2455 if (attr !=
nullptr) {
2457 string tempname(attr_name);
2458 attr->name = tempname;
2463 attr->value.resize (attrsize);
2464 if (VSgetattr (vdata_id, fieldindex, i, &attr->value[0]) == FAIL) {
2466 throw5 (
"VSgetattr failed ",
"vdata field index is ",
2467 fieldindex,
" attr index is ", i);
2469 attrs.push_back (attr);
2479 char attr_name[H4_MAX_NC_NAME];
2482 intn n_attrs = Vnattrs(vgroup_id);
2483 if (n_attrs == FAIL)
2484 throw1(
"Vnattrs failed");
2487 string temp_container_name(fullpath);
2491 for(
int attr_index = 0; attr_index <n_attrs; attr_index++) {
2494 int32 value_size_32 = 0;
2495 status_n = Vattrinfo(vgroup_id, attr_index, attr_name, &attr->type,
2496 &attr->count, &value_size_32);
2497 if (status_n == FAIL) {
2499 throw1(
"Vattrinfo failed.");
2501 int value_size = value_size_32;
2503 string tempname (attr_name);
2504 if (attr !=
nullptr) {
2505 attr->name = tempname;
2507 attr->newname = tempname;
2508 attr->value.resize (value_size);
2510 status_n = Vgetattr(vgroup_id,(intn)attr_index,&attr->value[0]);
2511 if (status_n == FAIL) {
2514 throw3(
"Vgetattr failed. ",
"The attribute name is ",attr->name);
2516 vg_attr->attrs.push_back(attr);
2520 if (vg_attr !=
nullptr)
2521 vg_attrs.push_back(vg_attr);
2540 int32 vgroup_id = 0;
2546 int32 num_of_lones = -1;
2549 int32 num_gobjects = 0;
2559 char vdata_name[VSNAMELENMAX];
2562 char vdata_class[VSNAMELENMAX];
2565 char vgroup_name[VGNAMELENMAX*4];
2568 char vgroup_class[VGNAMELENMAX*4];
2571 char *full_path =
nullptr;
2574 char *cfull_path =
nullptr;
2579 file_id = this->fileid;
2585 num_of_lones = Vlone (file_id,
nullptr, 0);
2586 if (num_of_lones == FAIL)
2587 throw3 (
"Fail to obtain lone vgroup number",
"file id is", file_id);
2590 if (num_of_lones > 0) {
2594 vector<int32>ref_array;
2595 ref_array.resize(num_of_lones);
2599 num_of_lones = Vlone (file_id, ref_array.data(), num_of_lones);
2600 if (num_of_lones == FAIL) {
2601 throw3 (
"Cannot obtain lone vgroup reference arrays ",
2602 "file id is ", file_id);
2606 for (
int lone_vg_number = 0; lone_vg_number < num_of_lones;
2610 vgroup_id = Vattach (file_id, ref_array[lone_vg_number],
"r");
2611 if (vgroup_id == FAIL) {
2612 throw3 (
"Vattach failed ",
"Reference number is ",
2613 ref_array[lone_vg_number]);
2616 status = Vgetname (vgroup_id, vgroup_name);
2617 if (status == FAIL) {
2618 Vdetach (vgroup_id);
2619 throw3 (
"Vgetname failed ",
"vgroup_id is ", vgroup_id);
2622 status = Vgetclass (vgroup_id, vgroup_class);
2623 if (status == FAIL) {
2624 Vdetach (vgroup_id);
2625 throw3 (
"Vgetclass failed ",
"vgroup_name is ", vgroup_name);
2629 if (strcmp (vgroup_class, _HDF_ATTRIBUTE) == 0
2630 || strcmp (vgroup_class, _HDF_VARIABLE) == 0
2631 || strcmp (vgroup_class, _HDF_DIMENSION) == 0
2632 || strcmp (vgroup_class, _HDF_UDIMENSION) == 0
2633 || strcmp (vgroup_class, _HDF_CDF) == 0
2634 || strcmp (vgroup_class, GR_NAME) == 0
2635 || strcmp (vgroup_class, RI_NAME) == 0) {
2640 num_gobjects = Vntagrefs (vgroup_id);
2641 if (num_gobjects < 0) {
2642 Vdetach (vgroup_id);
2643 throw3 (
"Vntagrefs failed ",
"vgroup_name is ", vgroup_name);
2651 full_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2652 if (full_path ==
nullptr) {
2653 Vdetach (vgroup_id);
2654 throw1 (
"No enough memory to allocate the buffer.");
2657 memset(full_path,
'\0',MAX_FULL_PATH_LEN);
2658 strncpy (full_path,_BACK_SLASH,strlen(_BACK_SLASH));
2659 strncat(full_path,vgroup_name,strlen(vgroup_name));
2666 Vdetach (vgroup_id);
2668 throw1 (
"ReadVgattrs failed ");
2670 strncat(full_path,_BACK_SLASH,strlen(_BACK_SLASH));
2672 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2673 if (cfull_path ==
nullptr) {
2674 Vdetach (vgroup_id);
2676 throw1 (
"No enough memory to allocate the buffer.");
2679 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
2680 strncpy (cfull_path, full_path,strlen(full_path));
2684 for (
int i = 0; i < num_gobjects; i++) {
2685 if (Vgettagref (vgroup_id, i, &obj_tag, &obj_ref) == FAIL) {
2686 Vdetach (vgroup_id);
2689 throw5 (
"Vgettagref failed ",
"vgroup_name is ",
2690 vgroup_name,
" reference number is ", obj_ref);
2694 if (Visvg (vgroup_id, obj_ref) == TRUE) {
2695 strncpy (full_path, cfull_path,strlen(cfull_path)+1);
2696 full_path[strlen(cfull_path)]=
'\0';
2700 else if (Visvs (vgroup_id, obj_ref)) {
2702 vdata_id = VSattach (file_id, obj_ref,
"r");
2703 if (vdata_id == FAIL) {
2704 Vdetach (vgroup_id);
2707 throw5 (
"VSattach failed ",
"vgroup_name is ",
2708 vgroup_name,
" reference number is ",
2711 status = VSgetname (vdata_id, vdata_name);
2712 if (status == FAIL) {
2713 Vdetach (vgroup_id);
2716 throw5 (
"VSgetclass failed ",
"vgroup_name is ",
2717 vgroup_name,
" reference number is ",
2721 status = VSgetclass (vdata_id, vdata_class);
2722 if (status == FAIL) {
2723 Vdetach (vgroup_id);
2726 throw5 (
"VSgetclass failed ",
"vgroup_name is ",
2727 vgroup_name,
" reference number is ",
2740 if (VSisattr (vdata_id) == TRUE
2741 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
2742 strlen (_HDF_CHK_TBL_CLASS))
2743 || !strncmp (vdata_class, _HDF_SDSVAR,
2744 strlen (_HDF_SDSVAR))
2745 || !strncmp (vdata_class, _HDF_CRDVAR,
2746 strlen (_HDF_CRDVAR))
2747 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
2748 || !strncmp (vdata_class, DIM_VALS01,
2749 strlen (DIM_VALS01))
2750 || !strncmp (vdata_class, RIGATTRCLASS,
2751 strlen (RIGATTRCLASS))
2752 || !strncmp (vdata_name, RIGATTRNAME,
2753 strlen (RIGATTRNAME))) {
2755 status = VSdetach (vdata_id);
2756 if (status == FAIL) {
2757 Vdetach (vgroup_id);
2760 throw3 (
"VSdetach failed ",
2761 "Vdata is under vgroup ", vgroup_name);
2767 VDATA*vdataobj =
nullptr;
2775 Vdetach (vgroup_id);
2780 vdataobj->newname = full_path +vdataobj->name;
2785 for (
const auto &vdf:vdataobj->
getFields ()) {
2791 "vdata" + vdataobj->newname +
"_vdf_" + vdf->name;
2800 this->vds.push_back (vdataobj);
2802 status = VSdetach (vdata_id);
2803 if (status == FAIL) {
2804 Vdetach (vgroup_id);
2807 throw3 (
"VSdetach failed ",
2808 "Vdata is under vgroup ", vgroup_name);
2814 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
2815 || obj_tag == DFTAG_SD) {
2818 if (this->sd->refindexlist.find (obj_ref) != sd->refindexlist.end ()) {
2822 if (full_path !=
nullptr) {
2823 this->sd->sdfields[this->sd->refindexlist[obj_ref]]->newname =
2825 this->sd->sdfields[this->sd->refindexlist[obj_ref]]->name;
2829 Vdetach (vgroup_id);
2832 throw3 (
"SDS with the reference number ", obj_ref,
2840 status = Vdetach (vgroup_id);
2841 if (status == FAIL) {
2842 throw3 (
"Vdetach failed ",
"vgroup_name is ", vgroup_name);
2857 int32 vgroup_pid = -1;
2866 int num_gobjects = 0;
2874 char cvgroup_name[VGNAMELENMAX*4];
2877 char vdata_name[VSNAMELENMAX];
2880 char vdata_class[VSNAMELENMAX];
2883 int32 vdata_id = -1;
2892 char *cfull_path =
nullptr;
2894 bool unexpected_fail =
false;
2896 vgroup_pid = Vattach (file_id, pobj_ref,
"r");
2897 if (vgroup_pid == FAIL)
2898 throw3 (
"Vattach failed ",
"Object reference number is ", pobj_ref);
2901 if (Vgetname (vgroup_pid, cvgroup_name) == FAIL) {
2902 Vdetach (vgroup_pid);
2903 throw3 (
"Vgetname failed ",
"Object reference number is ", pobj_ref);
2905 num_gobjects = Vntagrefs (vgroup_pid);
2906 if (num_gobjects < 0) {
2907 Vdetach (vgroup_pid);
2908 throw3 (
"Vntagrefs failed ",
"Object reference number is ", pobj_ref);
2919 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
2920 if (cfull_path ==
nullptr)
2921 throw1 (
"No enough memory to allocate the buffer");
2923 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
2925 strncpy(cfull_path,full_path,strlen(full_path));
2926 strncat(cfull_path,cvgroup_name,strlen(cvgroup_name));
2932 Vdetach (vgroup_pid);
2934 throw1 (
"ReadVgattrs failed ");
2937 strncat(cfull_path,_BACK_SLASH,strlen(_BACK_SLASH));
2943 for (i = 0; i < num_gobjects; i++) {
2945 if (Vgettagref (vgroup_pid, i, &obj_tag, &obj_ref) == FAIL) {
2946 unexpected_fail =
true;
2947 err_msg = string(ERR_LOC) +
" Vgettagref failed. ";
2951 if (Visvg (vgroup_pid, obj_ref) == TRUE) {
2952 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
2953 full_path[strlen(cfull_path)]=
'\0';
2956 else if (Visvs (vgroup_pid, obj_ref)) {
2958 vdata_id = VSattach (file_id, obj_ref,
"r");
2959 if (vdata_id == FAIL) {
2960 unexpected_fail =
true;
2961 err_msg = string(ERR_LOC) +
" VSattach failed. ";
2965 status = VSQueryname (vdata_id, vdata_name);
2966 if (status == FAIL) {
2967 unexpected_fail =
true;
2968 err_msg = string(ERR_LOC) +
" VSQueryname failed. ";
2972 status = VSgetclass (vdata_id, vdata_class);
2973 if (status == FAIL) {
2974 unexpected_fail =
true;
2975 err_msg = string(ERR_LOC) +
" VSgetclass failed. ";
2979 if (VSisattr (vdata_id) != TRUE) {
2981 (vdata_class, _HDF_CHK_TBL_CLASS,
2982 strlen (_HDF_CHK_TBL_CLASS))) {
2984 VDATA *vdataobj =
nullptr;
2992 Vdetach (vgroup_pid);
2998 vdataobj->newname = cfull_path + vdataobj->name;
3002 for (std::vector <VDField * >::const_iterator it_vdf =
3004 it_vdf != vdataobj->
getFields ().end ();
3009 (*it_vdf)->newname =
3010 "vdata" + vdataobj->newname +
"_vdf_" +
3018 this->vds.push_back (vdataobj);
3021 status = VSdetach (vdata_id);
3022 if (status == FAIL) {
3023 unexpected_fail =
true;
3024 err_msg = string(ERR_LOC) +
" VSdetach failed. ";
3028 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
3029 || obj_tag == DFTAG_SD) {
3031 if (this->sd->refindexlist.find (obj_ref) !=
3032 this->sd->refindexlist.end ())
3033 this->sd->sdfields[this->sd->refindexlist[obj_ref]]->newname =
3035 cfull_path + this->sd->sdfields[this->sd->refindexlist[obj_ref]]->name;
3037 unexpected_fail =
true;
3038 stringstream temp_ss;
3040 err_msg = string(ERR_LOC) +
"SDS with the reference number"
3041 + temp_ss.str() +
" is not found.";
3050 if (vdata_id != -1) {
3051 status = VSdetach(vdata_id);
3052 if (status == FAIL) {
3053 Vdetach(vgroup_pid);
3054 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" VSdetached failed. ";
3055 err_msg = err_msg + err_msg2;
3058 else if (
true == unexpected_fail)
3063 if (vgroup_pid != -1) {
3064 status = Vdetach(vgroup_pid);
3065 if (status == FAIL) {
3066 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" VSdetached failed. ";
3067 err_msg = err_msg + err_msg2;
3070 else if (
true == unexpected_fail)
3086 int32 vgroup_cid = -1;
3088 int num_gobjects = 0;
3093 char cvgroup_name[VGNAMELENMAX*4];
3097 char *cfull_path =
nullptr;
3099 bool unexpected_fail =
false;
3101 vgroup_cid = Vattach (file_id, pobj_ref,
"r");
3102 if (vgroup_cid == FAIL)
3103 throw3 (
"Vattach failed ",
"Object reference number is ", pobj_ref);
3105 if (Vgetname (vgroup_cid, cvgroup_name) == FAIL) {
3106 Vdetach (vgroup_cid);
3107 throw3 (
"Vgetname failed ",
"Object reference number is ", pobj_ref);
3109 num_gobjects = Vntagrefs (vgroup_cid);
3110 if (num_gobjects < 0) {
3111 Vdetach (vgroup_cid);
3112 throw3 (
"Vntagrefs failed ",
"Object reference number is ", pobj_ref);
3124 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
3125 if (cfull_path ==
nullptr)
3126 throw1 (
"No enough memory to allocate the buffer");
3128 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
3132 strncpy(cfull_path,full_path,strlen(full_path));
3133 strncat(cfull_path,cvgroup_name,strlen(cvgroup_name));
3134 strncat(cfull_path,_BACK_SLASH,strlen(_BACK_SLASH));
3138 for (
int i = 0; i < num_gobjects; i++) {
3140 if (Vgettagref (vgroup_cid, i, &obj_tag, &obj_ref) == FAIL) {
3141 unexpected_fail =
true;
3142 err_msg = string(ERR_LOC) +
" Vgettagref failed. ";
3146 if (Visvg (vgroup_cid, obj_ref) == TRUE) {
3147 strncpy (full_path, cfull_path,strlen(cfull_path)+1);
3148 full_path[strlen(cfull_path)]=
'\0';
3151 else if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG
3152 || obj_tag == DFTAG_SD) {
3158 string temp_str = string(cfull_path);
3159 if ((temp_str.find(
"Data Fields") != std::string::npos)||
3160 (temp_str.find(
"Geolocation Fields") != std::string::npos))
3161 sds_ref_list.remove(obj_ref);
3166 if (vgroup_cid != -1) {
3167 status = Vdetach(vgroup_cid);
3168 if (status == FAIL) {
3169 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" Vdetached failed. ";
3170 err_msg = err_msg + err_msg2;
3173 else if (
true == unexpected_fail)
3189 int32 vgroup_cid = -1;
3192 int num_gobjects = -1;
3197 char cvgroup_name[VGNAMELENMAX*4];
3198 char vdata_name[VSNAMELENMAX];
3199 char vdata_class[VSNAMELENMAX];
3200 int32 vdata_id = -1;
3203 char *cfull_path =
nullptr;
3206 bool unexpected_fail =
false;
3217 cfull_path = (
char *) malloc (MAX_FULL_PATH_LEN);
3218 if (cfull_path ==
nullptr)
3219 throw1 (
"No enough memory to allocate the buffer");
3221 memset(cfull_path,
'\0',MAX_FULL_PATH_LEN);
3223 vgroup_cid = Vattach (file_id, pobj_ref,
"r");
3224 if (vgroup_cid == FAIL) {
3225 unexpected_fail =
true;
3226 err_msg = string(ERR_LOC)+
"Vattach failed";
3230 if (Vgetname (vgroup_cid, cvgroup_name) == FAIL) {
3231 unexpected_fail =
true;
3232 err_msg = string(ERR_LOC)+
"Vgetname failed";
3235 num_gobjects = Vntagrefs (vgroup_cid);
3236 if (num_gobjects < 0) {
3237 unexpected_fail =
true;
3238 err_msg = string(ERR_LOC)+
"Vntagrefs failed";
3242 strncpy(cfull_path,full_path,strlen(full_path));
3243 strncat(cfull_path,cvgroup_name,strlen(cvgroup_name));
3244 strncat(cfull_path,_BACK_SLASH,strlen(_BACK_SLASH));
3248 temp_str = string(cfull_path);
3250 if (temp_str.find(
"Geolocation Fields") != string::npos) {
3251 if (
false == this->EOS2Swathflag)
3252 this->EOS2Swathflag =
true;
3255 for (i = 0; i < num_gobjects; i++) {
3257 if (Vgettagref (vgroup_cid, i, &obj_tag, &obj_ref) == FAIL) {
3258 unexpected_fail =
true;
3259 err_msg = string(ERR_LOC)+
"Vgettagref failed";
3263 if (Visvg (vgroup_cid, obj_ref) == TRUE) {
3264 strncpy(full_path,cfull_path,strlen(cfull_path)+1);
3265 full_path[strlen(cfull_path)] =
'\0';
3268 else if (Visvs (vgroup_cid, obj_ref)) {
3270 vdata_id = VSattach (file_id, obj_ref,
"r");
3271 if (vdata_id == FAIL) {
3272 unexpected_fail =
true;
3273 err_msg = string(ERR_LOC)+
"VSattach failed";
3277 status = VSQueryname (vdata_id, vdata_name);
3278 if (status == FAIL) {
3279 unexpected_fail =
true;
3280 err_msg = string(ERR_LOC)+
"VSQueryname failed";
3284 status = VSgetclass (vdata_id, vdata_class);
3285 if (status == FAIL) {
3286 unexpected_fail =
true;
3287 err_msg = string(ERR_LOC)+
"VSgetclass failed";
3292 string temp_str2 = string(cfull_path);
3302 bool ignore_eos2_geo_vdata =
false;
3303 bool ignore_eos2_data_vdata =
false;
3304 if (temp_str2.find(
"Geolocation Fields") != string::npos) {
3305 ignore_eos2_geo_vdata =
true;
3309 if (temp_str2.find(
"Data Fields") != string::npos) {
3310 if (
true == this->EOS2Swathflag)
3311 ignore_eos2_data_vdata =
true;
3313 if ((
true == ignore_eos2_data_vdata)
3314 ||(
true == ignore_eos2_geo_vdata)
3315 || VSisattr (vdata_id) == TRUE
3316 || !strncmp (vdata_class, _HDF_CHK_TBL_CLASS,
3317 strlen (_HDF_CHK_TBL_CLASS))
3318 || !strncmp (vdata_class, _HDF_SDSVAR,
3319 strlen (_HDF_SDSVAR))
3320 || !strncmp (vdata_class, _HDF_CRDVAR,
3321 strlen (_HDF_CRDVAR))
3322 || !strncmp (vdata_class, DIM_VALS, strlen (DIM_VALS))
3323 || !strncmp (vdata_class, DIM_VALS01,
3324 strlen (DIM_VALS01))
3325 || !strncmp (vdata_class, RIGATTRCLASS,
3326 strlen (RIGATTRCLASS))
3327 || !strncmp (vdata_name, RIGATTRNAME,
3328 strlen (RIGATTRNAME))) {
3330 status = VSdetach (vdata_id);
3331 if (status == FAIL) {
3332 unexpected_fail =
true;
3333 err_msg = string(ERR_LOC)+
"VSdetach failed";
3339 VDATA *vdataobj =
nullptr;
3346 Vdetach (vgroup_cid);
3351 vdataobj->newname = cfull_path + vdataobj->name;
3355 for (std::vector <VDField * >::const_iterator it_vdf =
3357 it_vdf != vdataobj->
getFields ().end ();
3362 (*it_vdf)->newname =
3363 "vdata" + vdataobj->newname +
"_vdf_" +
3371 this->vds.push_back (vdataobj);
3372 status = VSdetach (vdata_id);
3373 if (status == FAIL) {
3374 unexpected_fail =
true;
3375 err_msg = string(ERR_LOC)+
"VSdetach failed";
3384 if (vgroup_cid != -1) {
3385 status = Vdetach(vgroup_cid);
3386 if (status == FAIL) {
3387 string err_msg2 =
"In the cleanup " + string(ERR_LOC) +
" Vdetached failed. ";
3388 err_msg = err_msg + err_msg2;
3389 throw3(err_msg,
"vgroup name is ",cvgroup_name);
3391 else if (
true == unexpected_fail)
3392 throw3(err_msg,
"vgroup name is ",cvgroup_name);
3414 std::string tempdimname;
3415 std::pair < std::set < std::string >::iterator,
bool > ret;
3416 std::string temppath;
3417 std::set < int32 > fakedimsizeset;
3418 std::pair < std::set < int32 >::iterator,
bool > fakedimsizeit;
3419 std::map < int32, std::string > fakedimsizenamelist;
3420 std::map < int32, std::string >::iterator fakedimsizenamelistit;
3422 for (
const auto &sdf:file->sd->sdfields) {
3424 for (
const auto &sdim:sdf->getDimensions ()) {
3427 if (file->sptype != OTHERHDF)
3428 tempdimname = sdim->getName ();
3430 tempdimname = sdim->getName () + temppath;
3433 new Dimension (tempdimname, sdim->getSize (),
3435 sdf->correcteddims.push_back (dim);
3436 if (tempdimname.find (
"fakeDim") != std::string::npos) {
3437 fakedimsizeit = fakedimsizeset.insert (sdim->getSize ());
3438 if (fakedimsizeit.second ==
true) {
3439 fakedimsizenamelist[sdim->getSize ()] = sdim->getName ();
3449 if (file->sptype != OTHERHDF) {
3450 for (std::vector < SDField * >::const_iterator i =
3451 file->sd->sdfields.begin (); i != file->sd->sdfields.end (); ++i) {
3452 for (std::vector < Dimension * >::const_iterator j =
3453 (*i)->getCorrectedDimensions ().begin ();
3454 j != (*i)->getCorrectedDimensions ().end (); ++j) {
3455 if ((*j)->getName ().find (
"fakeDim") != std::string::npos) {
3456 if (fakedimsizenamelist.find ((*j)->getSize ()) !=
3457 fakedimsizenamelist.end ()) {
3458 (*j)->name = fakedimsizenamelist[(*j)->getSize ()];
3461 throw5 (
"The fakeDim name ", (*j)->getName (),
3462 "with the size", (*j)->getSize (),
3463 "does not in the fakedimsize list");
3476 for (
const auto &sdf:file->sd->sdfields) {
3477 for (
const auto &dim:sdf->getCorrectedDimensions ()) {
3478 std::pair < std::set < std::string >::iterator,
bool > ret;
3479 ret = file->sd->fulldimnamelist.insert (dim->getName ());
3482 if (ret.second ==
true) {
3483 file->sd->n1dimnamelist[dim->getName ()] = dim->getSize ();
3493 const File *file =
this;
3501 for (std::map < std::string, int32 >::const_iterator i =
3502 file->sd->n1dimnamelist.begin ();
3503 i != file->sd->n1dimnamelist.end (); ++i) {
3506 if (file->sd->nonmisscvdimnamelist.find ((*i).first) == file->sd->nonmisscvdimnamelist.end ()) {
3508 auto missingfield =
new SDField ();
3513 missingfield->type = DFNT_INT32;
3514 missingfield->name = (*i).first;
3515 missingfield->newname = (*i).first;
3516 missingfield->rank = 1;
3517 missingfield->fieldtype = 4;
3518 auto dim =
new Dimension ((*i).first, (*i).second, 0);
3520 missingfield->dims.push_back (dim);
3521 dim =
new Dimension ((*i).first, (*i).second, 0);
3522 missingfield->correcteddims.push_back (dim);
3523 file->sd->sdfields.push_back (missingfield);
3538 vector<string>tempfulldimnamelist;
3540 for (
const auto &dimname:file->sd->fulldimnamelist)
3546 int total_dcounter = 0;
3547 for (
const auto &dimname:file->sd->fulldimnamelist) {
3553 std::map < std::string, std::string >::iterator tempmapit;
3554 for (
const auto &sfd:file->sd->sdfields) {
3555 for (
const auto &dim:sfd->getCorrectedDimensions ()) {
3556 tempmapit = file->sd->n2dimnamelist.find (dim->getName ());
3557 if (tempmapit != file->sd->n2dimnamelist.end ())
3558 dim->name = tempmapit->second;
3560 throw5 (
"This dimension with the name ", dim->name,
3561 "and the field name ", sfd->name,
3562 " is not found in the dimension list.");
3585 if (
true == HDF4RequestHandler::get_enable_ceres_merra_short_name() && (file->sptype == CER_ES4 || file->sptype == CER_SRB
3586 || file->sptype == CER_CDAY || file->sptype == CER_CGEO
3587 || file->sptype == CER_SYN || file->sptype == CER_ZAVG
3588 || file->sptype == CER_AVG)) {
3591 for (
auto &sdf:file->sd->sdfields) {
3592 sdf->special_product_fullpath = sdf->newname;
3593 sdf->newname = sdf->name;
3599 vector<string>sd_data_fieldnamelist;
3600 vector<string>sd_latlon_fieldnamelist;
3601 vector<string>sd_nollcv_fieldnamelist;
3603 set<string>sd_fieldnamelist;
3605 for (std::vector < SDField * >::const_iterator i =
3606 file->sd->sdfields.begin (); i != file->sd->sdfields.end (); ++i) {
3607 if ((*i)->fieldtype ==0)
3609 else if ((*i)->fieldtype == 1 || (*i)->fieldtype == 2)
3622 int total_data_counter = 0;
3623 int total_latlon_counter = 0;
3624 int total_nollcv_counter = 0;
3627 std::map < std::string, std::string >::iterator tempmapit;
3630 for (
const auto &sdf:file->sd->sdfields) {
3645 if (sdf->fieldtype != 0) {
3646 if (sdf->fieldtype == 1 || sdf->fieldtype == 2) {
3648 sdf->newname = sd_latlon_fieldnamelist[total_latlon_counter];
3649 total_latlon_counter++;
3651 if (sdf->getRank () > 2)
3652 throw3 (
"the lat/lon rank should NOT be greater than 2",
3653 sdf->name, sdf->getRank ());
3654 else if (sdf->getRank () == 2) {
3655 for (
const auto &dim:sdf->getCorrectedDimensions()) {
3657 file->sd->dimcvarlist.find (dim->getName ());
3658 if (tempmapit == file->sd->dimcvarlist.end ()) {
3662 if (lldimname1 ==
"")
3663 lldimname1 =dim->name;
3665 lldimname2 = dim->name;
3675 sdf->getCorrectedDimensions ()[0]->getName ();
3676 HDFCFUtil::insert_map(file->sd->dimcvarlist, sdf->getCorrectedDimensions()[0]->getName(), sdf->newname);
3682 sdf->newname = sd_data_fieldnamelist[total_data_counter];
3683 total_data_counter++;
3687 for (
const auto &sdf:file->sd->sdfields) {
3702 if (sdf->fieldtype != 0) {
3705 if (sdf->fieldtype != 1 && sdf->fieldtype != 2) {
3707 sdf->newname = sd_nollcv_fieldnamelist[total_nollcv_counter];
3708 total_nollcv_counter++;
3710 if (sdf->getRank () > 1)
3711 throw3 (
"The lat/lon rank should be 1", sdf->name,
3717 sdf->newname = sdf->getCorrectedDimensions ()[0]->getName ();
3718 HDFCFUtil::insert_map(file->sd->dimcvarlist, sdf->getCorrectedDimensions()[0]->getName(), sdf->newname);
3733 std::map < std::string, std::string >::iterator tempmapit;
3735 std::string tempcoordinates;
3736 std::string tempfieldname;
3737 for (
const auto &sdf:file->sd->sdfields) {
3738 if (sdf->fieldtype == 0) {
3740 tempcoordinates =
"";
3743 for (
const auto &dim:sdf->getCorrectedDimensions()) {
3744 tempmapit = (file->sd->dimcvarlist).find (dim->getName ());
3745 if (tempmapit != (file->sd->dimcvarlist).end ())
3746 tempfieldname = tempmapit->second;
3748 throw3 (
"The dimension with the name ", dim->getName (),
3749 "must have corresponding coordinate variables.");
3751 tempcoordinates = tempfieldname;
3753 tempcoordinates = tempcoordinates +
" " + tempfieldname;
3756 sdf->setCoordinates (tempcoordinates);
3760 if (sdf->fieldtype == 1) {
3761 std::string tempunits =
"degrees_north";
3762 sdf->setUnits (tempunits);
3765 if (sdf->fieldtype == 2) {
3766 std::string tempunits =
"degrees_east";
3767 sdf->setUnits (tempunits);
3771 if ((sdf->fieldtype == 3) || (sdf->fieldtype == 4)) {
3772 std::string tempunits =
"level";
3773 sdf->setUnits (tempunits);
3781 if (
false == COARDFLAG) {
3782 for (
const auto &sdf:file->sd->sdfields) {
3783 if (sdf->fieldtype == 0) {
3784 bool has_lldim1 =
false;
3785 bool has_lldim2 =
false;
3786 for (
const auto &dim:sdf->getCorrectedDimensions()) {
3787 if (lldimname1 == dim->name)
3789 else if (lldimname2 == dim->name)
3794 if (has_lldim1^has_lldim2)
3795 sdf->coordinates =
"";
3807 const File *file =
this;
3815 if (
false == HDF4RequestHandler::get_disable_vdata_nameclashing_check()) {
3817 vector<string> tempvdatafieldnamelist;
3819 for (
const auto &vd:file->vds)
3820 for (
const auto &vdf:vd->getFields())
3821 tempvdatafieldnamelist.push_back(vdf->newname);
3825 int total_vfd_counter = 0;
3827 for (
const auto &vd:file->vds) {
3828 for (
const auto &vdf:vd->getFields()) {
3829 vdf->newname = tempvdatafieldnamelist[total_vfd_counter];
3830 total_vfd_counter++;
3853 if (file->sptype != OTHERHDF) {
3855 for (
const auto &sdf:file->sd->sdfields) {
3857 j!= sdf->dims_info.end(); ) {
3859 j = sdf->dims_info.erase(j);
3861 if (sdf->dims_info.empty()==
false )
3862 throw1(
"Not totally erase the dimension container ");
3872 switch (file->sptype) {
3967 throw3 (
"No such SP datatype ",
"sptype is ", sptype);
3982 bool COARDFLAG =
false;
4000 for (
const auto &attr:this->sd->getAttributes()) {
4002 if (attr->getName () ==
"GridHeader") {
4003 float lat_start = 0.;
4004 float lon_start = 0.;
4008 HDFCFUtil::parser_trmm_v7_gridheader(attr->getValue(),latsize,lonsize,
4009 lat_start,lon_start,
4010 lat_res,lon_res,
false);
4020bool File:: Obtain_TRMM_V7_latlon_name(
const SDField* sdfield,
const int latsize,
4021 const int lonsize,
string& latname,
string& lonname) {
4023 int latname_index = -1;
4024 int lonname_index = -1;
4025 for (
int temp_index = 0; temp_index <sdfield->
getRank(); ++temp_index) {
4027 latname_index = temp_index;
4031 lonname_index = temp_index;
4036 return (latname_index + lonname_index == 1);
4046 std::string tempdimname1;
4047 std::string tempdimname2;
4048 std::string tempnewdimname1;
4049 std::string tempnewdimname2;
4050 std::string temppath;
4053 std::set < int32 > tempdimsizeset;
4054 std::map < int32, std::string > tempdimsizenamelist;
4055 std::map < int32, std::string >::iterator tempsizemapit;
4056 std::pair < std::set < int32 >::iterator,
bool > tempsetit;
4059 for (
const auto &sdf:file->sd->sdfields) {
4060 for (
const auto &dim:sdf->getCorrectedDimensions()) {
4061 if ((dim->getName ()).find (
"fakeDim") == std::string::npos) {
4062 tempsetit = tempdimsizeset.insert (dim->getSize ());
4063 if (tempsetit.second ==
true)
4064 tempdimsizenamelist[dim->getSize ()] = dim->getName ();
4070 for (
const auto &sdf:file->sd->sdfields) {
4071 string temp_name = sdf->newname.substr(1) ;
4072 size_t temp_pos = temp_name.find_first_of(
'/');
4073 if (temp_pos !=string::npos)
4074 sdf->newname = temp_name.substr(temp_pos+1);
4077 for (
const auto &sdf:file->sd->sdfields) {
4079 if (sdf->getName() ==
"Latitude") {
4080 if (sdf->getRank() ==2) {
4083 (sdf->getCorrectedDimensions ())[0]->getName ();
4085 (sdf->getCorrectedDimensions ())[1]->getName ();
4091 else if (sdf->getName() ==
"Longitude") {
4099 for (
const auto &dim:sdf->getCorrectedDimensions ()) {
4100 size_t fakeDimpos = (dim->getName ()).find (
"fakeDim");
4102 if (fakeDimpos != std::string::npos) {
4104 tempdimsizenamelist.find (dim->getSize ());
4105 if (tempsizemapit != tempdimsizenamelist.end ())
4106 dim->name = tempdimsizenamelist[dim->getSize ()];
4113 if (tempnewdimname1.empty()!=
true)
4114 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
4116 if (tempnewdimname2.empty()!=
true)
4117 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
4119 string base_filename;
4120 size_t last_slash_pos = file->
getPath().find_last_of(
"/");
4121 if (last_slash_pos != string::npos)
4122 base_filename = file->
getPath().substr(last_slash_pos+1);
4123 if (
""==base_filename)
4124 base_filename = file->
getPath();
4126 if (base_filename.find(
"2A12")!=string::npos) {
4129 string nlayer_name =
"nlayer";
4131 for (
const auto &sdf:file->sd->sdfields) {
4133 bool has_nlayer =
false;
4135 for (
const auto &sdim:sdf->getDimensions()) {
4137 if (sdim->getSize() == 28 && sdim->name == nlayer_name) {
4140 nlayer->
name = nlayer_name;
4142 nlayer->
type = DFNT_FLOAT32;
4143 nlayer->fieldtype = 6;
4146 auto dim =
new Dimension (nlayer->
name, sdim->getSize (), 0);
4147 nlayer->dims.push_back(dim);
4150 nlayer->correcteddims.push_back(cdim);
4157 if (
true == has_nlayer)
4161 if (nlayer !=
nullptr) {
4162 file->sd->sdfields.push_back(nlayer);
4163 file->sd->nonmisscvdimnamelist.insert (nlayer_name);
4172 for (std::vector < SDField * >::iterator i =
4173 file->sd->sdfields.begin (); i != file->sd->sdfields.end (); ) {
4176 if ((*i)->name ==
"InputFileNames") {
4178 i = file->sd->sdfields.erase(i);
4180 else if ((*i)->name ==
"InputAlgorithmVersions") {
4182 i = file->sd->sdfields.erase(i);
4184 else if ((*i)->name ==
"InputGenerationDateTimes") {
4186 i = file->sd->sdfields.erase(i);
4189 (*i)->newname = (*i)->name;
4196 string nlayer_name =
"nlayer";
4198 for (
const auto &sdf:file->sd->sdfields) {
4200 bool has_nlayer =
false;
4202 for (
const auto &sdim:sdf->getDimensions()) {
4204 if (sdim->getSize() == 28 && sdim->name == nlayer_name) {
4207 nlayer->
name = nlayer_name;
4209 nlayer->
type = DFNT_FLOAT32;
4210 nlayer->fieldtype = 6;
4213 auto dim =
new Dimension (nlayer->
name, sdim->getSize(), 0);
4214 nlayer->dims.push_back(dim);
4217 nlayer->correcteddims.push_back(cdim);
4225 if (
true == has_nlayer)
4229 if (nlayer !=
nullptr) {
4230 file->sd->sdfields.push_back(nlayer);
4231 file->sd->nonmisscvdimnamelist.insert (nlayer_name);
4242 bool llname_found =
false;
4243 for (
const auto &sdf:file->sd->sdfields) {
4245 if (2 == sdf->getRank()) {
4247 llname_found = Obtain_TRMM_V7_latlon_name(sdf,latsize,lonsize,latname,lonname);
4248 if (
true == llname_found)
4255 auto longitude =
new SDField ();
4256 longitude->name = lonname;
4257 longitude->rank = 1;
4258 longitude->type = DFNT_FLOAT32;
4259 longitude->fieldtype = 2;
4261 longitude->newname = longitude->name;
4262 auto dim =
new Dimension (lonname, lonsize, 0);
4263 longitude->dims.push_back (dim);
4265 auto cdim =
new Dimension (lonname, lonsize, 0);
4266 longitude->correcteddims.push_back (cdim);
4267 file->sd->sdfields.push_back(longitude);
4269 auto latitude =
new SDField ();
4270 latitude->name = latname;
4272 latitude->type = DFNT_FLOAT32;
4273 latitude->fieldtype = 1;
4275 latitude->newname = latitude->name;
4276 auto latdim =
new Dimension (latname, latsize, 0);
4277 latitude->dims.push_back (latdim);
4279 auto latcdim =
new Dimension (latname, latsize, 0);
4280 latitude->correcteddims.push_back (latcdim);
4281 file->sd->sdfields.push_back(latitude);
4284 file->sd->nonmisscvdimnamelist.insert (latname);
4285 file->sd->nonmisscvdimnamelist.insert (lonname);
4290 string base_filename;
4291 if (path.find_last_of(
"/") != string::npos)
4292 base_filename = path.substr(path.find_last_of(
"/")+1);
4293 if (base_filename.find(
"3A26")!=string::npos) {
4295 bool ZOflag =
false;
4296 bool SRTflag =
false;
4297 bool HBflag =
false;
4298 string nthrsh_base_name =
"nthrsh";
4299 string nthrsh_zo_name =
"nthrshZO";
4300 string nthrsh_hb_name =
"nthrshHB";
4301 string nthrsh_srt_name =
"nthrshSRT";
4305 SDField* nthrsh_srt =
nullptr;
4307 for (
const auto &sdf:file->sd->sdfields) {
4309 if (ZOflag !=
true) {
4310 if (sdf->name.find(
"Order")!=string::npos) {
4311 for (
const auto &sdim:sdf->getDimensions()) {
4312 if (sdim->getSize() == 6 && sdim->name == nthrsh_base_name) {
4313 if (nthrsh_zo ==
nullptr) {
4315 nthrsh_zo->
name = nthrsh_zo_name;
4316 nthrsh_zo->
rank = 1;
4317 nthrsh_zo->
type = DFNT_FLOAT32;
4318 nthrsh_zo->fieldtype = 6;
4321 auto nz_dim =
new Dimension (nthrsh_zo->
name, sdim->getSize (), 0);
4322 nthrsh_zo->dims.push_back(nz_dim);
4324 auto nz_cdim =
new Dimension(nthrsh_zo->
name,sdim->getSize(),0);
4325 nthrsh_zo->correcteddims.push_back(nz_cdim);
4336 else if (SRTflag !=
true) {
4337 if (sdf->name.find(
"2A25")!=string::npos) {
4339 for (
const auto &sdim:sdf->getDimensions ()) {
4341 if (sdim->getSize() == 6 && sdim->name == nthrsh_base_name) {
4342 if (nthrsh_srt ==
nullptr) {
4344 nthrsh_srt->
name = nthrsh_srt_name;
4345 nthrsh_srt->
rank = 1;
4346 nthrsh_srt->
type = DFNT_FLOAT32;
4347 nthrsh_srt->fieldtype = 6;
4350 auto ns_dim =
new Dimension (nthrsh_srt->
name, sdim->getSize (), 0);
4351 nthrsh_srt->dims.push_back(ns_dim);
4353 auto ns_cdim =
new Dimension(nthrsh_srt->
name,sdim->getSize(),0);
4354 nthrsh_srt->correcteddims.push_back(ns_cdim);
4362 else if (HBflag !=
true) {
4363 if (sdf->name.find(
"hb")!=string::npos || sdf->name.find(
"HB")!=string::npos) {
4365 for (
const auto &sdim:sdf->getDimensions ()) {
4367 if (sdim->getSize() == 6 && sdim->name == nthrsh_base_name) {
4369 if (nthrsh_hb ==
nullptr) {
4371 nthrsh_hb->
name = nthrsh_hb_name;
4372 nthrsh_hb->
rank = 1;
4373 nthrsh_hb->
type = DFNT_FLOAT32;
4374 nthrsh_hb->fieldtype = 6;
4377 auto nh_dim =
new Dimension (nthrsh_hb->
name, sdim->getSize (), 0);
4378 nthrsh_hb->dims.push_back(nh_dim);
4380 auto nh_cdim =
new Dimension(nthrsh_hb->
name,sdim->getSize(),0);
4381 nthrsh_hb->correcteddims.push_back(nh_cdim);
4392 for (
const auto &sdf:file->sd->sdfields) {
4394 if (sdf->name.find(
"Order")!=string::npos && ZOflag ==
true) {
4395 for (
const auto &sdim:sdf->getDimensions()) {
4396 if (sdim->getSize() == 6 && sdim->name == nthrsh_base_name) {
4397 sdim->name = nthrsh_zo_name;
4402 for (
const auto &cor_dim:sdf->getCorrectedDimensions()) {
4403 if (cor_dim->getSize() == 6 && cor_dim->name == nthrsh_base_name) {
4404 cor_dim->name = nthrsh_zo_name;
4411 else if ((sdf->name.find(
"hb")!=string::npos || sdf->name.find(
"HB")!=string::npos)&& HBflag ==
true) {
4412 for (
const auto &sdim:sdf->getDimensions()) {
4413 if (sdim->getSize() == 6 && sdim->name == nthrsh_base_name) {
4414 sdim->name = nthrsh_hb_name;
4419 for (
const auto &cor_dim:sdf->getCorrectedDimensions()) {
4420 if (cor_dim->getSize() == 6 && cor_dim->name == nthrsh_base_name) {
4421 cor_dim->name = nthrsh_hb_name;
4427 else if ((sdf->name.find(
"2A25")!=string::npos) && SRTflag ==
true) {
4428 for (
const auto &sdim:sdf->getDimensions()) {
4429 if (sdim->getSize() == 6 && sdim->name == nthrsh_base_name) {
4430 sdim->name = nthrsh_srt_name;
4435 for (
const auto &cor_dim:sdf->getCorrectedDimensions()) {
4436 if (cor_dim->getSize() == 6 && cor_dim->name == nthrsh_base_name) {
4437 cor_dim->name = nthrsh_srt_name;
4444 if (nthrsh_zo !=
nullptr) {
4445 file->sd->sdfields.push_back(nthrsh_zo);
4446 file->sd->nonmisscvdimnamelist.insert (nthrsh_zo_name);
4449 if (nthrsh_hb !=
nullptr) {
4450 file->sd->sdfields.push_back(nthrsh_hb);
4451 file->sd->nonmisscvdimnamelist.insert (nthrsh_hb_name);
4454 if (nthrsh_srt !=
nullptr) {
4455 file->sd->sdfields.push_back(nthrsh_srt);
4456 file->sd->nonmisscvdimnamelist.insert (nthrsh_srt_name);
4466 for (std::vector < SDField * >::iterator i =
4467 file->sd->sdfields.begin (); i != file->sd->sdfields.end (); ) {
4469 if ((*i)->name ==
"InputFileNames") {
4471 i = file->sd->sdfields.erase(i);
4473 else if ((*i)->name ==
"InputAlgorithmVersions") {
4475 i = file->sd->sdfields.erase(i);
4477 else if ((*i)->name ==
"InputGenerationDateTimes") {
4479 i = file->sd->sdfields.erase(i);
4508 int first_index = -1;
4509 for (
const auto &attr:this->sd->getAttributes()) {
4511 if (attr->getName ().find(
"GridHeader")==0) {
4512 string temp_name = attr->getName();
4515 string str_num = temp_name.substr(10);
4516 stringstream ss_num(str_num);
4519 ss_num >> grid_index;
4521 if ( -1 == first_index)
4522 first_index = grid_index;
4524 float lat_start = 0.;
4525 float lon_start = 0.;
4532 HDFCFUtil::parser_trmm_v7_gridheader(attr->getValue(),latsize,lonsize,
4533 lat_start,lon_start,
4534 lat_res, lon_res,
false);
4543 bool llname_found =
false;
4544 for (
const auto &sdf:file->sd->sdfields) {
4547 if (2 == sdf->getRank()) {
4550 if (sdf->newname !=sdf->name) {
4552 string temp_field_full_path = sdf->getNewName();
4553 size_t last_path_pos = temp_field_full_path.find_last_of(
'/');
4554 char str_index = temp_field_full_path[last_path_pos-1];
4555 if (grid_index ==(
int)(str_index -
'0')) {
4556 if (llname_found !=
true)
4557 llname_found = Obtain_TRMM_V7_latlon_name(sdf,latsize,lonsize,latname,lonname);
4558 sdf->newname = sdf->name;
4562 else if (first_index == grid_index)
4563 sdf->newname = sdf->name;
4567 auto longitude =
new SDField ();
4568 longitude->name = lonname;
4569 longitude->rank = 1;
4570 longitude->type = DFNT_FLOAT32;
4571 longitude->fieldtype = 2;
4572 longitude->fieldref = grid_index;
4574 longitude->newname = longitude->name;
4575 auto lon_dim =
new Dimension (lonname, lonsize, 0);
4576 longitude->dims.push_back (lon_dim);
4578 auto lon_cdim =
new Dimension (lonname, lonsize, 0);
4579 longitude->correcteddims.push_back(lon_cdim);
4580 file->sd->sdfields.push_back(longitude);
4582 auto latitude =
new SDField ();
4583 latitude->name = latname;
4585 latitude->type = DFNT_FLOAT32;
4586 latitude->fieldtype = 1;
4587 latitude->fieldref = grid_index;
4589 latitude->newname = latitude->name;
4590 auto lat_dim =
new Dimension (latname, latsize, 0);
4591 latitude->dims.push_back (lat_dim);
4593 auto lat_cdim =
new Dimension (latname, latsize, 0);
4594 latitude->correcteddims.push_back (lat_cdim);
4595 file->sd->sdfields.push_back(latitude);
4598 file->sd->nonmisscvdimnamelist.insert (latname);
4599 file->sd->nonmisscvdimnamelist.insert (lonname);
4615 std::string tempdimname1;
4616 std::string tempdimname2;
4617 std::string tempnewdimname1;
4618 std::string tempnewdimname2;
4619 std::string temppath;
4627 std::set < int32 > tempdimsizeset;
4628 std::map < int32, std::string > tempdimsizenamelist;
4629 std::map < int32, std::string >::iterator tempsizemapit;
4630 std::pair < std::set < int32 >::iterator,
bool > tempsetit;
4633 for (
const auto &sdf:file->sd->sdfields) {
4634 for (
const auto &dim:sdf->getCorrectedDimensions()) {
4635 if ((dim->getName ()).find (
"fakeDim") == std::string::npos) {
4636 tempsetit = tempdimsizeset.insert (dim->getSize ());
4637 if (tempsetit.second ==
true)
4638 tempdimsizenamelist[dim->getSize ()] = dim->getName ();
4643 for (
const auto &sdf:file->sd->sdfields) {
4645 if (sdf->getName () ==
"geolocation") {
4649 tempdimname1 = (sdf->getDimensions ())[0]->getName ();
4650 tempdimsize1 = (sdf->getDimensions ())[0]->getSize ();
4651 tempdimname2 = (sdf->getDimensions ())[1]->getName ();
4652 tempdimsize2 = (sdf->getDimensions ())[1]->getSize ();
4655 (sdf->getCorrectedDimensions ())[0]->getName ();
4657 (sdf->getCorrectedDimensions ())[1]->getName ();
4665 if (latitude ==
nullptr) {
4668 latitude->
name =
"latitude";
4670 latitude->fieldref = sdf->fieldref;
4671 latitude->
type = sdf->getType ();
4672 temppath = sdf->newname.substr (sdf->name.size ());
4674 latitude->fieldtype = 1;
4675 latitude->rootfieldname =
"geolocation";
4677 auto lat_dim =
new Dimension (tempdimname1, tempdimsize1, 0);
4679 latitude->dims.push_back (lat_dim);
4681 auto lat_dim2 =
new Dimension (tempdimname2, tempdimsize2, 0);
4682 latitude->dims.push_back (lat_dim2);
4684 auto lat_cdim =
new Dimension (tempnewdimname1, tempdimsize1, 0);
4685 latitude->correcteddims.push_back (lat_cdim);
4687 auto lat_cdim2 =
new Dimension (tempnewdimname2, tempdimsize2, 0);
4688 latitude->correcteddims.push_back (lat_cdim2);
4691 if (longitude ==
nullptr) {
4693 longitude->
name =
"longitude";
4694 longitude->
rank = 2;
4695 longitude->fieldref = sdf->fieldref;
4696 longitude->
type = sdf->getType ();
4698 longitude->fieldtype = 2;
4699 longitude->rootfieldname =
"geolocation";
4701 auto lon_dim =
new Dimension (tempdimname1, tempdimsize1, 0);
4702 longitude->dims.push_back (lon_dim);
4703 auto lon_dim2 =
new Dimension (tempdimname2, tempdimsize2, 0);
4704 longitude->dims.push_back (lon_dim2);
4706 auto lon_cdim =
new Dimension (tempnewdimname1, tempdimsize1, 0);
4707 longitude->correcteddims.push_back (lon_cdim);
4709 auto lon_cdim2 =
new Dimension (tempnewdimname2, tempdimsize2, 0);
4710 longitude->correcteddims.push_back (lon_cdim2);
4718 for (
const auto &dim:sdf->getCorrectedDimensions()) {
4719 size_t fakeDimpos = (dim->getName ()).find (
"fakeDim");
4721 if (fakeDimpos != std::string::npos) {
4723 tempdimsizenamelist.find (dim->getSize ());
4724 if (tempsizemapit != tempdimsizenamelist.end ())
4725 dim->name = tempdimsizenamelist[dim->getSize ()];
4731 file->sd->sdfields.push_back (latitude);
4732 file->sd->sdfields.push_back (longitude);
4738 std::vector < SDField * >::iterator toeraseit;
4739 for (std::vector < SDField * >::iterator i = file->sd->sdfields.begin ();
4740 i != file->sd->sdfields.end (); ++i) {
4741 if ((*i)->getName () ==
"geolocation") {
4748 file->sd->sdfields.erase (toeraseit);
4749 if (origeo !=
nullptr)
4753 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
4754 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
4763 string tempnewdimname1;
4764 string tempnewdimname2;
4773 for (
const auto &sdf:file->sd->sdfields) {
4775 for (
const auto &sdim:sdf->getDimensions()) {
4778 if (((sdim->getName ()).find (
"fakeDim")) == std::string::npos) {
4780 temppath = sdf->newname.substr (sdf->name.size ());
4783 if (sdim->getSize () == 1440 && sdim->getType () == 0) {
4785 if (longitude ==
nullptr) {
4787 longitude->
name =
"longitude";
4788 longitude->
rank = 1;
4789 longitude->
type = DFNT_FLOAT32;
4790 longitude->fieldtype = 2;
4793 auto dim =
new Dimension (sdim->getName (), sdim->getSize (), 0);
4794 longitude->dims.push_back (dim);
4795 tempnewdimname2 = sdim->getName ();
4796 auto cdim =
new Dimension (sdim->getName (), sdim->getSize (), 0);
4797 longitude->correcteddims.push_back (cdim);
4802 if (sdim->getSize () == 400 && sdim->getType () == 0) {
4804 if (latitude ==
nullptr) {
4806 latitude->
name =
"latitude";
4808 latitude->
type = DFNT_FLOAT32;
4809 latitude->fieldtype = 1;
4811 auto dim =
new Dimension (sdim->getName (), sdim->getSize (), 0);
4812 latitude->dims.push_back (dim);
4813 tempnewdimname1 = sdim->getName ();
4823 auto cdim =
new Dimension (sdim->getName (), sdim->getSize (), 0);
4824 latitude->correcteddims.push_back (cdim);
4830 if (latflag == 1 && lonflag == 1)
4834 if (latflag == 1 && lonflag == 1)
4843 if (latflag != 1 || lonflag != 1) {
4844 if (latitude !=
nullptr)
4846 if (longitude !=
nullptr)
4848 throw5 (
"Either latitude or longitude doesn't exist.",
"lat. flag= ",
4849 latflag,
"lon. flag= ", lonflag);
4851 file->sd->sdfields.push_back (latitude);
4852 file->sd->sdfields.push_back (longitude);
4856 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
4857 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
4865 std::string tempnewdimname1;
4866 std::string tempnewdimname2;
4867 bool latflag =
false;
4868 bool lonflag =
false;
4874 for (
const auto &sdf:file->sd->sdfields) {
4875 for (
const auto &dim:sdf->getDimensions()) {
4876 if (((dim->getName ()).find (
"latitude")) == 0)
4877 dim->name =
"fakeDim1";
4878 if (((dim->getName()).find (
"longitude")) == 0)
4879 dim->name =
"fakeDim2";
4884 for (
const auto &dim:sdf->getCorrectedDimensions()) {
4885 if (((dim->getName ()).find (
"latitude")) == 0)
4886 dim->name =
"fakeDim1";
4887 if (((dim->getName()).find (
"longitude")) == 0)
4888 dim->name =
"fakeDim2";
4892 for (
const auto &sdf:file->sd->sdfields) {
4894 for (
const auto &sdim:sdf->getDimensions()) {
4898 if (sdim->getSize () == 360 && sdim->getType () == 0) {
4900 if (longitude ==
nullptr) {
4902 longitude->
name =
"longitude";
4903 longitude->
rank = 1;
4904 longitude->
type = DFNT_FLOAT32;
4905 longitude->fieldtype = 2;
4909 longitude->dims.push_back (dim);
4910 tempnewdimname2 = longitude->
name;
4913 longitude->correcteddims.push_back (cdim);
4918 if (sdim->getSize () == 180 && sdim->getType () == 0) {
4920 if (latitude ==
nullptr) {
4922 latitude->
name =
"latitude";
4924 latitude->
type = DFNT_FLOAT32;
4925 latitude->fieldtype = 1;
4929 latitude->dims.push_back (dim);
4930 tempnewdimname1 = latitude->
getName ();
4933 latitude->correcteddims.push_back (cdim);
4938 if (latflag ==
true && lonflag ==
true)
4942 if (latflag ==
true && lonflag ==
true)
4951 if (latflag !=
true || lonflag !=
true) {
4952 if (latitude !=
nullptr)
4954 if (longitude !=
nullptr)
4956 throw5 (
"Either latitude or longitude doesn't exist.",
"lat. flag= ",
4957 latflag,
"lon. flag= ", lonflag);
4962 for (
const auto &sdf:file->sd->sdfields) {
4964 for (
const auto &dim:sdf->getDimensions()) {
4966 if (dim->getSize () == 360 )
4967 dim->name = longitude->
name;
4969 if (dim->getSize () == 180 )
4970 dim->name = latitude->
name;
4974 for (
const auto &dim:sdf->getCorrectedDimensions()) {
4976 if (dim->getSize () == 360 )
4977 dim->name = longitude->
name;
4979 if (dim->getSize () == 180 )
4980 dim->name = latitude->
name;
4987 file->sd->sdfields.push_back (latitude);
4988 file->sd->sdfields.push_back (longitude);
4993 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
4994 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
5003 std::string tempnewdimname1;
5004 std::string tempnewdimname2;
5005 std::string tempnewdimname3;
5006 bool latflag =
false;
5007 bool lonflag =
false;
5008 bool heiflag =
false;
5016 for (
const auto &sdf:file->sd->sdfields) {
5018 for (
const auto &sdim:sdf->getDimensions()) {
5022 if (sdim->getSize () == 720 && sdim->getType () == 0) {
5025 if (longitude ==
nullptr) {
5027 longitude->
name =
"longitude";
5028 longitude->
rank = 1;
5029 longitude->
type = DFNT_FLOAT32;
5030 longitude->fieldtype = 2;
5034 longitude->dims.push_back (dim);
5035 tempnewdimname2 = longitude->
name;
5038 longitude->correcteddims.push_back (cdim);
5043 if (sdim->getSize () == 148 && sdim->getType () == 0) {
5045 if (latitude ==
nullptr) {
5047 latitude->
name =
"latitude";
5049 latitude->
type = DFNT_FLOAT32;
5050 latitude->fieldtype = 1;
5054 latitude->dims.push_back (dim);
5055 tempnewdimname1 = latitude->
getName ();
5058 latitude->correcteddims.push_back (cdim);
5063 if (sdim->getSize () == 19 && sdim->getType () == 0) {
5065 if (height ==
nullptr) {
5067 height->
name =
"height";
5069 height->
type = DFNT_FLOAT32;
5070 height->fieldtype = 6;
5074 height->dims.push_back (dim);
5075 tempnewdimname3 = height->
getName ();
5078 height->correcteddims.push_back (cdim);
5084 if (latflag ==
true && lonflag ==
true)
5094 if (latflag !=
true || lonflag !=
true) {
5095 if (latitude !=
nullptr)
5097 if (longitude !=
nullptr)
5099 throw5 (
"Either latitude or longitude doesn't exist.",
"lat. flag= ",
5100 latflag,
"lon. flag= ", lonflag);
5103 if (height!=
nullptr && heiflag !=
true) {
5105 throw1(
"Height is allocated but the flag is not true");
5109 file->sd->sdfields.push_back (latitude);
5110 file->sd->sdfields.push_back (longitude);
5112 if (height!=
nullptr) {
5114 if (heiflag !=
true) {
5116 throw1(
"Height is allocated but the flag is not true");
5119 file->sd->sdfields.push_back (height);
5120 file->sd->nonmisscvdimnamelist.insert (tempnewdimname3);
5125 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
5126 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
5135 int pixels_per_scan_line = 0;
5137 string pixels_per_scan_line_name =
"Pixels per Scan Line";
5138 string number_pixels_control_points =
"Number of Pixel Control Points";
5139 string tempnewdimname1;
5140 string tempnewdimname2;
5146 if (attr->getName () == pixels_per_scan_line_name) {
5147 auto attrvalueptr = (
int *) (&(attr->getValue ()[0]));
5148 pixels_per_scan_line = *attrvalueptr;
5153 if ( 0 == pixels_per_scan_line)
5154 throw1(
"The attribute 'Pixels per Scan Line' doesn't exist");
5158 int tempcountllflag = 0;
5160 for (
const auto &sdf:file->sd->sdfields) {
5162 if (sdf->getName () ==
"longitude" || sdf->getName () ==
"latitude") {
5163 if (sdf->getName () ==
"longitude")
5165 if (sdf->getName () ==
"latitude")
5169 if (sdf->getRank () != 2)
5170 throw3 (
"The lat/lon rank must be 2", sdf->getName (),
5172 for (
const auto &dim:sdf->getDimensions()) {
5173 if (dim->getName () == number_pixels_control_points) {
5174 dim->name = pixels_per_scan_line_name;
5175 dim->dimsize = pixels_per_scan_line;
5180 for (
const auto &dim:sdf->getCorrectedDimensions()) {
5181 if (dim->getName ().find (number_pixels_control_points) !=
5182 std::string::npos) {
5183 dim->name = pixels_per_scan_line_name;
5184 dim->dimsize = pixels_per_scan_line;
5185 if (tempcountllflag == 1)
5186 tempnewdimname2 = dim->name;
5189 if (tempcountllflag == 1)
5190 tempnewdimname1 = dim->name;
5194 if (tempcountllflag == 2)
5201 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
5202 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
5213 std::string num_lat_name =
"Number of Lines";
5214 std::string num_lon_name =
"Number of Columns";
5220 int tempcountllflag = 0;
5224 if (attr->getName () == num_lon_name) {
5227 auto attrvalue = (
int *) (&(attr->getValue ()[0]));
5229 num_lon = *attrvalue;
5233 if (attr->getName () == num_lat_name) {
5235 auto attrvalue = (
int *) (&(attr->getValue ()[0]));
5237 num_lat = *attrvalue;
5240 if (tempcountllflag == 2)
5245 auto longitude =
new SDField ();
5246 if (longitude ==
nullptr)
5247 throw1(
"Allocate memory for longitude failed .");
5249 longitude->name =
"longitude";
5250 longitude->rank = 1;
5251 longitude->type = DFNT_FLOAT32;
5252 longitude->fieldtype = 2;
5255 longitude->newname = longitude->name;
5258 throw3(
"The size of the dimension of the longitude ",longitude->name,
" is 0.");
5261 auto lon_dim =
new Dimension (num_lon_name, num_lon, 0);
5262 if (lon_dim ==
nullptr) {
5264 throw1(
"Allocate memory for longitude dim failed .");
5267 longitude->dims.push_back (lon_dim);
5270 auto lon_cdim =
new Dimension (num_lon_name, num_lon, 0);
5271 if (lon_cdim ==
nullptr) {
5273 throw1(
"Allocate memory for corrected longitude dim failed .");
5275 longitude->correcteddims.push_back (lon_cdim);
5278 auto latitude =
new SDField ();
5279 if (latitude ==
nullptr) {
5281 throw1(
"Allocate memory for dim failed .");
5283 latitude->name =
"latitude";
5285 latitude->type = DFNT_FLOAT32;
5286 latitude->fieldtype = 1;
5289 latitude->newname = latitude->name;
5293 throw3(
"The size of the dimension of the latitude ",latitude->name,
" is 0.");
5296 auto lat_dim =
new Dimension (num_lat_name, num_lat, 0);
5297 if ( lat_dim ==
nullptr) {
5300 throw1(
"Allocate memory for latitude dim failed .");
5303 if (latitude !=
nullptr)
5304 latitude->dims.push_back (lat_dim);
5307 auto lat_cdim =
new Dimension (num_lat_name, num_lat, 0);
5308 if (lat_cdim ==
nullptr) {
5311 throw1(
"Allocate memory for dim failed .");
5313 latitude->correcteddims.push_back (lat_cdim);
5316 for (
const auto &sdf:file->sd->sdfields) {
5317 if (sdf->getRank () != 2) {
5320 throw3 (
"The lat/lon rank must be 2", sdf->getName (),
5323 for (
const auto &dim:sdf->getDimensions()) {
5324 if (((dim->getName ()).find (
"fakeDim")) != std::string::npos) {
5325 if (dim->getSize () == num_lon)
5326 dim->name = num_lon_name;
5327 if (dim->getSize () == num_lat)
5328 dim->name = num_lat_name;
5331 for (
const auto &dim:sdf->getCorrectedDimensions()) {
5332 if (((dim->getName ()).find (
"fakeDim")) != std::string::npos) {
5333 if (dim->getSize () == num_lon)
5334 dim->name = num_lon_name;
5335 if (dim->getSize () == num_lat)
5336 dim->name = num_lat_name;
5340 file->sd->sdfields.push_back (latitude);
5341 file->sd->sdfields.push_back (longitude);
5344 file->sd->nonmisscvdimnamelist.insert (num_lat_name);
5345 file->sd->nonmisscvdimnamelist.insert (num_lon_name);
5355 bool colatflag =
false;
5356 bool lonflag =
false;
5358 std::string tempnewdimname1;
5359 std::string tempnewdimname2;
5360 std::string tempcvarname1;
5361 std::string tempcvarname2;
5365 for (std::vector < SDField * >::iterator i = file->sd->sdfields.begin ();
5366 i != file->sd->sdfields.end (); ) {
5369 if (((*i)->getName ()).find (
"Colatitude") != std::string::npos) {
5371 if ((*i)->getRank () != 2)
5372 throw3 (
"The lat/lon rank must be 2", (*i)->getName (),
5374 int dimsize0 = (*i)->getDimensions ()[0]->getSize ();
5375 int dimsize1 = (*i)->getDimensions ()[1]->getSize ();
5380 if (dimsize0 < dimsize1) {
5381 tempnewdimname1 = (*i)->getDimensions ()[0]->getName ();
5382 tempnewdimname2 = (*i)->getDimensions ()[1]->getName ();
5385 tempnewdimname1 = (*i)->getDimensions ()[1]->getName ();
5386 tempnewdimname2 = (*i)->getDimensions ()[0]->getName ();
5391 (*i)->fieldtype = 1;
5392 tempcvarname1 = (*i)->getName ();
5398 i = file->sd->sdfields.erase (i);
5402 else if (((*i)->getName ()).find (
"Longitude") != std::string::npos) {
5405 (*i)->fieldtype = 2;
5406 tempcvarname2 = (*i)->getName ();
5411 i = file->sd->sdfields.erase (i);
5419 file->sd->nonmisscvdimnamelist.insert (tempnewdimname1);
5420 file->sd->nonmisscvdimnamelist.insert (tempnewdimname2);
5429 std::string tempdimname1;
5430 std::string tempdimname2;
5431 int tempdimsize1 = 0;
5432 int tempdimsize2 = 0;
5433 std::string tempcvarname1;
5434 std::string tempcvarname2;
5435 std::string temppath;
5436 std::set < std::string > tempdimnameset;
5437 std::pair < std::set < std::string >::iterator,
bool > tempsetit;
5439 bool cvflag =
false;
5444 for (std::vector < SDField * >::iterator i = file->sd->sdfields.begin ();
5445 i != file->sd->sdfields.end (); ) {
5446 std::string tempfieldname = (*i)->getName ();
5447 if (tempfieldname.find (
"Colatitude") != std::string::npos) {
5449 for (std::vector < Dimension * >::const_iterator j =
5450 (*i)->getDimensions ().begin ();
5451 j != (*i)->getDimensions ().end (); ++j) {
5452 if (((*j)->getName ()).find (
"regional colat") !=
5453 std::string::npos) {
5454 tempsetit = tempdimnameset.insert ((*j)->getName ());
5455 if (tempsetit.second ==
true) {
5456 tempdimname1 = (*j)->getName ();
5457 tempdimsize1 = (*j)->getSize ();
5458 (*i)->fieldtype = 1;
5468 for (std::vector < Dimension * >::const_iterator j =
5469 (*i)->getDimensions ().begin ();
5470 j != (*i)->getDimensions ().end (); ++j)
5472 for (std::vector < Dimension * >::const_iterator j =
5473 (*i)->getCorrectedDimensions ().begin ();
5474 j != (*i)->getCorrectedDimensions ().end (); ++j)
5476 (*i)->dims.clear ();
5477 (*i)->correcteddims.clear ();
5479 auto dim =
new Dimension (tempdimname1, tempdimsize1, 0);
5480 (*i)->dims.push_back (dim);
5481 auto cdim =
new Dimension (tempdimname1, tempdimsize1, 0);
5482 (*i)->correcteddims.push_back (cdim);
5483 file->sd->nonmisscvdimnamelist.insert (tempdimname1);
5489 i = file->sd->sdfields.erase (i);
5493 else if (tempfieldname.find (
"Longitude") != std::string::npos) {
5494 for (std::vector < Dimension * >::const_iterator j =
5495 (*i)->getDimensions ().begin ();
5496 j != (*i)->getDimensions ().end (); ++j) {
5497 if (((*j)->getName ()).find (
"regional long") !=
5498 std::string::npos) {
5499 tempsetit = tempdimnameset.insert ((*j)->getName ());
5500 if (tempsetit.second ==
true) {
5501 tempdimname2 = (*j)->getName ();
5502 tempdimsize2 = (*j)->getSize ();
5503 (*i)->fieldtype = 2;
5512 for (std::vector < Dimension * >::const_iterator j =
5513 (*i)->getDimensions ().begin ();
5514 j != (*i)->getDimensions ().end (); ++j) {
5517 for (std::vector < Dimension * >::const_iterator j =
5518 (*i)->getCorrectedDimensions ().begin ();
5519 j != (*i)->getCorrectedDimensions ().end (); ++j) {
5522 (*i)->dims.clear ();
5523 (*i)->correcteddims.clear ();
5525 auto dim =
new Dimension (tempdimname2, tempdimsize2, 0);
5526 (*i)->dims.push_back (dim);
5527 auto cdim =
new Dimension (tempdimname2, tempdimsize2, 0);
5528 (*i)->correcteddims.push_back (cdim);
5530 file->sd->nonmisscvdimnamelist.insert (tempdimname2);
5536 i = file->sd->sdfields.erase (i);
5556 std::string tempdimname1 =
"1.0 deg. regional colat. zones";
5557 std::string tempdimname2 =
"1.0 deg. regional long. zones";
5558 std::string tempdimname3 =
"1.0 deg. zonal colat. zones";
5559 std::string tempdimname4 =
"1.0 deg. zonal long. zones";
5560 int tempdimsize1 = 180;
5561 int tempdimsize2 = 360;
5562 int tempdimsize3 = 180;
5563 int tempdimsize4 = 1;
5565 std::string tempnewdimname1;
5566 std::string tempnewdimname2;
5567 std::string tempcvarname1;
5568 std::string tempcvarname2;
5573 auto latitude =
new SDField ();
5575 latitude->name =
"latitude";
5577 latitude->type = DFNT_FLOAT32;
5578 latitude->fieldtype = 1;
5581 latitude->newname = latitude->name;
5583 auto dim =
new Dimension (tempdimname1, tempdimsize1, 0);
5584 latitude->dims.push_back (dim);
5586 auto dim2 =
new Dimension (tempdimname2, tempdimsize2, 0);
5587 latitude->dims.push_back (dim2);
5589 auto cdim =
new Dimension (tempdimname1, tempdimsize1, 0);
5590 latitude->correcteddims.push_back (cdim);
5592 auto cdim2 =
new Dimension (tempdimname2, tempdimsize2, 0);
5593 latitude->correcteddims.push_back (cdim2);
5594 file->sd->sdfields.push_back (latitude);
5596 auto longitude =
new SDField ();
5598 longitude->name =
"longitude";
5599 longitude->rank = 2;
5600 longitude->type = DFNT_FLOAT32;
5601 longitude->fieldtype = 2;
5604 longitude->newname = longitude->name;
5606 auto lon_dim =
new Dimension (tempdimname1, tempdimsize1, 0);
5607 longitude->dims.push_back (lon_dim);
5609 auto lon_dim2 =
new Dimension (tempdimname2, tempdimsize2, 0);
5610 longitude->dims.push_back (lon_dim2);
5612 auto lon_cdim =
new Dimension (tempdimname1, tempdimsize1, 0);
5613 longitude->correcteddims.push_back (lon_cdim);
5615 auto lon_cdim2 =
new Dimension (tempdimname2, tempdimsize2, 0);
5616 longitude->correcteddims.push_back (lon_cdim2);
5617 file->sd->sdfields.push_back (longitude);
5621 if (file->sptype == CER_SRB) {
5623 auto latitudez =
new SDField ();
5625 latitudez->name =
"latitudez";
5626 latitudez->rank = 1;
5627 latitudez->type = DFNT_FLOAT32;
5628 latitudez->fieldtype = 1;
5629 latitudez->newname = latitudez->name;
5631 auto latz_dim =
new Dimension (tempdimname3, tempdimsize3, 0);
5632 latitudez->dims.push_back (latz_dim);
5634 auto latz_cdim =
new Dimension (tempdimname3, tempdimsize3, 0);
5635 latitudez->correcteddims.push_back (latz_cdim);
5636 file->sd->sdfields.push_back (latitudez);
5638 auto longitudez =
new SDField ();
5639 longitudez->name =
"longitudez";
5640 longitudez->rank = 1;
5641 longitudez->type = DFNT_FLOAT32;
5642 longitudez->fieldtype = 2;
5643 longitudez->newname = longitudez->name;
5645 auto lonz_dim =
new Dimension (tempdimname4, tempdimsize4, 0);
5646 longitudez->dims.push_back (lonz_dim);
5648 auto lonz_cdim =
new Dimension (tempdimname4, tempdimsize4, 0);
5649 longitudez->correcteddims.push_back (lonz_cdim);
5650 file->sd->sdfields.push_back (longitudez);
5653 if (file->sptype == CER_SRB) {
5654 file->sd->nonmisscvdimnamelist.insert (tempdimname3);
5655 file->sd->nonmisscvdimnamelist.insert (tempdimname4);
5658 file->sd->nonmisscvdimnamelist.insert (tempdimname1);
5659 file->sd->nonmisscvdimnamelist.insert (tempdimname2);
5661 if (file->sptype == CER_CDAY) {
5663 string odddimname1=
"1.0 deg. regional Colat. zones";
5664 string odddimname2 =
"1.0 deg. regional Long. zones";
5667 for (
const auto &sdf:file->sd->sdfields) {
5668 for (
const auto &sdim:sdf->getDimensions()) {
5669 if (odddimname1 == sdim->name)
5670 sdim->name = tempdimname1;
5671 if (odddimname2 == sdim->name)
5672 sdim->name = tempdimname2;
5674 for (
const auto &sdim:sdf->getCorrectedDimensions()) {
5675 if (odddimname1 == sdim->name)
5676 sdim->name = tempdimname1;
5677 if (odddimname2 == sdim->name)
5678 sdim->name = tempdimname2;
5690 std::string tempdimname3 =
"1.0 deg. zonal colat. zones";
5691 std::string tempdimname4 =
"1.0 deg. zonal long. zones";
5692 int tempdimsize3 = 180;
5693 int tempdimsize4 = 1;
5696 auto latitudez =
new SDField ();
5698 latitudez->name =
"latitudez";
5699 latitudez->rank = 1;
5700 latitudez->type = DFNT_FLOAT32;
5701 latitudez->fieldtype = 1;
5702 latitudez->newname = latitudez->name;
5705 auto latz_dim =
new Dimension (tempdimname3, tempdimsize3, 0);
5706 latitudez->dims.push_back (latz_dim);
5708 auto latz_cdim =
new Dimension (tempdimname3, tempdimsize3, 0);
5709 latitudez->correcteddims.push_back (latz_cdim);
5711 file->sd->sdfields.push_back (latitudez);
5713 auto longitudez =
new SDField ();
5714 longitudez->name =
"longitudez";
5715 longitudez->rank = 1;
5716 longitudez->type = DFNT_FLOAT32;
5717 longitudez->fieldtype = 2;
5718 longitudez->newname = longitudez->name;
5720 auto lonz_dim =
new Dimension (tempdimname4, tempdimsize4, 0);
5721 longitudez->dims.push_back (lonz_dim);
5723 auto lonz_cdim =
new Dimension (tempdimname4, tempdimsize4, 0);
5724 longitudez->correcteddims.push_back (lonz_cdim);
5726 file->sd->sdfields.push_back (longitudez);
5727 file->sd->nonmisscvdimnamelist.insert (tempdimname3);
5728 file->sd->nonmisscvdimnamelist.insert (tempdimname4);
5740 std::set < std::string > tempfulldimnamelist;
5741 std::pair < std::set < std::string >::iterator,
bool > ret;
5743 std::map < int, std::string > tempsizedimnamelist;
5747 for (
const auto &sdf:file->sd->sdfields) {
5749 if (sdf->getName () ==
"Latitude")
5751 if (sdf->getName () ==
"Longitude") {
5757 for (
const auto &dim:sdf->getCorrectedDimensions()) {
5758 tempsizedimnamelist[dim->getSize ()] = dim->getName ();
5759 file->sd->nonmisscvdimnamelist.insert (dim->getName ());
5764 for (
const auto &sdf:file->sd->sdfields) {
5765 for (
const auto &dim:sdf->getCorrectedDimensions()) {
5769 if (sdf->fieldtype == 0) {
5770 if ((tempsizedimnamelist.find (dim->getSize ())) !=
5771 tempsizedimnamelist.end ())
5772 dim->name = tempsizedimnamelist[dim->getSize ()];
5786 std::set < std::string > tempfulldimnamelist;
5787 std::pair < std::set < std::string >::iterator,
bool > ret;
5797 bool merra_is_eos2 =
false;
5798 size_t found_forward_slash = file->path.find_last_of(
"/");
5799 if ((found_forward_slash != string::npos) &&
5800 (((file->path).substr(found_forward_slash+1).compare(0,5,
"MERRA"))==0)){
5804 if ((attr->getName().compare(0, 14,
"StructMetadata" )== 0) ||
5805 (attr->getName().compare(0, 14,
"structmetadata" )== 0)) {
5806 merra_is_eos2 =
true;
5812 if (
true == merra_is_eos2) {
5813 vector <string> noneos_newnamelist;
5816 for (
const auto &sdf:file->sd->sdfields) {
5817 sdf->special_product_fullpath = sdf->newname;
5819 string EOSGRIDstring=
":EOSGRID";
5820 size_t found = (sdf->name).rfind(EOSGRIDstring);
5822 if (found !=string::npos && ((sdf->name).size() == (found + EOSGRIDstring.size()))) {
5824 sdf->newname = sdf->name.substr(0,found);
5825 noneos_newnamelist.push_back(sdf->newname);
5828 sdf->newname = sdf->name;
5835 for (
const auto &sdf:file->sd->sdfields) {
5836 for(
const auto &noneos_name:noneos_newnamelist) {
5837 if (sdf->newname == noneos_name && sdf->name == noneos_name) {
5839 sdf->newname = sdf->newname +
"_EOS";
5846 map<string,string> dimname_to_newdimname;
5847 for (
const auto &sdf:file->sd->sdfields) {
5848 for (
const auto &dim:sdf->getCorrectedDimensions()) {
5850 if (dim->getType () != 0) {
5851 if (sdf->name == dim->getName () && sdf->getRank () == 1){
5853 sdf->is_dim_scale =
true;
5854 dim->name = sdf->newname;
5859 file->sd->nonmisscvdimnamelist.insert (dim->name);
5866 for (
const auto &sdf:file->sd->sdfields) {
5867 if (0 == sdf->fieldtype) {
5868 for (
const auto &dim:sdf->getCorrectedDimensions()) {
5869 itmap = dimname_to_newdimname.find(dim->name);
5870 if (itmap == dimname_to_newdimname.end())
5871 throw2(
"Cannot find the corresponding new dim. name for dim. name ",dim->name);
5873 dim->name = (*itmap).second;
5882 for (std::vector < SDField * >::const_iterator i =
5883 file->sd->sdfields.begin (); i != file->sd->sdfields.end () && (
false == this->OTHERHDF_Has_Dim_NoScale_Field); ++i) {
5884 for (std::vector < Dimension * >::const_iterator j =
5885 (*i)->getCorrectedDimensions ().begin ();
5886 j != (*i)->getCorrectedDimensions ().end () && (
false == this->OTHERHDF_Has_Dim_NoScale_Field); ++j) {
5888 if ((*j)->getType () != 0) {
5889 if ((*i)->name == (*j)->getName () && (*i)->getRank () == 1)
5890 (*i)->fieldtype = 3;
5891 file->sd->nonmisscvdimnamelist.insert ((*j)->getName ());
5894 this->OTHERHDF_Has_Dim_NoScale_Field =
true;
5902 if (
true == this->OTHERHDF_Has_Dim_NoScale_Field)
5903 file->sd->nonmisscvdimnamelist.clear();
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.
int32 getRank() const
Get the dimension rank 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.
void PrepareTRMML3M_V7()
Special method to prepare TRMM multiple grid Level 3 geolocation fields(latitude,longitude,...
void PrepareTRMML3S_V7()
Special method to prepare TRMM single grid Level 3 geolocation fields(latitude,longitude,...
void ReadHybridNonLoneVdatas(const File *)
void handle_vdata() const
Handle Vdata.
void CheckSDType()
This method will check if the HDF4 file is one of TRMM or OBPG products we supported.
void ReadVgattrs(int32 vgroup_id, const char *fullpath)
Obtain vgroup attributes.
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.
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 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 handle_sds_missing_fields() const
Add the missing coordinate variables based on the corrected dimension name list.
void ReadLoneVdatas(File *) const
Handle non-attribute lone vdatas.
void PrepareOTHERHDF()
We still provide a hook for other HDF data product although no CF compliant is followed.
void handle_sds_coords(bool COARDFLAG, const std::string &lldimname1, const std::string &lldimname2)
Create "coordinates", "units" CF attributes.
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 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.
const std::vector< Dimension * > & getCorrectedDimensions() const
Get the list of the corrected dimensions.
This class retrieves all SDS objects and SD file attributes.
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain the SD(file) attributes.
static SD * Read_Hybrid(int32 sdfileid, int32 hfileid)
Read the information of all hybrid SDS objects from the HDF4 file.
const std::vector< SDField * > & getFields() const
Public interface to obtain information of all SDS vectors(objects).
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...
This class retrieves all information of one Vdata.
bool getTreatAsAttrFlag() const
const std::vector< VDField * > & getFields() const
Obtain Vdata fields.
void ReadAttributes(int32 vdata_id)
Retrieve all attributes of this Vdata.
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 "_".