39#include "h5apicompatible.h"
45using namespace HDF5CF;
48GMCVar::GMCVar(
Var*var) {
50 BESDEBUG(
"h5",
"Coming to GMCVar()"<<endl);
51 newname = var->newname;
53 fullpath = var->fullpath;
55 total_elems = var->total_elems;
56 zero_storage_size = var->zero_storage_size;
58 unsupported_attr_dtype = var->unsupported_attr_dtype;
59 unsupported_dspace = var->unsupported_dspace;
60 coord_attr_add_path =
false;
62 for (
auto ira = var->attrs.begin();
63 ira!=var->attrs.end(); ++ira) {
65 attr->name = (*ira)->name;
66 attr->newname = (*ira)->newname;
67 attr->dtype =(*ira)->dtype;
68 attr->count =(*ira)->count;
69 attr->strsize = (*ira)->strsize;
70 attr->fstrsize = (*ira)->fstrsize;
71 attr->value =(*ira)->value;
72 attrs.push_back(attr);
75 for (
auto ird = var->dims.begin();
76 ird!=var->dims.end(); ++ird) {
78 dim->name = (*ird)->name;
79 dim->newname = (*ird)->newname;
80 dim->unlimited_dim = (*ird)->unlimited_dim;
84 product_type = General_Product;
88GMCVar::GMCVar(
GMCVar*cvar) {
90 newname = cvar->newname;
92 fullpath = cvar->fullpath;
95 unsupported_attr_dtype = cvar->unsupported_attr_dtype;
96 unsupported_dspace = cvar->unsupported_dspace;
98 for (vector<Attribute*>::iterator ira = cvar->attrs.begin();
99 ira!=cvar->attrs.end(); ++ira) {
101 attr->name = (*ira)->name;
102 attr->newname = (*ira)->newname;
103 attr->dtype =(*ira)->dtype;
104 attr->count =(*ira)->count;
105 attr->strsize = (*ira)->strsize;
106 attr->fstrsize = (*ira)->fstrsize;
107 attr->value =(*ira)->value;
108 attrs.push_back(attr);
111 for (vector<Dimension*>::iterator ird = cvar->dims.begin();
112 ird!=cvar->dims.end(); ++ird) {
116 dim->name = (*ird)->name;
117 dim->newname = (*ird)->newname;
121 GMcvar->cfdimname = latdim0;
122 GMcvar->cvartype = CV_EXIST;
123 GMcvar->product_type = product_type;
130GMSPVar::GMSPVar(
Var*var) {
132 BESDEBUG(
"h5",
"Coming to GMSPVar()"<<endl);
133 fullpath = var->fullpath;
135 total_elems = var->total_elems;
136 zero_storage_size = var->zero_storage_size;
137 unsupported_attr_dtype = var->unsupported_attr_dtype;
138 unsupported_dspace = var->unsupported_dspace;
139 coord_attr_add_path = var->coord_attr_add_path;
146 for (
auto ira = var->attrs.begin();
147 ira!=var->attrs.end(); ++ira) {
149 attr->name = (*ira)->name;
150 attr->newname = (*ira)->newname;
151 attr->dtype =(*ira)->dtype;
152 attr->count =(*ira)->count;
153 attr->strsize = (*ira)->strsize;
154 attr->fstrsize = (*ira)->fstrsize;
155 attr->value =(*ira)->value;
156 attrs.push_back(attr);
159 for (
auto ird = var->dims.begin();
160 ird!=var->dims.end(); ++ird) {
162 dim->name = (*ird)->name;
163 dim->newname = (*ird)->newname;
164 dim->unlimited_dim = (*ird)->unlimited_dim;
170GMFile::GMFile(
const char*file_fullpath, hid_t file_id, H5GCFProduct product_type, GMPattern gproduct_pattern):
171File(file_fullpath,file_id), product_type(product_type),gproduct_pattern(gproduct_pattern)
180 if (!this->cvars.empty()){
181 for (
auto i= this->cvars.begin(); i!=this->cvars.end(); ++i) {
186 if (!this->spvars.empty()){
187 for (
auto i= this->spvars.begin(); i!=this->spvars.end(); ++i) {
195string GMFile::get_CF_string(
string s) {
202 return File::get_CF_string(s);
203 else if (General_Product == product_type && OTHERGMS == gproduct_pattern) {
205 if(
true == HDF5RequestHandler::get_keep_var_leading_underscore())
206 return File::get_CF_string(s);
209 return File::get_CF_string(s);
215 return File::get_CF_string(s);
221 hid_t file_id,
bool include_attr) {
223 BESDEBUG(
"h5",
"Coming to Retrieve_H5_Info()"<<endl);
226 if (product_type == Mea_SeaWiFS_L2 || product_type == Mea_SeaWiFS_L3
227 || GPMS_L3 == product_type || GPMM_L3 == product_type || GPM_L1 == product_type || OBPG_L3 == product_type
228 || Mea_Ozone == product_type || General_Product == product_type)
241 BESDEBUG(
"h5",
"Coming to Update_Product_Type()"<<endl);
242 if(GPMS_L3 == this->product_type || GPMM_L3 == this->product_type) {
248 Check_Dimscale_General_Product_Pattern();
249 if(GENERAL_DIMSCALE == this->gproduct_pattern){
250 if(GPMS_L3 == this->product_type) {
251 for (
auto irv = this->
vars.begin();
252 irv != this->vars.end(); ++irv)
253 (*irv)->newname = (*irv)->name;
255 this->product_type = General_Product;
258 else if(General_Product == this->product_type)
259 Check_General_Product_Pattern();
264 BESDEBUG(
"h5",
"Coming to Remove_Unneeded_Objects()"<<endl);
265 if(General_Product == this->product_type) {
266 string file_path = this->path;
267 if(HDF5CFUtil::obtain_string_after_lastslash(file_path).find(
"OMPS-NPP")==0)
268 Remove_OMPSNPP_InputPointers();
270 if((General_Product == this->product_type) && (GENERAL_DIMSCALE == this->gproduct_pattern)) {
271 set<string> nc4_non_coord_set;
272 string nc4_non_coord=
"_nc4_non_coord_";
273 size_t nc4_non_coord_size= nc4_non_coord.size();
274 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
275 if((*irv)->name.find(nc4_non_coord)==0)
276 nc4_non_coord_set.insert((*irv)->name.substr(nc4_non_coord_size,(*irv)->name.size()-nc4_non_coord_size));
280 for (
auto irv = this->
vars.begin(); irv != this->vars.end();) {
281 if(nc4_non_coord_set.find((*irv)->name)!=nc4_non_coord_set.end()){
283 irv=this->
vars.erase(irv);
289 if(nc4_non_coord_set.empty()==
false)
290 this->have_nc4_non_coord =
true;
292 else if(GPM_L3_New == this->product_type) {
293 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ) {
294 if((*irg)->attrs.empty()) {
296 irg = this->
groups.erase(irg);
305void GMFile::Remove_OMPSNPP_InputPointers() {
309 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ) {
310 if((*irg)->path.find(
"/InputPointers")==0) {
312 irg = this->
groups.erase(irg);
319 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
320 if((*irv)->fullpath.find(
"/InputPointers")==0) {
322 irv = this->
vars.erase(irv);
331 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
333 if ((*ircv)->cvartype != CV_NONLATLON_MISS){
334 for (
auto ira = (*ircv)->attrs.begin();
335 ira != (*ircv)->attrs.end(); ++ira) {
336 Retrieve_H5_Attr_Value(*ira,(*ircv)->fullpath);
345 BESDEBUG(
"h5",
"Coming to Retrieve_H5_Supported_Attr_Values()"<<endl);
351 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
352 if ((*ircv)->cvartype != CV_NONLATLON_MISS){
353 for (
auto ira = (*ircv)->attrs.begin();
354 ira != (*ircv)->attrs.end(); ++ira) {
355 Retrieve_H5_Attr_Value(*ira,(*ircv)->fullpath);
361 for (
auto irspv = this->spvars.begin(); irspv != this->spvars.end(); ++irspv) {
362 for (
auto ira = (*irspv)->attrs.begin();
363 ira != (*irspv)->attrs.end(); ++ira) {
364 Retrieve_H5_Attr_Value(*ira,(*irspv)->fullpath);
375 BESDEBUG(
"h5",
"Coming to Adjust_H5_Attr_Value()"<<endl);
376 if (product_type == ACOS_L2S_OR_OCO2_L1B) {
377 if ((
"Type" == attr->name) && (H5VSTRING == attr->dtype)) {
378 string orig_attrvalues(attr->value.begin(),attr->value.end());
379 if (orig_attrvalues !=
"Signed64")
return;
380 string new_attrvalues =
"Signed32";
384 attr->value.resize(new_attrvalues.size());
385 copy(new_attrvalues.begin(),new_attrvalues.end(),attr->value.begin());
393 BESDEBUG(
"h5",
"Coming to Handle_Unsupported_Dtype()"<<endl);
394 if(
true == check_ignored) {
395 Gen_Unsupported_Dtype_Info(include_attr);
398 Handle_GM_Unsupported_Dtype(include_attr);
402void GMFile:: Handle_GM_Unsupported_Dtype(
bool include_attr) {
404 BESDEBUG(
"h5",
"Coming to Handle_GM_Unsupported_Dtype()"<<endl);
405 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ) {
406 if (
true == include_attr) {
407 for (
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end(); ) {
408 H5DataType temp_dtype = (*ira)->getType();
409 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
411 ira = (*ircv)->attrs.erase(ira);
418 H5DataType temp_dtype = (*ircv)->getType();
419 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
427 ircv = this->cvars.erase(ircv);
435 for (
auto ircv = this->spvars.begin(); ircv != this->spvars.end(); ) {
436 if (
true == include_attr) {
437 for (
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end(); ) {
438 H5DataType temp_dtype = (*ira)->getType();
439 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
441 ira = (*ircv)->attrs.erase(ira);
448 H5DataType temp_dtype = (*ircv)->getType();
449 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4)) {
451 ircv = this->spvars.erase(ircv);
461void GMFile:: Gen_Unsupported_Dtype_Info(
bool include_attr) {
463 BESDEBUG(
"h5",
"GMFile::Coming to Gen_Unsupported_Dtype_Info()"<<endl);
464 if(
true == include_attr) {
466 File::Gen_Group_Unsupported_Dtype_Info();
467 File::Gen_Var_Unsupported_Dtype_Info();
468 Gen_VarAttr_Unsupported_Dtype_Info();
474void GMFile:: Gen_VarAttr_Unsupported_Dtype_Info() {
476 BESDEBUG(
"h5",
"GMFile::Coming to Gen_Unsupported_Dtype_Info()"<<endl);
478 if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
479 || (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type) || (Mea_SeaWiFS_L3 == this->product_type)
480 || (OBPG_L3 == this->product_type)) {
481 Gen_DimScale_VarAttr_Unsupported_Dtype_Info();
485 File::Gen_VarAttr_Unsupported_Dtype_Info();
488 Gen_GM_VarAttr_Unsupported_Dtype_Info();
493void GMFile:: Gen_GM_VarAttr_Unsupported_Dtype_Info(){
495 BESDEBUG(
"h5",
"GMFile::Coming to Gen_GM_VarAttr_Unsupported_Dtype_Info()"<<endl);
496 if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
497 || (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type) || (Mea_SeaWiFS_L3 == this->product_type)
498 || (OBPG_L3 == this->product_type)) {
500 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
503 bool is_ignored = ignored_dimscale_ref_list((*irv));
504 if (
false == (*irv)->attrs.empty()) {
505 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
506 H5DataType temp_dtype = (*ira)->getType();
508 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
512 if ((
"DIMENSION_LIST" !=(*ira)->name) &&
513 (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
514 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
520 for (
auto irv = this->spvars.begin(); irv != this->spvars.end(); ++irv) {
523 bool is_ignored = ignored_dimscale_ref_list((*irv));
524 if (
false == (*irv)->attrs.empty()) {
528 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
529 H5DataType temp_dtype = (*ira)->getType();
531 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
535 if ((
"DIMENSION_LIST" !=(*ira)->name) &&
536 (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
537 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
544 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
545 if (
false == (*irv)->attrs.empty()) {
549 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
550 H5DataType temp_dtype = (*ira)->getType();
552 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64)
553 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
558 for (
auto irv = this->spvars.begin(); irv != this->spvars.end(); ++irv) {
559 if (
false == (*irv)->attrs.empty()) {
563 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
564 H5DataType temp_dtype = (*ira)->getType();
566 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype,_is_dap4) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
567 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
580 BESDEBUG(
"h5",
"Coming to GMFile:Handle_Unsupported_Dspace()"<<endl);
581 if(
true == check_ignored)
582 Gen_Unsupported_Dspace_Info();
585 Handle_GM_Unsupported_Dspace(include_attr);
590void GMFile:: Handle_GM_Unsupported_Dspace(
bool include_attr) {
592 BESDEBUG(
"h5",
"Coming to GMFile:Handle_GM_Unsupported_Dspace()"<<endl);
593 if(
true == this->unsupported_var_dspace) {
594 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ) {
595 if (
true == (*ircv)->unsupported_dspace ) {
603 ircv = this->cvars.erase(ircv);
610 for (
auto ircv = this->spvars.begin(); ircv != this->spvars.end(); ) {
611 if (
true == (*ircv)->unsupported_dspace) {
613 ircv = this->spvars.erase(ircv);
622 if(
true == include_attr) {
623 if(
true == this->unsupported_var_attr_dspace) {
624 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
625 if (
false == (*ircv)->attrs.empty()) {
626 if (
true == (*ircv)->unsupported_attr_dspace) {
627 for (
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end(); ) {
628 if (0 == (*ira)->count) {
630 ira = (*ircv)->attrs.erase(ira);
640 for (
auto ircv = this->spvars.begin(); ircv != this->spvars.end(); ++ircv) {
641 if (
false == (*ircv)->attrs.empty()) {
642 if (
true == (*ircv)->unsupported_attr_dspace) {
643 for (
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end(); ) {
644 if (0 == (*ira)->count) {
646 ira = (*ircv)->attrs.erase(ira);
661void GMFile:: Gen_Unsupported_Dspace_Info() {
663 File::Gen_Unsupported_Dspace_Info();
670 BESDEBUG(
"h5",
"Coming to GMFile:Handle_Unsupported_Others()"<<endl);
675 if(General_Product != this->product_type
676 || (General_Product == this->product_type && OTHERGMS != this->gproduct_pattern)){
679 if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
680 || (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type)
681 || (Mea_SeaWiFS_L3 == this->product_type)
682 || (OBPG_L3 == this->product_type))
684 remove_netCDF_internal_attributes(include_attr);
685 if(include_attr ==
true) {
687 for (
auto ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
689 if((*ira)->name ==
"_nc3_strict") {
694 else if((*ira)->name ==
"_NCProperties") {
698 else if((*ira)->name ==
"_Netcdf4Coordinates") {
707 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
708 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();) {
709 if((*ira)->name ==
"CLASS") {
710 string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
714 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
716 ira = (*irv)->attrs.erase(ira);
723 else if((*ira)->name ==
"NAME") {
725 ira =(*irv)->attrs.erase(ira);
729 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
730 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
732 ira =(*irv)->attrs.erase(ira);
735 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
736 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
738 ira =(*irv)->attrs.erase(ira);
746 else if((*ira)->name ==
"_Netcdf4Dimid") {
748 ira =(*irv)->attrs.erase(ira);
750 else if((*ira)->name ==
"_Netcdf4Coordinates") {
752 ira =(*irv)->attrs.erase(ira);
756 else if((*ira)->name ==
"_nc3_strict") {
758 ira =(*irv)->attrs.erase(ira);
771 if(
true == this->check_ignored &&
true == include_attr) {
772 if(
true == HDF5RequestHandler::get_drop_long_string()){
773 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
774 irv != this->cvars.end(); ++irv) {
775 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
776 ira != (*irv)->attrs.end();++ira) {
777 if(
true == Check_DropLongStr((*irv),(*ira))) {
778 this->add_ignored_droplongstr_hdr();
779 this->add_ignored_var_longstr_info((*irv),(*ira));
784 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
785 irv != this->spvars.end(); ++irv) {
786 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
787 ira != (*irv)->attrs.end();++ira) {
788 if(
true == Check_DropLongStr((*irv),(*ira))) {
789 this->add_ignored_droplongstr_hdr();
790 this->add_ignored_var_longstr_info((*irv),(*ira));
799 if(
false == this->have_ignored)
800 this->add_no_ignored_info();
807 BESDEBUG(
"h5",
"Coming to GMFile:Add_Dim_Name()"<<endl);
808 switch(product_type) {
811 Add_Dim_Name_Mea_SeaWiFS();
814 Add_Dim_Name_Aqu_L3();
817 Add_Dim_Name_OSMAPL2S();
819 case ACOS_L2S_OR_OCO2_L1B:
820 Add_Dim_Name_ACOS_L2S_OCO2_L1B();
823 Add_Dim_Name_Mea_Ozonel3z();
832 Add_Dim_Name_OBPG_L3();
834 case General_Product:
835 Add_Dim_Name_General_Product();
838 throw1(
"Cannot generate dim. names for unsupported datatype");
843for (vector<Var*>::iterator irv2 = this->
vars.begin();
844 irv2 != this->vars.end(); irv2++) {
845 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
846 ird !=(*irv2)->dims.end(); ird++) {
847 cerr<<
"Dimension name afet Add_Dim_Name "<<(*ird)->newname <<endl;
855void GMFile::Add_Dim_Name_OBPG_L3() {
857 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_OBPG_L3()"<<endl);
860 Check_General_Product_Pattern();
861 Add_Dim_Name_General_Product();
865void GMFile::Add_Dim_Name_Mea_SeaWiFS() {
867 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Mea_SeaWiFS()"<<endl);
868 pair<set<string>::iterator,
bool> setret;
869 if (Mea_SeaWiFS_L3 == product_type)
871 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
872 Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
873 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
874 setret = dimnamelist.insert((*ird)->name);
875 if (
true == setret.second)
876 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
880 if (
true == dimnamelist.empty())
881 throw1(
"This product should have the dimension names, but no dimension names are found");
885void GMFile::Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(
Var* var)
888 BESDEBUG(
"h5",
"Coming to Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
890 bool has_dimlist =
false;
891 bool has_class =
false;
892 bool has_reflist =
false;
894 for(
auto ira = var->attrs.begin(); ira != var->attrs.end();ira++) {
895 if (
"DIMENSION_LIST" == (*ira)->name) {
899 if (
"CLASS" == (*ira)->name)
901 if (
"REFERENCE_LIST" == (*ira)->name)
904 if (
true == has_dimlist)
906 if (
true == has_class &&
true == has_reflist)
910 if (
true == has_dimlist)
911 Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(var,dimlistattr);
914 else if(
true == has_class &&
true == has_reflist) {
915 if (var->dims.size() !=1)
916 throw2(
"dimension scale dataset must be 1 dimension, this is not true for variable ",
921 (var->dims)[0]->name = var->fullpath;
922 (var->dims)[0]->newname = var->fullpath;
923 pair<set<string>::iterator,
bool> setret;
924 setret = dimnamelist.insert((var->dims)[0]->name);
925 if (
true == setret.second)
926 Insert_One_NameSizeMap_Element((var->dims)[0]->name,(var->dims)[0]->size,(var->dims)[0]->unlimited_dim);
934 set<hsize_t> fakedimsize;
935 pair<set<hsize_t>::iterator,
bool> setsizeret;
936 for (
auto ird= var->dims.begin(); ird != var->dims.end(); ++ird) {
937 Add_One_FakeDim_Name(*ird);
938 setsizeret = fakedimsize.insert((*ird)->size);
939 if (
false == setsizeret.second)
940 Adjust_Duplicate_FakeDim_Name(*ird);
944 for (
int i = 0; i < var->dims.size(); ++i) {
945 Add_One_FakeDim_Name((var->dims)[i]);
946 bool gotoMainLoop =
false;
947 for (
int j =i-1; j>=0 && !gotoMainLoop; --j) {
948 if (((var->dims)[i])->size == ((var->dims)[j])->size){
949 Adjust_Duplicate_FakeDim_Name((var->dims)[i]);
960void GMFile::Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(
Var *var,
const Attribute*dimlistattr)
963 BESDEBUG(
"h5",
"Coming to Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
964 ssize_t objnamelen = -1;
972 hid_t amemtype_id = -1;
973 hid_t aspace_id = -1;
977 if(
nullptr == dimlistattr)
978 throw2(
"Cannot obtain the dimension list attribute for variable ",var->name);
981 throw2(
"The number of dimension should NOT be 0 for the variable ",var->name);
985 vlbuf.resize(var->rank);
987 dset_id = H5Dopen(this->fileid,(var->fullpath).c_str(),H5P_DEFAULT);
989 throw2(
"Cannot open the dataset ",var->fullpath);
991 attr_id = H5Aopen(dset_id,(dimlistattr->name).c_str(),H5P_DEFAULT);
993 throw4(
"Cannot open the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
995 atype_id = H5Aget_type(attr_id);
997 throw4(
"Cannot obtain the datatype of the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
999 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
1001 if (amemtype_id < 0)
1002 throw2(
"Cannot obtain the memory datatype for the attribute ",dimlistattr->name);
1005 if (H5Aread(attr_id,amemtype_id,vlbuf.data()) <0)
1006 throw2(
"Cannot obtain the referenced object for the variable ",var->name);
1009 vector<char> objname;
1010 int vlbuf_index = 0;
1013 for (
auto ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
1015 if(vlbuf[vlbuf_index].p==
nullptr)
1016 throw4(
"The dimension doesn't exist. Var name is ",var->name,
"; the dimension index is ",vlbuf_index);
1018 rbuf =((hobj_ref_t*)vlbuf[vlbuf_index].p)[0];
1019 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0)
1020 throw2(
"Cannot dereference from the DIMENSION_LIST attribute for the variable ",var->name);
1026 rbuf =((hobj_ref_t*)vl_ref[0].p)[0];
1028 dset1 = H5Rdereference2(attr_id,H5P_DEFAULT,H5R_OBJECT,&ds_ref_buf);
1031 H5R_ref_t new_rbuf =((H5R_ref_t*)vlbuf[vlbuf_index].p)[0];
1032 if ((ref_dset = H5Ropen_object((H5R_ref_t *)&new_rbuf, H5P_DEFAULT, H5P_DEFAULT))<0)
1033 throw2(
"Cannot dereference from the DIMENSION_LIST attribute for the variable ",var->name);
1034 H5Rdestroy(&new_rbuf);
1037 if ((objnamelen= H5Iget_name(ref_dset,
nullptr,0))<=0)
1038 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
1039 objname.resize(objnamelen+1);
1040 if ((objnamelen= H5Iget_name(ref_dset,objname.data(),objnamelen+1))<=0)
1041 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
1043 auto objname_str = string(objname.begin(),objname.end());
1044 string trim_objname = objname_str.substr(0,objnamelen);
1045 (*ird)->name = string(trim_objname.begin(),trim_objname.end());
1047 pair<set<string>::iterator,
bool> setret;
1048 setret = dimnamelist.insert((*ird)->name);
1049 if (
true == setret.second)
1050 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1051 (*ird)->newname = (*ird)->name;
1057 if(vlbuf.size()!= 0) {
1059 if ((aspace_id = H5Aget_space(attr_id)) < 0)
1060 throw2(
"Cannot get hdf5 dataspace id for the attribute ",dimlistattr->name);
1062 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)vlbuf.data())<0)
1063 throw2(
"Cannot successfully clean up the variable length memory for the variable ",var->name);
1065 H5Sclose(aspace_id);
1070 H5Tclose(amemtype_id);
1081 if(amemtype_id != -1)
1082 H5Tclose(amemtype_id);
1085 H5Sclose(aspace_id);
1099void GMFile::Add_Dim_Name_Mea_Ozonel3z() {
1101 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Mea_Ozonel3z()"<<endl);
1103 bool use_dimscale =
false;
1105 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++ irg) {
1106 if (
"/Dimensions" == (*irg)->path) {
1107 use_dimscale =
true;
1112 if (
false == use_dimscale) {
1114 bool has_dimlist =
false;
1115 bool has_class =
false;
1116 bool has_reflist =
false;
1118 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
1119 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
1120 if (
"DIMENSION_LIST" == (*ira)->name)
1123 if (
true == has_dimlist)
1127 if (
true == has_dimlist) {
1128 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
1130 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
1131 if (
"CLASS" == (*ira)->name)
1133 if (
"REFERENCE_LIST" == (*ira)->name)
1135 if (
true == has_class &&
true == has_reflist)
1139 if (
true == has_class &&
1140 true == has_reflist)
1144 if (
true == has_class &&
true == has_reflist)
1145 use_dimscale =
true;
1149 if (
true == use_dimscale) {
1151 pair<set<string>::iterator,
bool> setret;
1152 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1153 Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
1154 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
1155 setret = dimnamelist.insert((*ird)->name);
1156 if(
true == setret.second)
1157 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1161 if (
true == dimnamelist.empty())
1162 throw1(
"This product should have the dimension names, but no dimension names are found");
1168 multimap<hsize_t,string> ozonedimsize_to_dimname;
1169 pair<multimap<hsize_t,string>::iterator,multimap<hsize_t,string>::iterator> mm_er_ret;
1170 multimap<hsize_t,string>::iterator irmm;
1172 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1173 bool is_cv = check_cv((*irv)->name);
1174 if (
true == is_cv) {
1175 if ((*irv)->dims.size() != 1)
1176 throw3(
"The coordinate variable", (*irv)->name,
" must be one dimension for the zonal average product");
1177 ozonedimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[0]->size,(*irv)->fullpath));
1181 set<hsize_t> fakedimsize;
1182 pair<set<hsize_t>::iterator,
bool> setsizeret;
1183 pair<set<string>::iterator,
bool> setret;
1184 pair<set<string>::iterator,
bool> tempsetret;
1185 set<string> tempdimnamelist;
1186 bool fakedimflag =
false;
1188 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1190 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1193 mm_er_ret = ozonedimsize_to_dimname.equal_range((*ird)->size);
1194 for (irmm = mm_er_ret.first; irmm!=mm_er_ret.second;irmm++) {
1195 setret = tempdimnamelist.insert(irmm->second);
1196 if (
true == setret.second) {
1197 (*ird)->name = irmm->second;
1198 (*ird)->newname = (*ird)->name;
1199 setret = dimnamelist.insert((*ird)->name);
1200 if(setret.second) Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1201 fakedimflag =
false;
1206 if (
true == fakedimflag) {
1207 Add_One_FakeDim_Name(*ird);
1208 setsizeret = fakedimsize.insert((*ird)->size);
1209 if (
false == setsizeret.second)
1210 Adjust_Duplicate_FakeDim_Name(*ird);
1214 tempdimnamelist.clear();
1215 fakedimsize.clear();
1221bool GMFile::check_cv(
const string & varname)
const {
1223 BESDEBUG(
"h5",
"Coming to check_cv()"<<endl);
1224 const string lat_name =
"Latitude";
1225 const string time_name =
"Time";
1226 const string ratio_pressure_name =
"MixingRatioPressureLevels";
1227 const string profile_pressure_name =
"ProfilePressureLevels";
1228 const string wave_length_name =
"Wavelength";
1230 if (lat_name == varname)
1232 else if (time_name == varname)
1234 else if (ratio_pressure_name == varname)
1236 else if (profile_pressure_name == varname)
1238 else if (wave_length_name == varname)
1245void GMFile::Add_Dim_Name_GPM()
1248 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_GPM()"<<endl);
1250 pair<set<string>::iterator,
bool> setret;
1262 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
1264 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
1266 if(
"DimensionNames" == (*ira)->name) {
1268 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1269 string dimname_value((*ira)->value.begin(),(*ira)->value.end());
1271 vector<string> ind_elems;
1275 if(ind_elems.size() != (
size_t)((*irv)->getRank())) {
1276 throw2(
"The number of dims obtained from the <DimensionNames> attribute is not equal to the rank ",
1280 for(
unsigned int i = 0; i<ind_elems.size(); ++i) {
1282 ((*irv)->dims)[i]->name = ind_elems[i];
1286 if(((*irv)->dims)[i]->name==
""){
1287 Add_One_FakeDim_Name(((*irv)->dims)[i]);
1290 string fakedim =
"FakeDim";
1291 stringstream sdim_count;
1292 sdim_count << dim_count;
1293 fakedim = fakedim + sdim_count.str();
1295 ((*irv)->dims)[i]->name = fakedim;
1296 ((*irv)->dims)[i]->newname = fakedim;
1297 ind_elems[i] = fakedim;
1302 ((*irv)->dims)[i]->newname = ind_elems[i];
1303 setret = dimnamelist.insert(((*irv)->dims)[i]->name);
1305 if (
true == setret.second) {
1306 Insert_One_NameSizeMap_Element(((*irv)->dims)[i]->name,
1307 ((*irv)->dims)[i]->size,
1308 ((*irv)->dims)[i]->unlimited_dim);
1311 if(dimname_to_dimsize[((*irv)->dims)[i]->name] !=((*irv)->dims)[i]->size)
1312 throw5(
"Dimension ",((*irv)->dims)[i]->name,
"has two sizes",
1313 ((*irv)->dims)[i]->size,dimname_to_dimsize[((*irv)->dims)[i]->name]);
1325 if(
false == has_dim_name_attr) {
1327 throw4(
"The variable ", (*irv)->name,
" doesn't have the DimensionNames attribute.",
1328 "We currently don't support this case. Please report to the NASA data center.");
1337void GMFile::Add_Dim_Name_Aqu_L3()
1339 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Aqu_L3()"<<endl);
1340 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
1341 if (
"l3m_data" == (*irv)->name) {
1342 ((*irv)->dims)[0]->name =
"lat";
1343 ((*irv)->dims)[0]->newname =
"lat";
1344 ((*irv)->dims)[1]->name =
"lon";
1345 ((*irv)->dims)[1]->newname =
"lon";
1352 if (
"palette" == (*irv)->name) {
1354 ((*irv)->dims)[0]->name =
"paldim0";
1355 ((*irv)->dims)[0]->newname =
"paldim0";
1356 ((*irv)->dims)[1]->name =
"paldim1";
1357 ((*irv)->dims)[1]->newname =
"paldim1";
1365void GMFile::Add_Dim_Name_OSMAPL2S(){
1367 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_OSMAPL2S()"<<endl);
1368 string tempvarname =
"";
1369 string key =
"_lat";
1370 string osmapl2sdim0 =
"YDim";
1371 string osmapl2sdim1 =
"XDim";
1374 multimap<hsize_t,string> osmapl2sdimsize_to_dimname;
1375 pair<multimap<hsize_t,string>::iterator,multimap<hsize_t,string>::iterator> mm_er_ret;
1376 multimap<hsize_t,string>::iterator irmm;
1379 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1380 tempvarname = (*irv)->name;
1381 if ((tempvarname.size() > key.size())&&
1382 (key == tempvarname.substr(tempvarname.size()-key.size(),key.size()))){
1383 if ((*irv)->dims.size() !=2)
1384 throw1(
"Currently only 2D lat/lon is supported for OSMAPL2S");
1385 osmapl2sdimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[0]->size,osmapl2sdim0));
1386 osmapl2sdimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[1]->size,osmapl2sdim1));
1391 set<hsize_t> fakedimsize;
1392 pair<set<hsize_t>::iterator,
bool> setsizeret;
1393 pair<set<string>::iterator,
bool> setret;
1394 pair<set<string>::iterator,
bool> tempsetret;
1395 set<string> tempdimnamelist;
1396 bool fakedimflag =
false;
1399 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1400 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1403 mm_er_ret = osmapl2sdimsize_to_dimname.equal_range((*ird)->size);
1404 for (irmm = mm_er_ret.first; irmm!=mm_er_ret.second;irmm++) {
1405 setret = tempdimnamelist.insert(irmm->second);
1406 if (setret.second) {
1407 (*ird)->name = irmm->second;
1408 (*ird)->newname = (*ird)->name;
1409 setret = dimnamelist.insert((*ird)->name);
1410 if(setret.second) Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1411 fakedimflag =
false;
1416 if (
true == fakedimflag) {
1417 Add_One_FakeDim_Name(*ird);
1418 setsizeret = fakedimsize.insert((*ird)->size);
1419 if (!setsizeret.second)
1420 Adjust_Duplicate_FakeDim_Name(*ird);
1423 tempdimnamelist.clear();
1424 fakedimsize.clear();
1429void GMFile::Add_Dim_Name_ACOS_L2S_OCO2_L1B(){
1431 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_ACOS_L2S_OCO2_L1B()"<<endl);
1432 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1433 set<hsize_t> fakedimsize;
1434 pair<set<hsize_t>::iterator,
bool> setsizeret;
1435 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1436 Add_One_FakeDim_Name(*ird);
1437 setsizeret = fakedimsize.insert((*ird)->size);
1438 if (
false == setsizeret.second)
1439 Adjust_Duplicate_FakeDim_Name(*ird);
1445void GMFile::Add_Dim_Name_General_Product(){
1447 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_General_Product()"<<endl);
1450 if (GENERAL_DIMSCALE == this->gproduct_pattern){
1451 Add_Dim_Name_Dimscale_General_Product();
1454 else if (GENERAL_LATLON2D == this->gproduct_pattern)
1455 Add_Dim_Name_LatLon2D_General_Product();
1457 else if (GENERAL_LATLON1D == this->gproduct_pattern || GENERAL_LATLON_COOR_ATTR == this->gproduct_pattern)
1458 Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product();
1471void GMFile::Check_General_Product_Pattern() {
1473 BESDEBUG(
"h5",
"Coming to Check_General_Product_Pattern()"<<endl);
1474 if (
false == Check_Dimscale_General_Product_Pattern()) {
1476 if (
false == Check_And_Update_New_GPM_L3())
1477 if (
false == Check_LatLon2D_General_Product_Pattern())
1478 if (
false == Check_LatLon1D_General_Product_Pattern())
1479 Check_LatLon_With_Coordinate_Attr_General_Product_Pattern();
1486bool GMFile::Check_Dimscale_General_Product_Pattern() {
1488 BESDEBUG(
"h5",
"Coming to Check_Dimscale_General_Product_Pattern()"<<endl);
1489 bool ret_value =
false;
1490 bool has_dimlist =
false;
1491 bool has_dimscalelist =
false;
1494 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1495 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
1496 if (
"DIMENSION_LIST" == (*ira)->name) {
1501 if (
true == has_dimlist)
1510 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1511 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
1512 if (
"CLASS" == (*ira)->name) {
1514 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1516 class_value.resize((*ira)->value.size());
1517 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
1521 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
1522 has_dimscalelist =
true;
1527 if (
true == has_dimscalelist)
1531 if (
true == has_dimscalelist) {
1532 if (
true == has_dimlist ) {
1533 this->gproduct_pattern = GENERAL_DIMSCALE;
1541 bool is_general_dimscale =
false;
1543 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1545 bool has_class_dscale =
false;
1546 bool has_name =
false;
1547 bool has_netcdf4_id =
false;
1549 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
1551 if (
"CLASS" == (*ira)->name) {
1552 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1554 class_value.resize((*ira)->value.size());
1555 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
1559 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE"))
1560 has_class_dscale=
true;
1562 else if (
"NAME" == (*ira)->name)
1564 else if (
"_Netcdf4Dimid" == (*ira)->name)
1565 has_netcdf4_id =
true;
1566 if(
true == has_class_dscale &&
true == has_name &&
true == has_netcdf4_id)
1567 is_general_dimscale =
true;
1570 if(
true == is_general_dimscale)
1574 if (
true == is_general_dimscale) {
1575 this->gproduct_pattern = GENERAL_DIMSCALE;
1584bool GMFile::Check_And_Update_New_GPM_L3() {
1586 bool is_new_gpm_l3 =
false;
1587 unsigned num_vars = this->
vars.size();
1588 unsigned sel_steps = num_vars/5;
1589 string dim_name=
"DimensionNames";
1590 bool has_dim_name =
false;
1597 vector<Var *>::iterator it_var_end;
1600 it_var_end = this->
vars.end();
1602 it_var_end = this->
vars.begin()+5*sel_steps;
1604 for (
auto irv = this->
vars.begin(); irv != it_var_end; irv+=sel_steps) {
1605 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
1607 if(H5FSTRING == (*ira)->getType()) {
1608 if((*ira)->name == dim_name){
1609 has_dim_name =
true;
1614 if(
true == has_dim_name)
1622 if(
true == has_dim_name) {
1623 string attr_name_subset =
"GridHeader";
1624 BESDEBUG(
"h5",
"GMFile::Check_And_Update_New_GPM_L3() has attribute <DimensionNames>. "<<endl);
1625 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++ irg) {
1626 for (
auto ira = (*irg)->attrs.begin(); ira != (*irg)->attrs.end();ira++) {
1628 string attr_name = (*ira)->name;
1631 if (attr_name.find(attr_name_subset)!=string::npos) {
1632 this->product_type = GPM_L3_New;
1633 is_new_gpm_l3 =
true;
1637 if (
true == is_new_gpm_l3)
1641 return is_new_gpm_l3;
1647bool GMFile::Check_LatLon2D_General_Product_Pattern() {
1649 BESDEBUG(
"h5",
"Coming to Check_LatLon2D_General_Product_Pattern()"<<endl);
1650 bool ret_value =
false;
1652 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"latitude",
"longitude");
1653 if(
false == ret_value) {
1654 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"Latitude",
"Longitude");
1655 if(
false == ret_value) {
1656 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"lat",
"lon");
1657 if(
false == ret_value)
1658 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"cell_lat",
"cell_lon");
1663 if(
true == ret_value)
1664 this->gproduct_pattern = GENERAL_LATLON2D;
1671bool GMFile::Check_LatLon2D_General_Product_Pattern_Name_Size(
const string & latname,
const string & lonname) {
1673 BESDEBUG(
"h5",
"Coming to Check_LatLon2D_General_Product_Pattern_Name_Size()"<<endl);
1674 bool ret_value =
false;
1675 bool ll_flag =
false;
1677 vector<size_t>lat_size(2,0);
1678 vector<size_t>lon_size(2,0);
1680 const string designed_group1 =
"/";
1681 const string designed_group2 =
"/Geolocation/";
1683 bool lat_flag_g1 =
false;
1684 bool lon_flag_g1 =
false;
1685 bool lat_flag_g2 =
false;
1686 bool lon_flag_g2 =
false;
1692 lat_flag_g1 = is_var_under_group(latname,designed_group1,2,lat_size);
1693 lon_flag_g1 = is_var_under_group(lonname,designed_group1,2,lon_size);
1694 if(lat_flag_g1 ==
true && lon_flag_g1 ==
true) {
1697 lat_flag_g2 = is_var_under_group(latname,designed_group2,2,lat_size);
1698 if(lat_flag_g2 ==
false) {
1699 lon_flag_g2 = is_var_under_group(lonname,designed_group2,2,lon_size);
1700 if(lon_flag_g2 ==
false)
1704 else if(lat_flag_g1 ==
false && lon_flag_g1 ==
false) {
1705 lat_flag_g2 = is_var_under_group(latname,designed_group2,2,lat_size);
1706 if(lat_flag_g2 ==
true) {
1707 lon_flag_g2 = is_var_under_group(lonname,designed_group2,2,lon_size);
1708 if(lon_flag_g2 ==
true)
1717 if(
false == ll_flag) {
1719 const string designed_group3 =
"/GeolocationData/";
1720 if(is_var_under_group(latname,designed_group3,2,lat_size) &&
1721 is_var_under_group(lonname,designed_group3,2,lon_size))
1727 for (vector<Var *>::iterator irv = this->
vars.begin();
1728 irv != this->vars.end(); ++irv) {
1730 if((*irv)->rank == 2) {
1731 if((*irv)->name == latname) {
1734 string lat_path =HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1740 bool has_right_lat =
false;
1741 if(
"/" == lat_path ||
"/Geolocation/" == lat_path)
1742 if(
"/" == lat_path ||
"/Geolocation/" == lat_path) {
1744 lat_size[0] = (*irv)->getDimensions()[0]->size;
1745 lat_size[1] = (*irv)->getDimensions()[1]->size;
1749 else if((*irv)->name == lonname) {
1750 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1751 if(
"/" == lon_path ||
"/Geolocation/" == lon_path) {
1753 lon_size[0] = (*irv)->getDimensions()[0]->size;
1754 lon_size[1] = (*irv)->getDimensions()[1]->size;
1766 if(
true == ll_flag) {
1768 bool latlon_size_match =
true;
1769 for (
unsigned int size_index = 0; size_index <lat_size.size();size_index++) {
1770 if(lat_size[size_index] != lon_size[size_index]){
1771 latlon_size_match =
false;
1775 if (
true == latlon_size_match) {
1777 gp_latname = latname;
1778 gp_lonname = lonname;
1791bool GMFile::Check_LatLon1D_General_Product_Pattern() {
1793 BESDEBUG(
"h5",
"Coming to Check_LatLon1D_General_Product_Pattern()"<<endl);
1794 bool ret_value =
false;
1796 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"latitude",
"longitude");
1797 if(
false == ret_value) {
1798 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"Latitude",
"Longitude");
1799 if(
false == ret_value) {
1800 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"lat",
"lon");
1801 if(
false == ret_value)
1802 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"cell_lat",
"cell_lon");
1806 if(
true == ret_value)
1807 this->gproduct_pattern = GENERAL_LATLON1D;
1814bool GMFile::Check_LatLon1D_General_Product_Pattern_Name_Size(
const string & latname,
const string & lonname) {
1816 BESDEBUG(
"h5",
"Coming to Check_LatLon1D_General_Product_Pattern_Name_Size()"<<endl);
1817 bool ret_value =
false;
1819 size_t lat_size = 0;
1820 size_t lon_size = 0;
1822 for (vector<Var *>::iterator irv = this->
vars.begin();
1823 irv != this->vars.end(); ++irv) {
1825 if((*irv)->rank == 1) {
1826 if((*irv)->name == latname) {
1828 string lat_path =HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1832 if(
"/" == lat_path ||
"/Geolocation/" == lat_path) {
1834 lat_size = (*irv)->getDimensions()[0]->size;
1837 else if((*irv)->name == lonname) {
1838 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1839 if(
"/" == lon_path ||
"/Geolocation/" == lon_path) {
1841 lon_size = (*irv)->getDimensions()[0]->size;
1851 bool latlon_size_match_grid =
true;
1857 if(lat_size == lon_size) {
1860 latlon_size_match_grid =
false;
1864 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1865 if((*irv)->rank >=2) {
1866 short ll_size_flag = 0;
1867 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
1868 if(lat_size == (*ird)->size) {
1870 if(2 == ll_size_flag){
1875 if(2 == ll_size_flag) {
1876 latlon_size_match_grid =
true;
1885 if (
true == latlon_size_match_grid) {
1886 gp_latname = latname;
1887 gp_lonname = lonname;
1897bool GMFile::Check_LatLon_With_Coordinate_Attr_General_Product_Pattern() {
1899 BESDEBUG(
"h5",
"Coming to Check_LatLon_With_Coordinate_Attr_General_Product_Pattern()"<<endl);
1900 bool ret_value =
false;
1901 string co_attrname =
"coordinates";
1902 string co_attrvalue=
"";
1903 string unit_attrname =
"units";
1904 string lat_unit_attrvalue =
"degrees_north";
1905 string lon_unit_attrvalue =
"degrees_east";
1907 bool coor_has_lat_flag =
false;
1908 bool coor_has_lon_flag =
false;
1910 vector<Var*> tempvar_lat;
1911 vector<Var*> tempvar_lon;
1914 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1916 if((*irv)->rank >=2) {
1917 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
1921 if((*ira)->name == co_attrname) {
1922 Retrieve_H5_Attr_Value((*ira),(*irv)->fullpath);
1923 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
1924 vector<string> coord_values;
1926 HDF5CFUtil::Split_helper(coord_values,orig_attr_value,sep);
1928 for(
auto irs=coord_values.begin();irs!=coord_values.end();++irs) {
1929 string coord_value_suffix1;
1930 string coord_value_suffix2;
1931 string coord_value_suffix3;
1933 if((*irs).size() >=3) {
1936 coord_value_suffix1 = (*irs).substr((*irs).size()-3,3);
1939 if((*irs).size() >=8){
1940 coord_value_suffix2 = (*irs).substr((*irs).size()-8,8);
1941 if((*irs).size() >=9)
1942 coord_value_suffix3 = (*irs).substr((*irs).size()-9,9);
1947 if(coord_value_suffix1==
"lat" || coord_value_suffix2 ==
"latitude" || coord_value_suffix2 ==
"Latitude")
1948 coor_has_lat_flag =
true;
1949 else if(coord_value_suffix1==
"lon" || coord_value_suffix3 ==
"longitude" || coord_value_suffix3 ==
"Longitude")
1950 coor_has_lon_flag =
true;
1953 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag)
1958 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag)
1961 coor_has_lat_flag =
false;
1962 coor_has_lon_flag =
false;
1968 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag) {
1970 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
1972 bool var_is_lat =
false;
1973 bool var_is_lon =
false;
1975 string varname = (*irv)->name;
1979 if(varname.size() >=3) {
1980 ll_ssuffix = varname.substr(varname.size()-3,3);
1981 if(varname.size() >=8) {
1982 ll_lsuffix1 = varname.substr(varname.size()-8,8);
1983 if(varname.size() >=9)
1984 ll_lsuffix2 = varname.substr(varname.size()-9,9);
1987 if(ll_ssuffix==
"lat" || ll_lsuffix1 ==
"latitude" || ll_lsuffix1 ==
"Latitude")
1989 else if(ll_ssuffix==
"lon" || ll_lsuffix2 ==
"longitude" || ll_lsuffix2 ==
"Longitude")
1993 if(
true == var_is_lat) {
1994 if((*irv)->rank > 0) {
1995 auto lat =
new Var(*irv);
1996 tempvar_lat.push_back(lat);
1999 else if(
true == var_is_lon) {
2000 if((*irv)->rank >0) {
2001 auto lon =
new Var(*irv);
2002 tempvar_lon.push_back(lon);
2012 for (
auto irlat = tempvar_lat.begin(); irlat!=tempvar_lat.end();++irlat) {
2015 if((*irlat)->rank == 1)
2016 Build_lat1D_latlon_candidate(*irlat,tempvar_lon);
2019 else if((*irlat)->rank >1)
2020 Build_latg1D_latlon_candidate(*irlat,tempvar_lon);
2024for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
2025cerr<<
"struct lat lon names are " <<(*ivs).name1 <<
" and " << (*ivs).name2 <<endl;
2032 Build_unique_latlon_candidate();
2046 if(latloncv_candidate_pairs.size() >0) {
2047 int num_1d_rank = 0;
2048 int num_2d_rank = 0;
2049 int num_g2d_rank = 0;
2050 vector<struct Name_Size_2Pairs> temp_1d_latlon_pairs;
2051 for(
auto ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
2052 if(1 == (*ivs).rank) {
2054 temp_1d_latlon_pairs.push_back(*ivs);
2056 else if(2 == (*ivs).rank)
2058 else if((*ivs).rank >2)
2063 if (num_2d_rank !=0)
2065 else if(num_1d_rank!=0) {
2069 for(
auto ivs=temp_1d_latlon_pairs.begin(); ivs!=temp_1d_latlon_pairs.end();++ivs) {
2070 if((*ivs).size1 != (*ivs).size2) {
2081 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2083 if((*irv)->rank >=2) {
2084 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
2087 if((*ira)->name == co_attrname) {
2088 Retrieve_H5_Attr_Value((*ira),(*irv)->fullpath);
2089 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
2090 vector<string> coord_values;
2092 HDF5CFUtil::Split_helper(coord_values,orig_attr_value,sep);
2093 bool has_lat_flag =
false;
2094 bool has_lon_flag =
false;
2095 for (
auto itcv=coord_values.begin();itcv!=coord_values.end();++itcv) {
2096 if((*ivs).name1 == (*itcv))
2097 has_lat_flag =
true;
2098 else if((*ivs).name2 == (*itcv))
2099 has_lon_flag =
true;
2102 if(
true == has_lat_flag &&
true == has_lon_flag) {
2103 short has_same_ll_size = 0;
2104 for(
auto ird = (*irv)->dims.begin();ird!=(*irv)->dims.end();++ird){
2105 if((*ird)->size == (*ivs).size1)
2108 if(has_same_ll_size!=2){
2116 if(
false == ret_value)
2121 if(
true == ret_value)
2128 release_standalone_var_vector(tempvar_lat);
2129 release_standalone_var_vector(tempvar_lon);
2133if(
true == ret_value)
2134cerr<<
"This product is the coordinate type "<<endl;
2137 if(
true == ret_value)
2138 this->gproduct_pattern = GENERAL_LATLON_COOR_ATTR;
2144void GMFile::Build_lat1D_latlon_candidate(
const Var *lat,
const vector<Var*> &lon_vec) {
2146 BESDEBUG(
"h5",
"Coming to Build_lat1D_latlon_candidate()"<<endl);
2147 set<string> lon_candidate_path;
2148 vector< pair<string,hsize_t> > lon_path_size_vec;
2151 for(
auto irlon = lon_vec.begin(); irlon!=lon_vec.end();++irlon) {
2153 if (lat->rank == (*irlon)->rank) {
2154 pair<string,hsize_t>lon_path_size;
2155 lon_path_size.first = (*irlon)->fullpath;
2156 lon_path_size.second = (*irlon)->getDimensions()[0]->size;
2157 lon_path_size_vec.push_back(lon_path_size);
2162 if(lon_path_size_vec.size() == 1) {
2165 latlon_pair.name1 = lat->fullpath;
2166 latlon_pair.name2 = lon_path_size_vec[0].first;
2168 latlon_pair.size2 = lon_path_size_vec[0].second;
2169 latlon_pair.rank = lat->rank;
2170 latloncv_candidate_pairs.push_back(latlon_pair);
2173 else if(lon_path_size_vec.size() >1) {
2177 string lat_path = HDF5CFUtil::obtain_string_before_lastslash(lat->fullpath);
2178 pair<string,hsize_t> lon_final_path_size;
2179 short num_lon_match = 0;
2180 for (
auto islon =lon_path_size_vec.begin();islon!=lon_path_size_vec.end();++islon) {
2182 if(HDF5CFUtil::obtain_string_before_lastslash((*islon).first)==lat_path) {
2184 if(1 == num_lon_match)
2185 lon_final_path_size = *islon;
2186 else if(num_lon_match > 1)
2190 if(num_lon_match ==1) {
2192 latlon_pair.name1 = lat->fullpath;
2193 latlon_pair.name2 = lon_final_path_size.first;
2195 latlon_pair.size2 = lon_final_path_size.second;
2196 latlon_pair.rank = lat->rank;
2197 latloncv_candidate_pairs.push_back(latlon_pair);
2204void GMFile::Build_latg1D_latlon_candidate(
Var *lat,
const vector<Var*> & lon_vec) {
2206 BESDEBUG(
"h5",
"Coming to Build_latg1D_latlon_candidate()"<<endl);
2207 set<string> lon_candidate_path;
2210 for(
auto irlon = lon_vec.begin(); irlon!=lon_vec.end();++irlon) {
2212 if (lat->rank == (*irlon)->rank) {
2215 bool same_dim =
true;
2216 for(
int dim_index = 0; dim_index <lat->rank; dim_index++) {
2218 (*irlon)->getDimensions()[dim_index]->size){
2223 if(
true == same_dim)
2224 lon_candidate_path.insert((*irlon)->fullpath);
2229 if(lon_candidate_path.size() > 1) {
2231 string lat_path = HDF5CFUtil::obtain_string_before_lastslash(lat->fullpath);
2232 vector <string> lon_final_candidate_path_vec;
2233 for(
auto islon_path =lon_candidate_path.begin();islon_path!=lon_candidate_path.end();++islon_path) {
2236 if(HDF5CFUtil::obtain_string_before_lastslash(*islon_path)==lat_path)
2237 lon_final_candidate_path_vec.push_back(*islon_path);
2240 if(lon_final_candidate_path_vec.size() == 1) {
2244 latlon_pair.name1 = lat->fullpath;
2245 latlon_pair.name2 = lon_final_candidate_path_vec[0];
2248 latlon_pair.rank = lat->rank;
2249 latloncv_candidate_pairs.push_back(latlon_pair);
2251 else if(lon_final_candidate_path_vec.size() >1) {
2258 string lat_name = HDF5CFUtil::obtain_string_after_lastslash(lat->fullpath);
2259 string lat_name_prefix1;
2260 string lat_name_prefix2;
2263 if(lat_name.size() >3) {
2264 lat_name_prefix1 = lat_name.substr(0,lat_name.size()-3);
2265 if(lat_name.size() >8)
2266 lat_name_prefix2 = lat_name.substr(0,lat_name.size()-8);
2268 string lon_name_prefix1;
2269 string lon_name_prefix2;
2271 for(
auto ilon = lon_final_candidate_path_vec.begin(); ilon!=lon_final_candidate_path_vec.end();++ilon) {
2272 string lon_name = HDF5CFUtil::obtain_string_after_lastslash(*ilon);
2273 if(lon_name.size() >3) {
2274 lon_name_prefix1 = lon_name.substr(0,lon_name.size()-3);
2275 if(lon_name.size() >9)
2276 lon_name_prefix2 = lon_name.substr(0,lon_name.size()-9);
2278 if((lat_name_prefix1 !=
"" && lat_name_prefix1 == lon_name_prefix1) ||
2279 (lat_name_prefix2 !=
"" && lat_name_prefix2 == lon_name_prefix2)) {
2282 latlon_pair.name1 = lat->fullpath;
2283 latlon_pair.name2 = *ilon;
2286 latlon_pair.rank = lat->rank;
2287 latloncv_candidate_pairs.push_back(latlon_pair);
2294 else if(lon_candidate_path.size() == 1) {
2298 latlon_pair.name1 = lat->fullpath;
2299 latlon_pair.name2 = *(lon_candidate_path.begin());
2302 latlon_pair.rank = lat->rank;
2303 latloncv_candidate_pairs.push_back(latlon_pair);
2311void GMFile::Build_unique_latlon_candidate() {
2313 BESDEBUG(
"h5",
"Coming to Build_unique_latlon_candidate()"<<endl);
2314 set<int> duplicate_index;
2315 for(
unsigned int i= 0; i<latloncv_candidate_pairs.size();i++) {
2316 for(
unsigned int j=i+1;j<latloncv_candidate_pairs.size();j++) {
2317 if(latloncv_candidate_pairs[i].name2 == latloncv_candidate_pairs[j].name2) {
2318 duplicate_index.insert(i);
2319 duplicate_index.insert(j);
2325 for(
auto its= duplicate_index.rbegin();its!=duplicate_index.rend();++its) {
2326 latloncv_candidate_pairs[*its] = latloncv_candidate_pairs.back();
2327 latloncv_candidate_pairs.pop_back();
2334bool GMFile::Check_LatLonName_General_Product(
int ll_rank) {
2336 if(ll_rank <1 || ll_rank >2)
2337 throw2(
"Only support rank = 1 or 2 lat/lon case for the general product. The current rank is ",ll_rank);
2338 bool ret_value =
false;
2339 size_t lat2D_dimsize0 = 0;
2340 size_t lat2D_dimsize1 = 0;
2341 size_t lon2D_dimsize0 = 0;
2342 size_t lon2D_dimsize1 = 0;
2345 vector<short>ll_flag(3,0);
2347 vector<size_t>lat_size;
2348 vector<size_t>lon_size;
2353 lat_size.assign(6,0);
2354 lon_size.assign(6,0);
2357 for (vector<Var *>::iterator irv = this->
vars.begin();
2358 irv != this->vars.end(); ++irv) {
2360 if((*irv)->rank == ll_rank) {
2361 if((*irv)->name ==
"lat") {
2364 lat_size[0] = (*irv)->getDimensions()[0]->size;
2365 lat_size[1] = (*irv)->getDimensions()[1]->size;
2370 else if((*irv)->name ==
"lon") {
2373 lon_size[0] = (*irv)->getDimensions()[0]->size;
2374 lon_size[1] = (*irv)->getDimensions()[1]->size;
2379 else if((*irv)->name ==
"latitude"){
2382 lat_size[2] = (*irv)->getDimensions()[0]->size;
2383 lat_size[3] = (*irv)->getDimensions()[1]->size;
2387 else if((*irv)->name ==
"longitude"){
2390 lon_size[2] = (*irv)->getDimensions()[0]->size;
2391 lon_size[3] = (*irv)->getDimensions()[1]->size;
2396 else if((*irv)->name ==
"Latitude"){
2399 lat_size[4] = (*irv)->getDimensions()[0]->size;
2400 lat_size[5] = (*irv)->getDimensions()[1]->size;
2405 else if((*irv)->name ==
"Longitude"){
2408 lon_size[4] = (*irv)->getDimensions()[0]->size;
2409 lon_size[5] = (*irv)->getDimensions()[1]->size;
2415 int total_llflag = 0;
2416 for (
int i = 0; i < ll_flag.size();i++)
2421 if(1 == total_llflag) {
2422 bool latlon_size_match =
true;
2424 for (
int size_index = 0; size_index <lat_size.size();size_index++) {
2425 if(lat_size[size_index] != lon_size[size_index]){
2426 latlon_size_match =
false;
2432 if(
true == latlon_size_match) {
2434 if(2 == ll_flag[0]) {
2438 else if ( 2 == ll_flag[1]) {
2439 gp_latname =
"latitude";
2440 gp_lonname =
"longitude";
2443 else if (2 == ll_flag[2]){
2444 gp_latname =
"Latitude";
2445 gp_lonname =
"Longitude";
2455void GMFile::Add_Dim_Name_LatLon2D_General_Product() {
2457 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_LatLon2D_General_Product()"<<endl);
2460 size_t latdimsize0 = 0;
2461 size_t latdimsize1 = 0;
2464 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2466 set<hsize_t> fakedimsize;
2467 pair<set<hsize_t>::iterator,
bool> setsizeret;
2468 int num_dup_dim_size = 0;
2469 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
2470 Add_One_FakeDim_Name(*ird);
2471 setsizeret = fakedimsize.insert((*ird)->size);
2474 if (
false == setsizeret.second){
2476 Adjust_Duplicate_FakeDim_Name2(*ird,num_dup_dim_size);
2480 if (
false == setsizeret.second)
2481 Adjust_Duplicate_FakeDim_Name(*ird);
2487 if((*irv)->name == gp_latname) {
2488 if((*irv)->rank != 2) {
2489 throw4(
"coordinate variables ",gp_latname,
2490 " must have rank 2 for the 2-D latlon case , the current rank is ",
2493 latdimname0 = (*irv)->getDimensions()[0]->name;
2494 latdimsize0 = (*irv)->getDimensions()[0]->size;
2496 latdimname1 = (*irv)->getDimensions()[1]->name;
2497 latdimsize1 = (*irv)->getDimensions()[1]->size;
2504 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2505 int lat_dim0_index = 0;
2506 int lat_dim1_index = 0;
2507 bool has_lat_dims_size =
false;
2509 for (
unsigned int dim_index = 0; dim_index <(*irv)->dims.size(); dim_index++) {
2512 if(((*irv)->dims[dim_index])->size == latdimsize0) {
2515 lat_dim0_index = dim_index;
2516 for(
unsigned int dim_index2 = dim_index+1;dim_index2 < (*irv)->dims.size();dim_index2++) {
2517 if(((*irv)->dims[dim_index2])->size == latdimsize1) {
2518 lat_dim1_index = dim_index2;
2519 has_lat_dims_size =
true;
2524 if(
true == has_lat_dims_size)
2528 if(
true == has_lat_dims_size) {
2530 ((*irv)->dims[lat_dim0_index])->name = latdimname0;
2534 ((*irv)->dims[lat_dim1_index])->name = latdimname1;
2547 set<string>tempdimnamelist;
2549 for (
auto irv = this->
vars.begin(); irv != this->
vars.end(); ++irv) {
2550 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird)
2551 tempdimnamelist.insert((*ird)->name);
2555 set<string>finaldimnamelist;
2556 string finaldimname_base =
"FakeDim";
2558 for(
unsigned int i = 0; i<tempdimnamelist.size();i++) {
2559 stringstream sfakedimindex;
2561 string finaldimname = finaldimname_base + sfakedimindex.str();
2562 finaldimnamelist.insert(finaldimname);
2567 if(finaldimnamelist != tempdimnamelist) {
2568 map<string,string> tempdimname_to_finaldimname;
2569 auto tempit = tempdimnamelist.begin();
2570 auto finalit = finaldimnamelist.begin();
2571 while(tempit != tempdimnamelist.end()) {
2572 tempdimname_to_finaldimname[*tempit] = *finalit;
2578 for (
auto irv = this->
vars.begin(); irv != this->
vars.end(); ++irv) {
2579 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
2580 if(tempdimname_to_finaldimname.find((*ird)->name) !=tempdimname_to_finaldimname.end())
2581 (*ird)->name = tempdimname_to_finaldimname[(*ird)->name];
2583 throw3(
"The dimension names ",(*ird)->name,
"cannot be found in the dim. name list.");
2589 dimnamelist.clear();
2590 dimnamelist = finaldimnamelist;
2593 dimname_to_dimsize.clear();
2594 for (
auto irv = this->
vars.begin(); irv != this->
vars.end(); ++irv) {
2595 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
2596 if(finaldimnamelist.find((*ird)->name)!=finaldimnamelist.end()) {
2597 dimname_to_dimsize[(*ird)->name] = (*ird)->size;
2598 dimname_to_unlimited[(*ird)->name] = (*ird)->unlimited_dim;
2599 finaldimnamelist.erase((*ird)->name);
2603 if(
true == finaldimnamelist.empty())
2608 for (
auto irv = this->
vars.begin(); irv != this->
vars.end(); ++irv) {
2609 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird)
2610 (*ird)->newname = (*ird)->name;
2617void GMFile::Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product() {
2619 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product()"<<endl);
2621 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2622 set<hsize_t> fakedimsize;
2623 pair<set<hsize_t>::iterator,
bool> setsizeret;
2624 int num_dup_dim_size = 0;
2625 for (
auto ird= (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
2626 Add_One_FakeDim_Name(*ird);
2627 setsizeret = fakedimsize.insert((*ird)->size);
2634 if (
false == setsizeret.second){
2636 Adjust_Duplicate_FakeDim_Name2(*ird,num_dup_dim_size);
2640 if (
false == setsizeret.second){
2642 Adjust_Duplicate_FakeDim_Name(*ird,num_dup_dim_size);
2650for (vector<Var *>::iterator irv = this->
vars.begin();
2651 irv != this->vars.end(); ++irv) {
2652cerr<<
"Var name is "<<(*irv)->newname<<endl;
2653 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2654 ird != (*irv)->dims.end(); ++ird)
2655cerr<<
"Dimension name is "<<(*ird)->newname <<endl;
2662void GMFile::Add_Dim_Name_Dimscale_General_Product() {
2664 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Dimscale_General_Product()"<<endl);
2666 pair<set<string>::iterator,
bool> setret;
2667 this->iscoard =
true;
2669 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
2672 Handle_UseDimscale_Var_Dim_Names_General_Product((*irv));
2675 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
2676 setret = dimnamelist.insert((*ird)->name);
2677 if (
true == setret.second)
2678 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
2682 if (
true == dimnamelist.empty())
2683 throw1(
"This product should have the dimension names, but no dimension names are found");
2688void GMFile::Handle_UseDimscale_Var_Dim_Names_General_Product(
Var *var) {
2690 BESDEBUG(
"h5",
"Coming to Handle_UseDimscale_Var_Dim_Names_General_Product()"<<endl);
2692 bool has_dimlist =
false;
2693 bool has_dimclass =
false;
2695 for(
auto ira = var->attrs.begin(); ira != var->attrs.end();ira++) {
2696 if (
"DIMENSION_LIST" == (*ira)->name) {
2700 if (
"CLASS" == (*ira)->name) {
2702 Retrieve_H5_Attr_Value(*ira,var->fullpath);
2704 class_value.resize((*ira)->value.size());
2705 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
2709 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2710 has_dimclass =
true;
2718 if (
true == has_dimlist)
2719 Add_UseDimscale_Var_Dim_Names_General_Product(var,dimlistattr);
2722 else if(
true == has_dimclass) {
2723 if (var->dims.size() !=1)
2724 throw2(
"Currently dimension scale dataset must be 1 dimension, this is not true for the dataset ",
2729 (var->dims)[0]->name = var->fullpath;
2730 (var->dims)[0]->newname = var->fullpath;
2731 pair<set<string>::iterator,
bool> setret;
2732 setret = dimnamelist.insert((var->dims)[0]->name);
2733 if (
true == setret.second)
2734 Insert_One_NameSizeMap_Element((var->dims)[0]->name,(var->dims)[0]->size,(var->dims)[0]->unlimited_dim);
2740 set<hsize_t> fakedimsize;
2741 pair<set<hsize_t>::iterator,
bool> setsizeret;
2742 for (vector<Dimension *>::iterator ird= var->dims.begin();
2743 ird != var->dims.end(); ++ird) {
2744 Add_One_FakeDim_Name(*ird);
2745 setsizeret = fakedimsize.insert((*ird)->size);
2747 if (
false == setsizeret.second)
2748 Adjust_Duplicate_FakeDim_Name(*ird);
2755void GMFile::Add_UseDimscale_Var_Dim_Names_General_Product(
Var *var,
Attribute*dimlistattr)
2758 BESDEBUG(
"h5",
"Coming to Add_UseDimscale_Var_Dim_Names_General_Product()"<<endl);
2759 ssize_t objnamelen = -1;
2762 vector<hvl_t> vlbuf;
2766 hid_t atype_id = -1;
2767 hid_t amemtype_id = -1;
2768 hid_t aspace_id = -1;
2769 hid_t ref_dset = -1;
2771 if(
nullptr == dimlistattr)
2772 throw2(
"Cannot obtain the dimension list attribute for variable ",var->name);
2774 else if (0==var->rank)
2775 throw2(
"The number of dimension should NOT be 0 for the variable ",var->name);
2780 vlbuf.resize(var->rank);
2782 dset_id = H5Dopen(this->fileid,(var->fullpath).c_str(),H5P_DEFAULT);
2784 throw2(
"Cannot open the dataset ",var->fullpath);
2786 attr_id = H5Aopen(dset_id,(dimlistattr->name).c_str(),H5P_DEFAULT);
2788 throw4(
"Cannot open the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
2790 atype_id = H5Aget_type(attr_id);
2792 throw4(
"Cannot obtain the datatype of the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
2794 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
2796 if (amemtype_id < 0)
2797 throw2(
"Cannot obtain the memory datatype for the attribute ",dimlistattr->name);
2800 if (H5Aread(attr_id,amemtype_id,vlbuf.data()) <0)
2801 throw2(
"Cannot obtain the referenced object for the variable ",var->name);
2804 vector<char> objname;
2805 int vlbuf_index = 0;
2808 for (
auto ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
2810 if(vlbuf[vlbuf_index].p==
nullptr)
2811 throw4(
"The dimension doesn't exist. Var name is ",var->name,
"; the dimension index is ",vlbuf_index);
2812 rbuf =((hobj_ref_t*)vlbuf[vlbuf_index].p)[0];
2813 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0)
2814 throw2(
"Cannot dereference from the DIMENSION_LIST attribute for the variable ",var->name);
2816 if ((objnamelen= H5Iget_name(ref_dset,
nullptr,0))<=0)
2817 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
2818 objname.resize(objnamelen+1);
2819 if ((objnamelen= H5Iget_name(ref_dset,objname.data(),objnamelen+1))<=0)
2820 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
2822 auto objname_str = string(objname.begin(),objname.end());
2828 string trim_objname = objname_str.substr(0,objnamelen);
2829 (*ird)->name = string(trim_objname.begin(),trim_objname.end());
2831 pair<set<string>::iterator,
bool> setret;
2832 setret = dimnamelist.insert((*ird)->name);
2833 if (
true == setret.second)
2834 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
2835 (*ird)->newname = (*ird)->name;
2844 if(vlbuf.empty() ==
false) {
2846 if ((aspace_id = H5Aget_space(attr_id)) < 0)
2847 throw2(
"Cannot get hdf5 dataspace id for the attribute ",dimlistattr->name);
2849 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)vlbuf.data())<0)
2850 throw2(
"Cannot successfully clean up the variable length memory for the variable ",var->name);
2852 H5Sclose(aspace_id);
2857 H5Tclose(amemtype_id);
2867 if(amemtype_id != -1)
2868 H5Tclose(amemtype_id);
2871 H5Sclose(aspace_id);
2888 BESDEBUG(
"h5",
"GMFile:: Coming to Handle_CVar()"<<endl);
2894 if (General_Product == this->product_type ||
2895 ACOS_L2S_OR_OCO2_L1B == this->product_type) {
2896 if (GENERAL_DIMSCALE == this->gproduct_pattern)
2897 Handle_CVar_Dimscale_General_Product();
2898 else if (GENERAL_LATLON1D == this->gproduct_pattern)
2899 Handle_CVar_LatLon1D_General_Product();
2900 else if (GENERAL_LATLON2D == this->gproduct_pattern)
2901 Handle_CVar_LatLon2D_General_Product();
2905 else if (Mea_SeaWiFS_L2 == this->product_type ||
2906 Mea_SeaWiFS_L3 == this->product_type)
2907 Handle_CVar_Mea_SeaWiFS();
2908 else if (Aqu_L3 == this->product_type)
2909 Handle_CVar_Aqu_L3();
2910 else if (OBPG_L3 == this->product_type)
2911 Handle_CVar_OBPG_L3();
2912 else if (OSMAPL2S == this->product_type)
2913 Handle_CVar_OSMAPL2S();
2914 else if (Mea_Ozone == this->product_type)
2915 Handle_CVar_Mea_Ozone();
2916 else if (GPMS_L3 == this->product_type || GPMM_L3 == this->product_type
2917 || GPM_L3_New == this->product_type )
2918 Handle_CVar_GPM_L3();
2919 else if (GPM_L1 == this->product_type)
2920 Handle_CVar_GPM_L1();
2924void GMFile::Handle_CVar_GPM_L1() {
2926 BESDEBUG(
"h5",
"Coming to Handle_CVar_GPM_L1()"<<endl);
2929 for (vector<Var *>::iterator irv = this->
vars.begin();
2930 irv != this->vars.end(); ++irv) {
2931 if((*irv)->name==
"AlgorithmRuntimeInfo") {
2933 this->
vars.erase(irv);
2946 set<string> ll_dim_set;
2947 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
2948 if((*irv)->rank == 2 && (*irv)->name ==
"Latitude") {
2949 auto GMcvar =
new GMCVar(*irv);
2950 size_t lat_pos = (*irv)->fullpath.rfind(
"Latitude");
2951 string lat_path = (*irv)->fullpath.substr(0,lat_pos);
2952 GMcvar->cfdimname = lat_path + ((*irv)->dims)[0]->name;
2953 ll_dim_set.insert(((*irv)->dims)[0]->name);
2954 GMcvar->cvartype = CV_EXIST;
2955 GMcvar->product_type = product_type;
2956 this->cvars.push_back(GMcvar);
2958 irv = this->
vars.erase(irv);
2961 if((*irv)->rank == 2 && (*irv)->name ==
"Longitude") {
2962 auto GMcvar =
new GMCVar(*irv);
2963 size_t lon_pos = (*irv)->fullpath.rfind(
"Longitude");
2964 string lon_path = (*irv)->fullpath.substr(0,lon_pos);
2965 GMcvar->cfdimname = lon_path + ((*irv)->dims)[1]->name;
2966 ll_dim_set.insert(((*irv)->dims)[1]->name);
2967 GMcvar->cvartype = CV_EXIST;
2968 GMcvar->product_type = product_type;
2969 this->cvars.push_back(GMcvar);
2971 irv = this->
vars.erase(irv);
2980 set<string> cvdimset;
2981 pair<set<string>::iterator,
bool> setret;
2982 for (vector<Var *>::iterator irv = this->
vars.begin();
2983 irv != this->
vars.end(); ++irv) {
2984 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();
2985 ird != (*irv)->dims.end(); ++ird) {
2986 setret = cvdimset.insert((*ird)->name);
2987cerr<<
"var name is "<<(*irv)->fullpath <<endl;
2988 if (
true == setret.second) {
2989cerr<<
"dim name is "<<(*ird)->name <<endl;
2990 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size);
2999 for (map<string,hsize_t>::const_iterator itd = dimname_to_dimsize.begin();
3000 itd!=dimname_to_dimsize.end();++itd) {
3003 if((ll_dim_set.find(itd->first)) == ll_dim_set.end()) {
3004 auto GMcvar =
new GMCVar();
3005 Create_Missing_CV(GMcvar,itd->first);
3006 this->cvars.push_back(GMcvar);
3013void GMFile::Handle_CVar_GPM_L3() {
3015 BESDEBUG(
"h5",
"Coming to Handle_CVar_GPM_L3()"<<endl);
3020 for (map<string,hsize_t>::const_iterator itd = dimname_to_dimsize.begin();
3021 itd!=dimname_to_dimsize.end();++itd) {
3023 auto GMcvar =
new GMCVar();
3024 if(
"nlon" == itd->first ||
"nlat" == itd->first
3025 ||
"lnH" == itd->first ||
"ltH" == itd->first
3026 ||
"lnL" == itd->first ||
"ltL" == itd->first) {
3027 GMcvar->name = itd->first;
3028 GMcvar->newname = GMcvar->name;
3029 GMcvar->fullpath = GMcvar->name;
3031 GMcvar->dtype = H5FLOAT32;
3032 auto gmcvar_dim =
new Dimension(itd->second);
3033 gmcvar_dim->name = GMcvar->name;
3034 gmcvar_dim->newname = gmcvar_dim->name;
3035 GMcvar->dims.push_back(gmcvar_dim);
3036 GMcvar->cfdimname = gmcvar_dim->name;
3037 if (
"nlat" ==GMcvar->name ||
"ltH" == GMcvar->name
3038 ||
"ltL" == GMcvar->name)
3039 GMcvar->cvartype = CV_LAT_MISS;
3040 else if (
"nlon" == GMcvar->name ||
"lnH" == GMcvar->name
3041 ||
"lnL" == GMcvar->name)
3042 GMcvar->cvartype = CV_LON_MISS;
3043 GMcvar->product_type = product_type;
3045 else if ((
"nlayer" == itd->first && (28 == itd->second || 19 == itd->second)) ||
3046 (
"hgt" == itd->first && 5 == itd->second) ||
3047 (
"nalt" == itd->first && 5 == itd->second)){
3048 GMcvar->name = itd->first;
3049 GMcvar->newname = GMcvar->name;
3050 GMcvar->fullpath = GMcvar->name;
3052 GMcvar->dtype = H5FLOAT32;
3053 auto gmcvar_dim =
new Dimension(itd->second);
3054 gmcvar_dim->name = GMcvar->name;
3055 gmcvar_dim->newname = gmcvar_dim->name;
3056 GMcvar->dims.push_back(gmcvar_dim);
3057 GMcvar->cfdimname = gmcvar_dim->name;
3058 GMcvar->cvartype = CV_SPECIAL;
3059 GMcvar->product_type = product_type;
3062 Create_Missing_CV(GMcvar,itd->first);
3063 this->cvars.push_back(GMcvar);
3068void GMFile::Handle_CVar_Mea_SeaWiFS() {
3070 BESDEBUG(
"h5",
"Coming to Handle_CVar_Mea_SeaWiFS()"<<endl);
3071 pair<set<string>::iterator,
bool> setret;
3072 set<string>tempdimnamelist = dimnamelist;
3074 for (
auto irs = dimnamelist.begin(); irs != dimnamelist.end();++irs) {
3075 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
3076 if ((*irs)== (*irv)->fullpath) {
3078 if (!iscoard && ((
"/natrack" == (*irs))
3079 ||
"/nxtrack" == (*irs))) {
3084 if((*irv)->dims.size()!=1)
3085 throw3(
"Coard coordinate variable ",(*irv)->name,
"is not 1D");
3088 tempdimnamelist.erase(*irs);
3089 auto GMcvar =
new GMCVar(*irv);
3090 GMcvar->cfdimname = *irs;
3091 GMcvar->cvartype = CV_EXIST;
3092 GMcvar->product_type = product_type;
3093 this->cvars.push_back(GMcvar);
3095 irv = this->
vars.erase(irv);
3097 else if(
false == iscoard) {
3099 if ((((*irs) ==
"/natrack") && ((*irv)->fullpath ==
"/latitude"))
3100 ||(((*irs) ==
"/nxtrack") && ((*irv)->fullpath ==
"/longitude"))) {
3101 tempdimnamelist.erase(*irs);
3102 auto GMcvar =
new GMCVar(*irv);
3103 GMcvar->cfdimname = *irs;
3104 GMcvar->cvartype = CV_EXIST;
3105 GMcvar->product_type = product_type;
3106 this->cvars.push_back(GMcvar);
3108 irv = this->
vars.erase(irv);
3124 for (set<string>::iterator irs = tempdimnamelist.begin();
3125 irs != tempdimnamelist.end();++irs) {
3126 auto GMcvar =
new GMCVar();
3127 Create_Missing_CV(GMcvar,*irs);
3128 this->cvars.push_back(GMcvar);
3133void GMFile::Handle_CVar_OSMAPL2S() {
3135 BESDEBUG(
"h5",
"Coming to Handle_CVar_OSMAPL2S()"<<endl);
3136 pair<set<string>::iterator,
bool> setret;
3137 set<string>tempdimnamelist = dimnamelist;
3139 string key0 =
"_lat";
3140 string key1 =
"_lon";
3141 string osmapl2sdim0 =
"YDim";
3142 string osmapl2sdim1 =
"XDim";
3144 bool foundkey0 =
false;
3145 bool foundkey1 =
false;
3149 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
3151 tempvarname = (*irv)->name;
3153 if ((tempvarname.size() > key0.size())&&
3154 (key0 == tempvarname.substr(tempvarname.size()-key0.size(),key0.size()))){
3158 if (dimnamelist.find(osmapl2sdim0)== dimnamelist.end())
3159 throw5(
"variable ",tempvarname,
" must have dimension ",osmapl2sdim0,
" , but not found ");
3161 tempdimnamelist.erase(osmapl2sdim0);
3162 auto GMcvar =
new GMCVar(*irv);
3163 GMcvar->newname = GMcvar->name;
3164 GMcvar->cfdimname = osmapl2sdim0;
3165 GMcvar->cvartype = CV_EXIST;
3166 GMcvar->product_type = product_type;
3167 this->cvars.push_back(GMcvar);
3169 irv = this->
vars.erase(irv);
3172 else if ((tempvarname.size() > key1.size())&&
3173 (key1 == tempvarname.substr(tempvarname.size()-key1.size(),key1.size()))){
3177 if (dimnamelist.find(osmapl2sdim1)== dimnamelist.end())
3178 throw5(
"variable ",tempvarname,
" must have dimension ",osmapl2sdim1,
" , but not found ");
3180 tempdimnamelist.erase(osmapl2sdim1);
3182 auto GMcvar =
new GMCVar(*irv);
3183 GMcvar->newname = GMcvar->name;
3184 GMcvar->cfdimname = osmapl2sdim1;
3185 GMcvar->cvartype = CV_EXIST;
3186 GMcvar->product_type = product_type;
3187 this->cvars.push_back(GMcvar);
3189 irv = this->
vars.erase(irv);
3194 if (
true == foundkey0 &&
true == foundkey1)
3198 for (
auto irs = tempdimnamelist.begin(); irs != tempdimnamelist.end();++irs) {
3200 auto GMcvar =
new GMCVar();
3201 Create_Missing_CV(GMcvar,*irs);
3202 this->cvars.push_back(GMcvar);
3208void GMFile::Handle_CVar_Aqu_L3() {
3210 BESDEBUG(
"h5",
"Coming to Handle_CVar_Aqu_L3()"<<endl);
3212 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
3214 if (
"l3m_data" == (*irv)->name) {
3215 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird) {
3216 auto GMcvar =
new GMCVar();
3217 GMcvar->name = (*ird)->name;
3218 GMcvar->newname = GMcvar->name;
3219 GMcvar->fullpath = GMcvar->name;
3221 GMcvar->dtype = H5FLOAT32;
3222 auto gmcvar_dim =
new Dimension((*ird)->size);
3223 gmcvar_dim->name = GMcvar->name;
3224 gmcvar_dim->newname = gmcvar_dim->name;
3225 GMcvar->dims.push_back(gmcvar_dim);
3226 GMcvar->cfdimname = gmcvar_dim->name;
3227 if (
"lat" ==GMcvar->name ) GMcvar->cvartype = CV_LAT_MISS;
3228 if (
"lon" == GMcvar->name ) GMcvar->cvartype = CV_LON_MISS;
3229 GMcvar->product_type = product_type;
3230 this->cvars.push_back(GMcvar);
3238void GMFile::Handle_CVar_Mea_Ozone() {
3240 BESDEBUG(
"h5",
"Coming to Handle_CVar_Mea_Ozone()"<<endl);
3241 pair<set<string>::iterator,
bool> setret;
3242 set<string>tempdimnamelist = dimnamelist;
3244 if(
false == iscoard)
3245 throw1(
"Measure Ozone level 3 zonal average product must follow COARDS conventions");
3247 for (
auto irs = dimnamelist.begin(); irs != dimnamelist.end();++irs) {
3248 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
3249 if ((*irs)== (*irv)->fullpath) {
3251 if((*irv)->dims.size()!=1)
3252 throw3(
"Coard coordinate variable",(*irv)->name,
"is not 1D");
3255 tempdimnamelist.erase(*irs);
3256 auto GMcvar =
new GMCVar(*irv);
3257 GMcvar->cfdimname = *irs;
3258 GMcvar->cvartype = CV_EXIST;
3259 GMcvar->product_type = product_type;
3260 this->cvars.push_back(GMcvar);
3262 irv = this->
vars.erase(irv);
3270 for (
auto irs = tempdimnamelist.begin(); irs != tempdimnamelist.end();irs++) {
3272 auto GMcvar =
new GMCVar();
3273 Create_Missing_CV(GMcvar,*irs);
3274 this->cvars.push_back(GMcvar);
3279void GMFile::Handle_CVar_Dimscale_General_Product() {
3281 BESDEBUG(
"h5",
"Coming to Handle_CVar_Dimscale_General_Product"<<endl);
3282 pair<set<string>::iterator,
bool> setret;
3283 set<string>tempdimnamelist = dimnamelist;
3285 for (
auto irs = dimnamelist.begin(); irs != dimnamelist.end();++irs) {
3286 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
3289 if ((*irs)== (*irv)->fullpath) {
3290 if((*irv)->dims.size()!=1)
3291 throw3(
"COARDS coordinate variable",(*irv)->name,
"is not 1D");
3294 tempdimnamelist.erase(*irs);
3295 auto GMcvar =
new GMCVar(*irv);
3296 GMcvar->cfdimname = *irs;
3299 bool is_netcdf_dimension = Is_netCDF_Dimension(*irv);
3303 if (
true == is_netcdf_dimension)
3304 GMcvar->cvartype = CV_FILLINDEX;
3306 GMcvar->cvartype = CV_EXIST;
3307 GMcvar->product_type = product_type;
3308 this->cvars.push_back(GMcvar);
3310 irv = this->
vars.erase(irv);
3319 Update_M2DLatLon_Dimscale_CVs();
3322 for (
auto irs = tempdimnamelist.begin(); irs != tempdimnamelist.end();irs++) {
3323 auto GMcvar =
new GMCVar();
3324 Create_Missing_CV(GMcvar,*irs);
3325 this->cvars.push_back(GMcvar);
3331for (set<string>::iterator irs = dimnamelist.begin();
3332 irs != dimnamelist.end();irs++) {
3333cerr<<
"dimension name is "<<(*irs)<<endl;
3342void GMFile::Update_M2DLatLon_Dimscale_CVs() {
3344 BESDEBUG(
"h5",
"Coming to Update_M2DLatLon_Dimscale_CVs()"<<endl);
3346 if(
false == Check_1DGeolocation_Dimscale()) {
3349 vector<GMCVar*> tempcvar_1dlat;
3350 vector<GMCVar*> tempcvar_1dlon;
3353 Obtain_1DLatLon_CVs(tempcvar_1dlat,tempcvar_1dlon);
3356 vector<Var*> tempcvar_2dlat;
3357 vector<Var*> tempcvar_2dlon;
3363 map<string,int> latlon2d_path_to_index;
3366 Obtain_2DLatLon_Vars(tempcvar_2dlat,tempcvar_2dlon,latlon2d_path_to_index);
3369for(vector<GMCVar *>::iterator irv = tempcvar_1dlat.begin();irv != tempcvar_1dlat.end();++irv)
3370cerr<<
"1-D lat variable full path is "<<(*irv)->fullpath <<endl;
3371for(vector<GMCVar *>::iterator irv = tempcvar_1dlon.begin();irv != tempcvar_1dlon.end();++irv)
3372cerr<<
"1-D lon variable full path is "<<(*irv)->fullpath <<endl;
3374for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3375cerr<<
"2-D lat variable full path is "<<(*irv)->fullpath <<endl;
3376for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3377cerr<<
"2-D lon variable full path is "<<(*irv)->fullpath <<endl;
3381 Obtain_2DLLVars_With_Dims_not_1DLLCVars(tempcvar_2dlat,tempcvar_2dlon,tempcvar_1dlat,tempcvar_1dlon,latlon2d_path_to_index);
3384for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3385cerr<<
"2-D Left lat variable full path is "<<(*irv)->fullpath <<endl;
3386for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3387cerr<<
"2-D Left lon variable full path is "<<(*irv)->fullpath <<endl;
3392 Obtain_2DLLCVar_Candidate(tempcvar_2dlat,tempcvar_2dlon,latlon2d_path_to_index);
3395for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3396cerr<<
"Final candidate 2-D Left lat variable full path is "<<(*irv)->fullpath <<endl;
3397for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3398cerr<<
"Final candidate 2-D Left lon variable full path is "<<(*irv)->fullpath <<endl;
3403 vector<int> var2d_index;
3404 for (map<string,int>::const_iterator it= latlon2d_path_to_index.begin();it!=latlon2d_path_to_index.end();++it)
3405 var2d_index.push_back(it->second);
3407 Remove_2DLLCVar_Final_Candidate_from_Vars(var2d_index);
3410 if(tempcvar_2dlat.size()>0)
3415 set<string>dim_names_2d_cvs;
3417 for(
auto irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv){
3418 auto lat =
new GMCVar(*irv);
3421 dim_names_2d_cvs.insert(lat->cfdimname);
3422 lat->cvartype = CV_EXIST;
3423 lat->product_type = product_type;
3424 this->cvars.push_back(lat);
3426 for(
auto irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv){
3427 auto lon =
new GMCVar(*irv);
3429 lon->cfdimname = (*irv)->getDimensions()[1]->name;
3430 dim_names_2d_cvs.insert(lon->cfdimname);
3431 lon->cvartype = CV_EXIST;
3432 lon->product_type = product_type;
3433 this->cvars.push_back(lon);
3439 for(
auto ircv= this->cvars.begin();ircv !=this->cvars.end();) {
3440 if(1 == (*ircv)->rank) {
3441 if(dim_names_2d_cvs.find((*ircv)->cfdimname)!=dim_names_2d_cvs.end()) {
3442 if(CV_FILLINDEX == (*ircv)->cvartype) {
3444 ircv = this->cvars.erase(ircv);
3446 else if(CV_EXIST == (*ircv)->cvartype) {
3449 Var *var =
new Var(*ircv);
3450 this->
vars.push_back(var);
3454 ircv = this->cvars.erase(ircv);
3458 if(CV_LAT_MISS == (*ircv)->cvartype)
3459 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_LAT_MISS");
3460 else if(CV_LON_MISS == (*ircv)->cvartype)
3461 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_LON_MISS");
3462 else if(CV_NONLATLON_MISS == (*ircv)->cvartype)
3463 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_NONLATLON_MISS");
3464 else if(CV_MODIFY == (*ircv)->cvartype)
3465 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_MODIFY");
3466 else if(CV_SPECIAL == (*ircv)->cvartype)
3467 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_SPECIAL");
3469 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_UNSUPPORTED");
3486for(set<string>::iterator irs = grp_cv_paths.begin();irs != grp_cv_paths.end();++irs) {
3487cerr<<
"group path is "<< (*irs)<<endl;
3494cerr<<
"File name is "<< this->path <<endl;
3495cerr<<
"CV names are the following "<<endl;
3496for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i)
3497cerr<<(*i)->fullpath <<endl;
3502 release_standalone_GMCVar_vector(tempcvar_1dlat);
3503 release_standalone_GMCVar_vector(tempcvar_1dlon);
3504 release_standalone_var_vector(tempcvar_2dlat);
3505 release_standalone_var_vector(tempcvar_2dlon);
3508for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i)
3509cerr<<(*i)->fullpath <<endl;
3516bool GMFile::Check_1DGeolocation_Dimscale() {
3518 BESDEBUG(
"h5",
"Coming to Check_1DGeolocation_Dimscale()"<<endl);
3519 bool has_only_1d_geolocation_cv =
false;
3520 bool has_1d_lat_cv_flag =
false;
3521 bool has_1d_lon_cv_flag =
false;
3524 hsize_t lat_size = 0;
3527 hsize_t lon_size = 0;
3530 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
3531 if((*ircv)->cvartype == CV_EXIST) {
3532 string attr_name =
"units";
3533 string lat_unit_value =
"degrees_north";
3534 string lon_unit_value =
"degrees_east";
3536 for(
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end();ira++) {
3538 if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) {
3539 lat_size = (*ircv)->getDimensions()[0]->size;
3540 lat_dimname = (*ircv)->getDimensions()[0]->name;
3541 has_1d_lat_cv_flag =
true;
3544 else if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value)){
3545 lon_size = (*ircv)->getDimensions()[0]->size;
3546 lon_dimname = (*ircv)->getDimensions()[0]->name;
3547 has_1d_lon_cv_flag =
true;
3556 if(
true == has_1d_lat_cv_flag ) {
3558 if(
true == has_1d_lon_cv_flag) {
3561 if(0 == this->
groups.size()) {
3565 if(lat_size == lon_size) {
3566 bool var_has_latdim =
false;
3567 bool var_has_londim =
false;
3568 for (
auto irv = this->
vars.begin();
3569 irv != this->vars.end(); ++irv) {
3570 if((*irv)->rank >= 2) {
3571 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
3572 if((*ird)->name == lat_dimname)
3573 var_has_latdim =
true;
3574 else if((*ird)->name == lon_dimname)
3575 var_has_londim =
true;
3577 if(
true == var_has_latdim &&
true == var_has_londim) {
3578 has_only_1d_geolocation_cv =
true;
3582 var_has_latdim =
false;
3583 var_has_londim =
false;
3589 has_only_1d_geolocation_cv =
true;
3593 bool has_2d_latname_flag =
false;
3594 bool has_2d_lonname_flag =
false;
3595 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
3596 if((*irv)->rank == 2) {
3599 if(
true == Is_geolatlon((*irv)->name,
true))
3600 has_2d_latname_flag =
true;
3603 else if(
true == Is_geolatlon((*irv)->name,
false))
3604 has_2d_lonname_flag =
true;
3606 if((
true == has_2d_latname_flag) && (
true == has_2d_lonname_flag))
3611 if(has_2d_latname_flag !=
true || has_2d_lonname_flag !=
true) {
3614 has_2d_latname_flag =
false;
3615 has_2d_lonname_flag =
false;
3617 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
3618 if((*irv)->rank == 2) {
3619 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira) {
3621 if (
false == has_2d_latname_flag) {
3624 has_2d_latname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
true);
3625 if(
true == has_2d_latname_flag)
3627 else if(
false == has_2d_lonname_flag) {
3630 has_2d_lonname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
false);
3631 if(
true == has_2d_lonname_flag)
3635 else if(
false == has_2d_lonname_flag) {
3639 has_2d_lonname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
false);
3640 if(
true == has_2d_lonname_flag)
3644 if(
true == has_2d_latname_flag &&
true == has_2d_lonname_flag)
3651 if(has_2d_latname_flag !=
true || has_2d_lonname_flag !=
true)
3652 has_only_1d_geolocation_cv =
true;
3657 has_only_1d_geolocation_cv =
true;
3663if(has_only_1d_geolocation_cv ==
true)
3664cerr <<
"has only 1D lat/lon CVs. "<<endl;
3666cerr<<
"Possibly has 2D lat/lon CVs. "<<endl;
3669 return has_only_1d_geolocation_cv;
3675void GMFile::Obtain_1DLatLon_CVs(vector<GMCVar*> &cvar_1dlat,vector<GMCVar*> &cvar_1dlon) {
3677 BESDEBUG(
"h5",
"Coming to Obtain_1DLatLon_CVs()"<<endl);
3678 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
3680 if((*ircv)->cvartype == CV_EXIST) {
3682 string attr_name =
"units";
3683 string lat_unit_value =
"degrees_north";
3684 string lon_unit_value =
"degrees_east";
3686 for(
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end();ira++) {
3689 if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) {
3690 auto lat =
new GMCVar(*ircv);
3692 lat->cvartype = (*ircv)->cvartype;
3693 lat->product_type = (*ircv)->product_type;
3694 cvar_1dlat.push_back(lat);
3697 else if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value)){
3698 auto lon =
new GMCVar(*ircv);
3699 lon->cfdimname = (*ircv)->getDimensions()[0]->name;
3700 lon->cvartype = (*ircv)->cvartype;
3701 lon->product_type = (*ircv)->product_type;
3702 cvar_1dlon.push_back(lon);
3713void GMFile::Obtain_2DLatLon_Vars(vector<Var*> &var_2dlat,vector<Var*> &var_2dlon,map<string,int> & latlon2d_path_to_index) {
3715 BESDEBUG(
"h5",
"Coming to Obtain_2DLatLon_Vars()"<<endl);
3716 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
3717 if((*irv)->rank == 2) {
3720 if(
true == Is_geolatlon((*irv)->name,
true)) {
3721 Var *lat =
new Var(*irv);
3722 var_2dlat.push_back(lat);
3723 latlon2d_path_to_index[(*irv)->fullpath]= distance(this->
vars.begin(),irv);
3728 bool has_2dlat =
false;
3729 for (
auto ira = (*irv)->attrs.begin();
3730 ira != (*irv)->attrs.end(); ++ira) {
3733 if(
true == has_latlon_cf_units((*ira),(*irv)->fullpath,
true)) {
3734 Var *lat =
new Var(*irv);
3735 var_2dlat.push_back(lat);
3736 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3742 if(
true == has_2dlat)
3747 if(
true == Is_geolatlon((*irv)->name,
false)) {
3748 Var *lon =
new Var(*irv);
3749 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3750 var_2dlon.push_back(lon);
3753 for (
auto ira = (*irv)->attrs.begin();
3754 ira != (*irv)->attrs.end(); ++ira) {
3757 if(
true == has_latlon_cf_units((*ira),(*irv)->fullpath,
false)) {
3758 Var *lon =
new Var(*irv);
3759 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3760 var_2dlon.push_back(lon);
3771void GMFile::Obtain_2DLLVars_With_Dims_not_1DLLCVars(vector<Var*> &var_2dlat,
3772 vector<Var*> &var_2dlon,
3773 vector<GMCVar*> &cvar_1dlat,
3774 vector<GMCVar*> &cvar_1dlon,
3775 map<string,int> &latlon2d_path_to_index) {
3777 BESDEBUG(
"h5",
"Coming to Obtain_2DLLVars_With_Dims_not_1DLLCVars()"<<endl);
3779 for(
auto irv = var_2dlat.begin();irv != var_2dlat.end();) {
3780 bool remove_2dlat =
false;
3781 for(
auto ircv = cvar_1dlat.begin();ircv != cvar_1dlat.end();++ircv) {
3782 for (
auto ird = (*irv)->dims.begin(); ird!=(*irv)->dims.end(); ++ird) {
3783 if((*ird)->name == (*ircv)->getDimensions()[0]->name &&
3784 (*ird)->size == (*ircv)->getDimensions()[0]->size) {
3785 latlon2d_path_to_index.erase((*irv)->fullpath);
3787 irv = var_2dlat.erase(irv);
3788 remove_2dlat =
true;
3792 if(
true == remove_2dlat)
3796 if(
false == remove_2dlat)
3801 for(
auto irv = var_2dlon.begin();irv != var_2dlon.end();) {
3802 bool remove_2dlon =
false;
3803 for(
auto ircv = cvar_1dlon.begin();ircv != cvar_1dlon.end();++ircv) {
3804 for (
auto ird = (*irv)->dims.begin();
3805 ird!=(*irv)->dims.end(); ++ird) {
3806 if((*ird)->name == (*ircv)->getDimensions()[0]->name &&
3807 (*ird)->size == (*ircv)->getDimensions()[0]->size) {
3808 latlon2d_path_to_index.erase((*irv)->fullpath);
3810 irv = var_2dlon.erase(irv);
3811 remove_2dlon =
true;
3815 if(
true == remove_2dlon)
3819 if(
false == remove_2dlon)
3826void GMFile::Obtain_2DLLCVar_Candidate(vector<Var*> &var_2dlat,
3827 vector<Var*> &var_2dlon,
3828 map<string,int>& latlon2d_path_to_index) {
3829 BESDEBUG(
"h5",
"Coming to Obtain_2DLLCVar_Candidate()"<<endl);
3832 vector<string> lon2d_group_paths;
3834 for(
auto irv_2dlat = var_2dlat.begin();irv_2dlat !=var_2dlat.end();) {
3835 for(
auto irv_2dlon = var_2dlon.begin();irv_2dlon != var_2dlon.end();++irv_2dlon) {
3836 if(((*irv_2dlat)->getDimensions()[0]->name == (*irv_2dlon)->getDimensions()[0]->name) &&
3837 ((*irv_2dlat)->getDimensions()[0]->size == (*irv_2dlon)->getDimensions()[0]->size) &&
3838 ((*irv_2dlat)->getDimensions()[1]->name == (*irv_2dlon)->getDimensions()[1]->name) &&
3839 ((*irv_2dlat)->getDimensions()[1]->size == (*irv_2dlon)->getDimensions()[1]->size))
3840 lon2d_group_paths.push_back(HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlon)->fullpath));
3844 if(0 == lon2d_group_paths.size()) {
3845 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3847 irv_2dlat = var_2dlat.erase(irv_2dlat);
3853 string lat2d_group_path = HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlat)->fullpath);
3856 short lon2d_has_lat2d_group_path_flag = 0;
3857 for(
auto ivs = lon2d_group_paths.begin();ivs!=lon2d_group_paths.end();++ivs) {
3858 if((*ivs)==lat2d_group_path)
3859 lon2d_has_lat2d_group_path_flag++;
3863 if(0 == lon2d_has_lat2d_group_path_flag) {
3864 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3866 irv_2dlat = var_2dlat.erase(irv_2dlat);
3869 else if (1== lon2d_has_lat2d_group_path_flag) {
3876 grp_cv_paths.insert(lat2d_group_path);
3877 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3879 irv_2dlat = var_2dlat.erase(irv_2dlat);
3884 lon2d_group_paths.clear();
3888for(
auto irv_2dlat = var_2dlat.begin();irv_2dlat !=var_2dlat.end();++irv_2dlat)
3889cerr<<
"2 left 2-D lat variable full path is: "<<(*irv_2dlat)->fullpath <<endl;
3895 vector<string> lat2d_group_paths;
3898 for(
auto irv_2dlon = var_2dlon.begin();irv_2dlon !=var_2dlon.end();) {
3899 for(
auto irv_2dlat = var_2dlat.begin();irv_2dlat != var_2dlat.end();++irv_2dlat) {
3900 if(((*irv_2dlat)->getDimensions()[0]->name == (*irv_2dlon)->getDimensions()[0]->name) &&
3901 ((*irv_2dlat)->getDimensions()[0]->size == (*irv_2dlon)->getDimensions()[0]->size) &&
3902 ((*irv_2dlat)->getDimensions()[1]->name == (*irv_2dlon)->getDimensions()[1]->name) &&
3903 ((*irv_2dlat)->getDimensions()[1]->size == (*irv_2dlon)->getDimensions()[1]->size))
3904 lat2d_group_paths.push_back(HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlat)->fullpath));
3910 if(lat2d_group_paths.empty()) {
3911 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3913 irv_2dlon = var_2dlon.erase(irv_2dlon);
3916 string lon2d_group_path = HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlon)->fullpath);
3919 short lat2d_has_lon2d_group_path_flag = 0;
3920 for(
auto ivs = lat2d_group_paths.begin();ivs!=lat2d_group_paths.end();++ivs) {
3921 if((*ivs)==lon2d_group_path)
3922 lat2d_has_lon2d_group_path_flag++;
3926 if(0 == lat2d_has_lon2d_group_path_flag) {
3927 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3929 irv_2dlon = var_2dlon.erase(irv_2dlon);
3932 else if (1== lat2d_has_lon2d_group_path_flag) {
3939 grp_cv_paths.insert(lon2d_group_path);
3940 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3942 irv_2dlon = var_2dlon.erase(irv_2dlon);
3946 lat2d_group_paths.clear();
3949for(vector<Var*>::iterator itv = var_2dlat.begin(); itv!= var_2dlat.end();++itv) {
3950cerr<<
"Before unique, 2-D CV latitude name is "<<(*itv)->fullpath <<endl;
3952for(vector<Var*>::iterator itv = var_2dlon.begin(); itv!= var_2dlon.end();++itv) {
3953cerr<<
"Before unique, 2-D CV longitude name is "<<(*itv)->fullpath <<endl;
3958 Obtain_unique_2dCV(var_2dlat,latlon2d_path_to_index);
3959 Obtain_unique_2dCV(var_2dlon,latlon2d_path_to_index);
3961for(vector<Var*>::iterator itv = var_2dlat.begin(); itv!= var_2dlat.end();++itv) {
3962cerr<<
"2-D CV latitude name is "<<(*itv)->fullpath <<endl;
3964for(vector<Var*>::iterator itv = var_2dlon.begin(); itv!= var_2dlon.end();++itv) {
3965cerr<<
"2-D CV longitude name is "<<(*itv)->fullpath <<endl;
3970 if(var_2dlat.size() != var_2dlon.size()) {
3971 throw1(
"Error in generating 2-D lat/lon CVs. The size of 2d-lat should be the same as that of 2d-lon.");
3977void GMFile::Obtain_unique_2dCV(vector<Var*> &var_ll,map<string,int>&latlon2d_path_to_index){
3979 BESDEBUG(
"h5",
"Coming to Obtain_unique_2dCV()"<<endl);
3980 vector<bool> var_share_dims(var_ll.size(),
false);
3982 for(
unsigned int i = 0; i <var_ll.size();i++) {
3985 string var_ll_i_path = HDF5CFUtil::obtain_string_before_lastslash(var_ll[i]->fullpath);
3988 for(
unsigned int j = i+1; j<var_ll.size();j++) {
3989 if((var_ll[i]->getDimensions()[0]->name == var_ll[j]->getDimensions()[0]->name)
3990 ||(var_ll[i]->getDimensions()[0]->name == var_ll[j]->getDimensions()[1]->name)
3991 ||(var_ll[i]->getDimensions()[1]->name == var_ll[j]->getDimensions()[0]->name)
3992 ||(var_ll[i]->getDimensions()[1]->name == var_ll[j]->getDimensions()[1]->name)){
3993 string var_ll_j_path = HDF5CFUtil::obtain_string_before_lastslash(var_ll[j]->fullpath);
4000 if(var_ll_i_path.size() > var_ll_j_path.size()) {
4004 if(var_ll_i_path.compare(0,var_ll_j_path.size(),var_ll_j_path)==0) {
4005 var_share_dims[i] =
true;
4006 grp_cv_paths.insert(var_ll_i_path);
4009 var_share_dims[i] =
true;
4010 var_share_dims[j] =
true;
4012 grp_cv_paths.insert(var_ll_i_path);
4013 grp_cv_paths.insert(var_ll_j_path);
4016 else if (var_ll_i_path.size() == var_ll_j_path.size()) {
4017 var_share_dims[i] =
true;
4018 var_share_dims[j] =
true;
4019 if(var_ll_i_path == var_ll_j_path)
4020 grp_cv_paths.insert(var_ll_i_path);
4022 grp_cv_paths.insert(var_ll_i_path);
4023 grp_cv_paths.insert(var_ll_j_path);
4029 if(var_ll_j_path.compare(0,var_ll_i_path.size(),var_ll_i_path)==0) {
4030 var_share_dims[j] =
true;
4031 grp_cv_paths.insert(var_ll_j_path);
4034 var_share_dims[i] =
true;
4035 var_share_dims[j] =
true;
4037 grp_cv_paths.insert(var_ll_i_path);
4038 grp_cv_paths.insert(var_ll_j_path);
4048 for(
auto itv = var_ll.begin(); itv!= var_ll.end();) {
4049 if(
true == var_share_dims[var_index]) {
4050 latlon2d_path_to_index.erase((*itv)->fullpath);
4052 itv = var_ll.erase(itv);
4063void GMFile::Remove_2DLLCVar_Final_Candidate_from_Vars(vector<int> &var2d_index) {
4065 BESDEBUG(
"h5",
"Coming to Remove_2DLLCVar_Final_Candidate_from_Vars()"<<endl);
4067 sort(var2d_index.begin(),var2d_index.end());
4068 auto it = this->
vars.begin();
4074 for (
unsigned int i = 0; i <var2d_index.size();i++) {
4076 advance(it,var2d_index[i]);
4078 advance(it,var2d_index[i]-var2d_index[i-1]-1);
4080 if(it == this->
vars.end())
4081 throw1(
"Out of range to obtain 2D lat/lon variables");
4084 it = this->
vars.erase(it);
4092bool GMFile::Check_Var_2D_CVars(
Var *var) {
4094 BESDEBUG(
"h5",
"Coming to Check_Var_2D_CVars()"<<endl);
4095 bool ret_value =
true;
4096 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
4097 if((*ircv)->rank==2) {
4098 short first_dim_index = 0;
4099 short first_dim_times = 0;
4100 short second_dim_index = 0;
4101 short second_dim_times = 0;
4102 for (
auto ird = var->dims.begin(); ird != var->dims.end(); ++ird) {
4103 if((*ird)->name == ((*ircv)->getDimensions()[0])->name) {
4104 first_dim_index = distance(var->dims.begin(),ird);
4107 else if((*ird)->name == ((*ircv)->getDimensions()[1])->name) {
4108 second_dim_index = distance(var->dims.begin(),ird);
4114 if(first_dim_times == 1 && second_dim_times == 1) {
4115 if(first_dim_index < second_dim_index) {
4128bool GMFile::Flatten_VarPath_In_Coordinates_Attr(
Var *var) {
4130 BESDEBUG(
"h5",
"Coming to Flatten_VarPath_In_Coordinates_Attr()"<<endl);
4131 string co_attrname =
"coordinates";
4132 bool need_flatten_coor_attr =
false;
4133 string orig_coor_value;
4134 string flatten_coor_value;
4137 char backslash =
'/';
4139 for (
auto ira =var->attrs.begin(); ira !=var->attrs.end();) {
4149 if((*ira)->name == co_attrname) {
4150 Retrieve_H5_Attr_Value((*ira),var->fullpath);
4151 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
4152 if(orig_attr_value.find_first_of(backslash)!=string::npos){
4153 orig_coor_value = orig_attr_value;
4154 need_flatten_coor_attr =
true;
4156 ira = var->attrs.erase(ira);
4164 if(
true == need_flatten_coor_attr) {
4167 size_t ele_start_pos = 0;
4168 size_t cur_pos = orig_coor_value.find_first_of(sc);
4169 while(cur_pos !=string::npos) {
4170 string tempstr = orig_coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
4171 tempstr = get_CF_string(tempstr);
4172 flatten_coor_value += tempstr + sc;
4173 ele_start_pos = cur_pos+1;
4174 cur_pos = orig_coor_value.find_first_of(sc,cur_pos+1);
4177 if(ele_start_pos == 0)
4178 flatten_coor_value = get_CF_string(orig_coor_value);
4180 flatten_coor_value += get_CF_string(orig_coor_value.substr(ele_start_pos));
4184 Add_Str_Attr(attr,co_attrname,flatten_coor_value);
4185 var->attrs.push_back(attr);
4186 var->coord_attr_add_path =
false;
4197bool GMFile::Flatten_VarPath_In_Coordinates_Attr_EOS5(
Var *var) {
4199 BESDEBUG(
"h5",
"Coming to Flatten_VarPath_In_Coordinates_Attr_EOS5()"<<endl);
4200 string co_attrname =
"coordinates";
4201 bool has_coor_attr =
false;
4202 string orig_coor_value;
4203 string flatten_coor_value;
4207 for (
auto ira =var->attrs.begin(); ira !=var->attrs.end();) {
4211 if((*ira)->name == co_attrname) {
4212 Retrieve_H5_Attr_Value((*ira),var->fullpath);
4214 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
4215 orig_coor_value = orig_attr_value;
4216 has_coor_attr =
true;
4218 ira = var->attrs.erase(ira);
4225 if(
true == has_coor_attr) {
4229 size_t ele_start_pos = 0;
4231 size_t cur_pos = orig_coor_value.find_first_of(sc);
4232 while(cur_pos !=string::npos) {
4233 string tempstr = orig_coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
4236 tempstr = get_CF_string(tempstr);
4237 flatten_coor_value += tempstr + sc;
4238 ele_start_pos = cur_pos+1;
4239 cur_pos = orig_coor_value.find_first_of(sc,cur_pos+1);
4242 if(ele_start_pos == 0) {
4245 flatten_coor_value = get_CF_string(tempstr);
4248 flatten_coor_value += get_CF_string(orig_coor_value.substr(ele_start_pos));
4252 Add_Str_Attr(attr,co_attrname,flatten_coor_value);
4253 var->attrs.push_back(attr);
4265bool GMFile::Check_2DLatLon_Dimscale(
string & latname,
string &lonname) {
4283 bool latlon_2d_cv_check1 =
false;
4286 latlon_2d_cv_check1 =
true;
4289 for (
auto ircv = this->cvars.begin();
4290 ircv != this->cvars.end(); ++ircv) {
4291 if((*ircv)->cvartype == CV_FILLINDEX){
4292 latlon_2d_cv_check1 =
true;
4298 bool latlon_2d_cv_check2 =
true;
4301 if(
true == latlon_2d_cv_check1) {
4302 BESDEBUG(
"h5",
"Coming to check if having 2d latlon coordinates for a netCDF-4 like product. "<<endl);
4305 for (
auto ircv = this->cvars.begin();
4306 ircv != this->cvars.end(); ++ircv) {
4307 if((*ircv)->cvartype == CV_EXIST) {
4308 for(
auto ira = (*ircv)->attrs.begin();
4309 ira != (*ircv)->attrs.end();ira++) {
4310 string attr_name =
"units";
4311 string lat_unit_value =
"degrees_north";
4312 string lon_unit_value =
"degrees_east";
4315 if((
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) ||
4316 (
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value))) {
4317 latlon_2d_cv_check2=
false;
4323 if(
false == latlon_2d_cv_check2)
4328 bool latlon_2d_cv_check3 =
true;
4331 if(
true == latlon_2d_cv_check1 &&
true == latlon_2d_cv_check2) {
4333 short latlon_flag = 0;
4334 short LatLon_flag = 0;
4335 short latilong_flag = 0;
4337 for (
auto ircv = this->cvars.begin();
4338 ircv != this->cvars.end(); ++ircv) {
4339 if((*ircv)->cvartype == CV_EXIST) {
4340 if((*ircv)->name ==
"lat")
4342 else if((*ircv)->name ==
"lon")
4344 else if((*ircv)->name ==
"latitude")
4346 else if((*ircv)->name ==
"longitude")
4348 else if((*ircv)->name ==
"Latitude")
4350 else if((*ircv)->name ==
"Longitude")
4355 if((2== latlon_flag) || (2 == latilong_flag) || (2 == LatLon_flag ))
4356 latlon_2d_cv_check3 =
false;
4359 bool latlon_2d =
false;
4360 short latlon_flag = 0;
4361 string latdim1,latdim2,londim1,londim2;
4363 short LatLon_flag = 0;
4364 string Latdim1,Latdim2,Londim1,Londim2;
4366 short latilong_flag = 0;
4367 string latidim1,latidim2,longdim1,longdim2;
4374 if(
true == latlon_2d_cv_check1 &&
true == latlon_2d_cv_check2 &&
true == latlon_2d_cv_check3) {
4376 for (
auto irv = this->
vars.begin();
4377 irv != this->vars.end(); ++irv) {
4380 if((*irv)->rank == 2) {
4381 if((*irv)->name ==
"lat") {
4383 latdim1 = (*irv)->getDimensions()[0]->name;
4384 latdim2 = (*irv)->getDimensions()[1]->name;
4387 else if((*irv)->name ==
"lon") {
4389 londim1 = (*irv)->getDimensions()[0]->name;
4390 londim2 = (*irv)->getDimensions()[1]->name;
4392 else if((*irv)->name ==
"latitude"){
4394 latidim1 = (*irv)->getDimensions()[0]->name;
4395 latidim2 = (*irv)->getDimensions()[1]->name;
4397 else if((*irv)->name ==
"longitude"){
4399 longdim1 = (*irv)->getDimensions()[0]->name;
4400 longdim2 = (*irv)->getDimensions()[1]->name;
4403 else if((*irv)->name ==
"Latitude"){
4405 Latdim1 = (*irv)->getDimensions()[0]->name;
4406 Latdim2 = (*irv)->getDimensions()[1]->name;
4409 else if((*irv)->name ==
"Longitude"){
4411 Londim1 = (*irv)->getDimensions()[0]->name;
4412 Londim2 = (*irv)->getDimensions()[1]->name;
4422 if(2 == latlon_flag) {
4423 if((2 == latilong_flag) || ( 2 == LatLon_flag))
4425 else if((latdim1 == londim1) && (latdim2 == londim2)) {
4431 else if ( 2 == latilong_flag) {
4432 if( 2 == LatLon_flag)
4434 else if ((latidim1 == longdim1) ||(latidim2 == longdim2)) {
4435 latname =
"latitude";
4436 lonname =
"longitude";
4440 else if (2 == LatLon_flag){
4441 if ((Latdim1 == Londim1) ||(Latdim2 == Londim2)) {
4442 latname =
"Latitude";
4443 lonname =
"Longitude";
4454void GMFile::Update_2DLatLon_Dimscale_CV(
const string &latname,
const string &lonname) {
4459 for (
auto irv = this->
vars.begin();
4460 irv != this->vars.end(); ++irv) {
4462 if((*irv)->rank == 2) {
4465 if((*irv)->name == latname) {
4468 string latdim0 = (*irv)->getDimensions()[0]->name;
4472 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ) {
4473 if((*i)->cfdimname == latdim0) {
4474 if(CV_FILLINDEX == (*i)->cvartype) {
4476 i = this->cvars.erase(i);
4478 else if(CV_EXIST == (*i)->cvartype) {
4481 this->
vars.push_back(var);
4484 i = this->cvars.erase(i);
4488 if(CV_LAT_MISS == (*i)->cvartype)
4489 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_LAT_MISS");
4490 else if(CV_LON_MISS == (*i)->cvartype)
4491 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_LON_MISS");
4492 else if(CV_NONLATLON_MISS == (*i)->cvartype)
4493 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_NONLATLON_MISS");
4494 else if(CV_MODIFY == (*i)->cvartype)
4495 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_MODIFY");
4496 else if(CV_SPECIAL == (*i)->cvartype)
4497 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_SPECIAL");
4499 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_UNSUPPORTED");
4508 GMcvar->cfdimname = latdim0;
4509 GMcvar->cvartype = CV_EXIST;
4510 GMcvar->product_type = product_type;
4511 this->cvars.push_back(GMcvar);
4513 this->
vars.erase(irv);
4520 for (
auto irv = this->
vars.begin();
4521 irv != this->vars.end(); ++irv) {
4523 if((*irv)->rank == 2) {
4526 if((*irv)->name == lonname) {
4529 string londim0 = (*irv)->getDimensions()[1]->name;
4532 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ) {
4534 if((*i)->cfdimname == londim0) {
4535 if(CV_FILLINDEX == (*i)->cvartype) {
4537 i= this->cvars.erase(i);
4539 else if(CV_EXIST == (*i)->cvartype) {
4542 this->
vars.push_back(var);
4545 i = this->cvars.erase(i);
4548 if(CV_LAT_MISS == (*i)->cvartype)
4549 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_LAT_MISS");
4550 else if(CV_LON_MISS == (*i)->cvartype)
4551 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_LON_MISS");
4552 else if(CV_NONLATLON_MISS == (*i)->cvartype)
4553 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_NONLATLON_MISS");
4554 else if(CV_MODIFY == (*i)->cvartype)
4555 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_MODIFY");
4556 else if(CV_SPECIAL == (*i)->cvartype)
4557 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_SPECIAL");
4559 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_UNSUPPORTED");
4568 GMcvar->cfdimname = londim0;
4569 GMcvar->cvartype = CV_EXIST;
4570 GMcvar->product_type = product_type;
4571 this->cvars.push_back(GMcvar);
4573 this->
vars.erase(irv);
4582void GMFile::Handle_CVar_LatLon1D_General_Product() {
4584 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon1D_General_Product()"<<endl);
4585 this->iscoard =
true;
4586 Handle_CVar_LatLon_General_Product();
4591void GMFile::Handle_CVar_LatLon2D_General_Product() {
4593 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon2D_General_Product()"<<endl);
4594 Handle_CVar_LatLon_General_Product();
4600void GMFile::Handle_CVar_LatLon_General_Product() {
4602 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon_General_Product()"<<endl);
4603 if((GENERAL_LATLON2D != this->gproduct_pattern)
4604 && GENERAL_LATLON1D != this->gproduct_pattern)
4605 throw1(
"This function only supports latlon 1D or latlon 2D general products");
4607 pair<set<string>::iterator,
bool> setret;
4608 set<string>tempdimnamelist = dimnamelist;
4610 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
4613 if (gp_latname== (*irv)->name) {
4617 tempdimnamelist.erase(((*irv)->dims[0])->name);
4618 auto GMcvar =
new GMCVar(*irv);
4619 GMcvar->cfdimname = ((*irv)->dims[0])->name;
4620 GMcvar->cvartype = CV_EXIST;
4621 GMcvar->product_type = product_type;
4622 this->cvars.push_back(GMcvar);
4624 this->
vars.erase(irv);
4629 for (
auto irv = this->
vars.begin(); irv != this->
vars.end(); ++irv) {
4632 if (gp_lonname== (*irv)->name) {
4638 if(GENERAL_LATLON2D == this->gproduct_pattern)
4639 londimname = ((*irv)->dims[1])->name;
4641 londimname = ((*irv)->dims[0])->name;
4643 tempdimnamelist.erase(londimname);
4644 auto GMcvar =
new GMCVar(*irv);
4645 GMcvar->cfdimname = londimname;
4646 GMcvar->cvartype = CV_EXIST;
4647 GMcvar->product_type = product_type;
4648 this->cvars.push_back(GMcvar);
4650 this->
vars.erase(irv);
4657 for (
auto irs = tempdimnamelist.begin(); irs != tempdimnamelist.end();irs++) {
4658 auto GMcvar =
new GMCVar();
4659 Create_Missing_CV(GMcvar,*irs);
4660 this->cvars.push_back(GMcvar);
4666void GMFile::Handle_CVar_OBPG_L3() {
4668 BESDEBUG(
"h5",
"Coming to Handle_CVar_OBPG_L3()"<<endl);
4669 if (GENERAL_DIMSCALE == this->gproduct_pattern)
4670 Handle_CVar_Dimscale_General_Product();
4673 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
4680 if((*irv)->rank == 2) {
4682 if(((*irv)->fullpath.find(
"/geophsical_data") == 0) || ((*irv)->dtype == H5FLOAT32)) {
4684 size_t lat_size = (*irv)->getDimensions()[0]->size;
4685 string lat_name = (*irv)->getDimensions()[0]->name;
4686 size_t lon_size = (*irv)->getDimensions()[1]->size;
4687 string lon_name = (*irv)->getDimensions()[1]->name;
4688 size_t temp_size = 0;
4690 H5DataType ll_dtype = (*irv)->dtype;
4693 if(lat_size >lon_size) {
4694 temp_size = lon_size;
4695 temp_name = lon_name;
4696 lon_size = lat_size;
4697 lon_name = lat_name;
4698 lat_size = temp_size;
4699 lat_name = temp_name;
4701 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
4702 if((*ircv)->cvartype == CV_FILLINDEX) {
4703 if((*ircv)->getDimensions()[0]->size == lat_size &&
4704 (*ircv)->getDimensions()[0]->name == lat_name) {
4705 (*ircv)->cvartype = CV_LAT_MISS;
4706 (*ircv)->dtype = ll_dtype;
4707 for (
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end(); ++ira) {
4708 if ((*ira)->name ==
"NAME") {
4710 (*ircv)->attrs.erase(ira);
4715 else if((*ircv)->getDimensions()[0]->size == lon_size &&
4716 (*ircv)->getDimensions()[0]->name == lon_name) {
4717 (*ircv)->cvartype = CV_LON_MISS;
4718 (*ircv)->dtype = ll_dtype;
4719 for (
auto ira = (*ircv)->attrs.begin(); ira != (*ircv)->attrs.end(); ++ira) {
4720 if ((*ira)->name ==
"NAME") {
4722 (*ircv)->attrs.erase(ira);
4740 BESDEBUG(
"h5",
"Coming to Handle_SpVar()"<<endl);
4741 if (ACOS_L2S_OR_OCO2_L1B == product_type)
4742 Handle_SpVar_ACOS_OCO2();
4743 else if(GPM_L1 == product_type) {
4746 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
4747 if((*irv)->name==
"AlgorithmRuntimeInfo") {
4749 this->
vars.erase(irv);
4756 else if(GPMM_L3 == product_type || GPMS_L3 == product_type || GPM_L3_New==product_type) {
4758 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
4759 if((*irv)->name==
"InputFileNames") {
4761 irv = this->
vars.erase(irv);
4763 else if((*irv)->name==
"InputAlgorithmVersions") {
4765 irv = this->
vars.erase(irv);
4767 else if((*irv)->name==
"InputGenerationDateTimes") {
4769 irv = this->
vars.erase(irv);
4780void GMFile::Handle_SpVar_ACOS_OCO2() {
4782 BESDEBUG(
"h5",
"Coming to Handle_SpVar_ACOS_OCO2()"<<endl);
4785 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ) {
4787 if (H5INT64 == (*irv)->getType()) {
4790 auto spvar =
new GMSPVar(*irv);
4791 spvar->name = (*irv)->name +
"_Time";
4792 spvar->newname = (*irv)->newname+
"_Time";
4793 spvar->dtype = H5INT32;
4794 spvar->otype = (*irv)->getType();
4798 spvar->numofdbits = 6;
4799 this->spvars.push_back(spvar);
4802 auto spvar2 =
new GMSPVar(*irv);
4803 spvar2->name = (*irv)->name +
"_Date";
4804 spvar2->newname = (*irv)->newname+
"_Date";
4805 spvar2->dtype = H5INT32;
4806 spvar2->otype = (*irv)->getType();
4810 spvar2->numofdbits = 8;
4811 this->spvars.push_back(spvar2);
4814 irv = this->
vars.erase(irv);
4826 BESDEBUG(
"h5",
"Coming to Adjust_Obj_Name()"<<endl);
4827 if(Mea_Ozone == product_type)
4828 Adjust_Mea_Ozone_Obj_Name();
4830 if(GPMS_L3 == product_type || GPMM_L3 == product_type)
4831 Adjust_GPM_L3_Obj_Name();
4835for (
auto irv2 = this->
vars.begin();
4836 irv2 != this->vars.end(); irv2++) {
4837 for (
auto ird = (*irv2)->dims.begin();
4838 ird !=(*irv2)->dims.end(); ird++) {
4839 cerr<<
"Dimension name afet Adjust_Obj_Name "<<(*ird)->newname <<endl;
4847void GMFile:: Adjust_GPM_L3_Obj_Name() {
4849 BESDEBUG(
"h5",
"Coming to Adjust_GPM_L3_Obj_Name()"<<endl);
4852 if(this->
groups.size() <= 1) {
4853 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
4854 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4855 if (objnewname !=
"")
4856 (*irv)->newname = objnewname;
4860 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
4861 size_t grid_group_path_pos = ((*irv)->newname.substr(1)).find_first_of(
"/");
4862 objnewname = ((*irv)->newname).substr(grid_group_path_pos+2);
4863 (*irv)->newname = objnewname;
4869void GMFile:: Adjust_Mea_Ozone_Obj_Name() {
4871 BESDEBUG(
"h5",
"Coming to Adjust_Mea_Ozone_Obj_Name()"<<endl);
4873 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
4874 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4875 if (objnewname !=
"")
4876 (*irv)->newname = objnewname;
4880for (
auto ird = (*irv)->dims.begin();
4881 ird !=(*irv)->dims.end();++ird) {
4882 cerr<<
"Ozone dim. name "<<(*ird)->name <<endl;
4883 cerr<<
"Ozone dim. new name "<<(*ird)->newname <<endl;
4889 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
4890 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4891 if (objnewname !=
"")
4892 (*irv)->newname = objnewname;
4895for (
auto ird = (*irv)->dims.begin();
4896 ird !=(*irv)->dims.end();++ird) {
4897 cerr<<
"Ozone CV dim. name "<<(*ird)->name <<endl;
4898 cerr<<
"Ozone CV dim. new name "<<(*ird)->newname <<endl;
4907 BESDEBUG(
"h5",
"GMFile::Coming to Flatten_Obj_Name()"<<endl);
4912 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
4913 (*irv)->newname = get_CF_string((*irv)->newname);
4915 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird)
4916 (*ird)->newname = get_CF_string((*ird)->newname);
4918 if (
true == include_attr) {
4919 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira)
4920 (*ira)->newname = File::get_CF_string((*ira)->newname);
4926 for (
auto irv = this->spvars.begin(); irv != this->spvars.end(); ++irv) {
4927 (*irv)->newname = get_CF_string((*irv)->newname);
4929 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird)
4930 (*ird)->newname = get_CF_string((*ird)->newname);
4932 if (
true == include_attr) {
4933 for (
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end(); ++ira)
4934 (*ira)->newname = File::get_CF_string((*ira)->newname);
4940for (
auto irv2 = this->
vars.begin();
4941 irv2 != this->vars.end(); irv2++) {
4942 for (
auto ird = (*irv2)->dims.begin();
4943 ird !=(*irv2)->dims.end(); ird++) {
4944 cerr<<
"Dimension name afet Flatten_Obj_Name "<<(*ird)->newname <<endl;
4956 BESDEBUG(
"h5",
"GMFile::Coming to Handle_Obj_NameClashing()"<<endl);
4960 set<string>objnameset;
4961 Handle_GMCVar_NameClashing(objnameset);
4962 Handle_GMSPVar_NameClashing(objnameset);
4963 File::Handle_GeneralObj_NameClashing(include_attr,objnameset);
4964 if (
true == include_attr) {
4965 Handle_GMCVar_AttrNameClashing();
4966 Handle_GMSPVar_AttrNameClashing();
4973void GMFile::Handle_GMCVar_NameClashing(set<string> &objnameset ) {
4975 GMHandle_General_NameClashing(objnameset,this->cvars);
4979void GMFile::Handle_GMSPVar_NameClashing(set<string> &objnameset ) {
4981 GMHandle_General_NameClashing(objnameset,this->spvars);
4985void GMFile::Handle_GMCVar_AttrNameClashing() {
4987 BESDEBUG(
"h5",
"Coming to Handle_GMCVar_AttrNameClashing()"<<endl);
4988 set<string> objnameset;
4990 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
4991 Handle_General_NameClashing(objnameset,(*irv)->attrs);
4997void GMFile::Handle_GMSPVar_AttrNameClashing() {
4999 BESDEBUG(
"h5",
"Coming to Handle_GMSPVar_AttrNameClashing()"<<endl);
5000 set<string> objnameset;
5002 for (
auto irv = this->spvars.begin(); irv != this->spvars.end(); ++irv) {
5003 Handle_General_NameClashing(objnameset,(*irv)->attrs);
5011template<
class T>
void
5012GMFile::GMHandle_General_NameClashing(set <string>&objnameset, vector<T*>& objvec) {
5014 BESDEBUG(
"h5",
"Coming to GMHandle_General_NameClashing()"<<endl);
5015 pair<set<string>::iterator,
bool> setret;
5016 set<string>::iterator iss;
5018 vector<string> clashnamelist;
5020 map<int,int> cl_to_ol;
5024 typename vector<T*>::iterator irv;
5026 for (irv = objvec.begin(); irv != objvec.end(); ++irv) {
5028 setret = objnameset.insert((*irv)->newname);
5029 if (
false == setret.second ) {
5030 clashnamelist.insert(clashnamelist.end(),(*irv)->newname);
5031 cl_to_ol[cl_index] = ol_index;
5040 for (
auto ivs=clashnamelist.begin(); ivs!=clashnamelist.end(); ++ivs) {
5041 int clash_index = 1;
5042 string temp_clashname = *ivs +
'_';
5043 HDF5CFUtil::gen_unique_name(temp_clashname,objnameset,clash_index);
5044 *ivs = temp_clashname;
5049 for (
unsigned int i =0; i <clashnamelist.size(); i++)
5050 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
5058 BESDEBUG(
"h5",
"GMFile: Coming to Handle_DimNameClashing()"<<endl);
5060 if (ACOS_L2S_OR_OCO2_L1B == product_type)
5063 map<string,string>dimname_to_dimnewname;
5064 pair<map<string,string>::iterator,
bool>mapret;
5065 set<string> dimnameset;
5066 vector<Dimension*>vdims;
5067 set<string> dimnewnameset;
5068 pair<set<string>::iterator,
bool> setret;
5071 for (
auto irv = this->cvars.begin(); irv !=this->cvars.end(); ++irv) {
5072 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
5073 setret = dimnameset.insert((*ird)->name);
5074 if (
true == setret.second)
5075 vdims.push_back(*ird);
5082 for(
auto irv= this->
vars.begin(); irv != this->vars.end();++irv) {
5083 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
5087 setret = dimnameset.insert((*ird)->name);
5088 if (setret.second) vdims.push_back(*ird);
5092 GMHandle_General_NameClashing(dimnewnameset,vdims);
5095 for (
auto ird = vdims.begin();ird!=vdims.end();++ird) {
5096 mapret = dimname_to_dimnewname.insert(pair<string,string>((*ird)->name,(*ird)->newname));
5097 if (
false == mapret.second)
5098 throw4(
"The dimension name ",(*ird)->name,
" should map to ",
5103 for (
auto irv = this->cvars.begin(); irv !=this->cvars.end(); ++irv)
5104 for (
auto ird = (*irv)->dims.begin(); ird!=(*irv)->dims.end();++ird)
5105 (*ird)->newname = dimname_to_dimnewname[(*ird)->name];
5107 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv)
5108 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird)
5109 (*ird)->newname = dimname_to_dimnewname[(*ird)->name];
5116 BESDEBUG(
"h5",
"GMFile:Coming to Adjust_Dim_Name()"<<endl);
5119for (
auto irv2 = this->
vars.begin();
5120 irv2 != this->vars.end(); irv2++) {
5121 for (
auto ird = (*irv2)->dims.begin();
5122 ird !=(*irv2)->dims.end(); ird++) {
5123 cerr<<
"Dimension new name "<<(*ird)->newname <<endl;
5129 if(
true == iscoard) {
5130 for (
auto irv = this->cvars.begin(); irv !=this->cvars.end(); ++irv) {
5132cerr<<
"1D Cvariable name is "<<(*irv)->name <<endl;
5133cerr<<
"1D Cvariable new name is "<<(*irv)->newname <<endl;
5134cerr<<
"1D Cvariable dim name is "<<((*irv)->dims)[0]->name <<endl;
5135cerr<<
"1D Cvariable dim new name is "<<((*irv)->dims)[0]->newname <<endl;
5137 if ((*irv)->dims.size()!=1)
5138 throw3(
"Coard coordinate variable ",(*irv)->name,
"is not 1D");
5139 if ((*irv)->newname != (((*irv)->dims)[0]->newname)) {
5140 ((*irv)->dims)[0]->newname = (*irv)->newname;
5143 for (
auto irv2 = this->
vars.begin(); irv2 != this->
vars.end(); ++irv2) {
5144 for (
auto ird = (*irv2)->dims.begin(); ird !=(*irv2)->dims.end(); ++ird) {
5149 if ((*ird)->name == ((*irv)->dims)[0]->name)
5150 (*ird)->newname = ((*irv)->dims)[0]->newname;
5159for (
auto irv2 = this->
vars.begin();
5160 irv2 != this->
vars.end(); irv2++) {
5161 for (
auto ird = (*irv2)->dims.begin();
5162 ird !=(*irv2)->dims.end(); ird++) {
5163 cerr<<
"Dimension name afet Adjust_Dim_Name "<<(*ird)->newname <<endl;
5175 BESDEBUG(
"h5",
"GMFile::Coming to Add_Supplement_Attrs()"<<endl);
5176 if (General_Product == product_type ||
true == add_path) {
5179 if(
true == add_path) {
5181 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
5182 if (((*irv)->cvartype == CV_EXIST) || ((*irv)->cvartype == CV_MODIFY)) {
5184 const string varname = (*irv)->name;
5185 const string attrname =
"origname";
5186 Add_Str_Attr(attr,attrname,varname);
5187 (*irv)->attrs.push_back(attr);
5191 for (
auto irv = this->cvars.begin();
5192 irv != this->cvars.end(); ++irv) {
5196 if((*irv)->zero_storage_size ==
false
5197 || HDF5RequestHandler::get_no_zero_size_fullnameattr() ==
false) {
5198 if (((*irv)->cvartype == CV_EXIST) || ((*irv)->cvartype == CV_MODIFY)) {
5200 const string varname = (*irv)->fullpath;
5201 const string attrname =
"fullnamepath";
5202 Add_Str_Attr(attr,attrname,varname);
5203 (*irv)->attrs.push_back(attr);
5208 for (
auto irv = this->spvars.begin(); irv != this->spvars.end(); ++irv) {
5210 const string varname = (*irv)->name;
5211 const string attrname =
"origname";
5212 Add_Str_Attr(attr,attrname,varname);
5213 (*irv)->attrs.push_back(attr);
5216 for (
auto irv = this->spvars.begin(); irv != this->spvars.end(); ++irv) {
5220 if((*irv)->zero_storage_size ==
false
5221 || HDF5RequestHandler::get_no_zero_size_fullnameattr() ==
false) {
5223 const string varname = (*irv)->fullpath;
5224 const string attrname =
"fullnamepath";
5225 Add_Str_Attr(attr,attrname,varname);
5226 (*irv)->attrs.push_back(attr);
5232 if(GPM_L1 == product_type || GPMS_L3 == product_type || GPMM_L3 == product_type)
5234 else if (Aqu_L3 == product_type)
5236 else if (Mea_SeaWiFS_L2 == product_type || Mea_SeaWiFS_L3 == product_type)
5237 Add_SeaWiFS_Attrs();
5243GMFile:: Add_GPM_Attrs() {
5245 BESDEBUG(
"h5",
"Coming to Add_GPM_Attrs()"<<endl);
5246 vector<HDF5CF::Var *>::const_iterator it_v;
5247 vector<HDF5CF::Attribute *>::const_iterator ira;
5248 const string attr_name_be_replaced =
"CodeMissingValue";
5249 const string attr_new_name =
"_FillValue";
5250 const string attr2_name_be_replaced =
"Units";
5251 const string attr2_new_name =
"units";
5256 for (it_v =
vars.begin(); it_v !=
vars.end(); ++it_v) {
5257 bool has_fvalue_attr =
false;
5258 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5259 if(attr_new_name == (*ira)->name) {
5260 has_fvalue_attr =
true;
5265 if(
false == has_fvalue_attr) {
5266 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5267 if(attr_name_be_replaced == (*ira)->name) {
5268 if((*ira)->dtype == H5FSTRING)
5269 Change_Attr_One_Str_to_Others((*ira),(*it_v));
5270 (*ira)->name = attr_new_name;
5271 (*ira)->newname = attr_new_name;
5279 for (
auto irv = this->cvars.begin();
5280 irv != this->cvars.end(); ++irv) {
5281 bool has_fvalue_attr =
false;
5283 for(ira = (*irv)->attrs.begin(); ira!= (*irv)->attrs.end();ira++) {
5285 if(attr_new_name == (*ira)->name) {
5286 has_fvalue_attr =
true;
5290 if(
false == has_fvalue_attr) {
5291 for(ira = (*irv)->attrs.begin(); ira!= (*irv)->attrs.end();ira++) {
5293 if(attr_name_be_replaced == (*ira)->name) {
5294 if((*ira)->dtype == H5FSTRING)
5295 Change_Attr_One_Str_to_Others((*ira),(*irv));
5296 (*ira)->name = attr_new_name;
5297 (*ira)->newname = attr_new_name;
5304 if(product_type == GPM_L1) {
5306 if ((*irv)->cvartype == CV_EXIST) {
5307 if((*irv)->name.find(
"Latitude") !=string::npos) {
5308 string unit_value =
"degrees_north";
5309 Correct_GPM_L1_LatLon_units(*irv,unit_value);
5312 else if((*irv)->name.find(
"Longitude") !=string::npos) {
5313 string unit_value =
"degrees_east";
5314 Correct_GPM_L1_LatLon_units(*irv,unit_value);
5319 else if ((*irv)->cvartype == CV_NONLATLON_MISS) {
5322 const string attrname =
"comment";
5326 if((*irv)->name ==
"nchannel1")
5327 comment =
"Number of Swath S1 channels (10V 10H 19V 19H 23V 37V 37H 89V 89H).";
5328 else if((*irv)->name ==
"nchannel2")
5329 comment =
"Number of Swath S2 channels (166V 166H 183+/-3V 183+/-8V).";
5330 else if((*irv)->name ==
"nchan1")
5331 comment =
"Number of channels in Swath 1.";
5332 else if((*irv)->name ==
"nchan2")
5333 comment =
"Number of channels in Swath 2.";
5334 else if((*irv)->name ==
"VH")
5335 comment =
"Number of polarizations.";
5336 else if((*irv)->name ==
"GMIxyz")
5337 comment =
"x, y, z components in GMI instrument coordinate system.";
5338 else if((*irv)->name ==
"LNL")
5339 comment =
"Linear and non-linear.";
5340 else if((*irv)->name ==
"nscan")
5341 comment =
"Number of scans in the granule.";
5342 else if((*irv)->name ==
"nscan1")
5343 comment =
"Typical number of Swath S1 scans in the granule.";
5344 else if((*irv)->name ==
"nscan2")
5345 comment =
"Typical number of Swath S2 scans in the granule.";
5346 else if((*irv)->name ==
"npixelev")
5347 comment =
"Number of earth view pixels in one scan.";
5348 else if((*irv)->name ==
"npixelht")
5349 comment =
"Number of hot load pixels in one scan.";
5350 else if((*irv)->name ==
"npixelcs")
5351 comment =
"Number of cold sky pixels in one scan.";
5352 else if((*irv)->name ==
"npixelfr")
5353 comment =
"Number of full rotation earth view pixels in one scan.";
5354 else if((*irv)->name ==
"nfreq1")
5355 comment =
"Number of frequencies in Swath 1.";
5356 else if((*irv)->name ==
"nfreq2")
5357 comment =
"Number of frequencies in Swath 2.";
5358 else if((*irv)->name ==
"npix1")
5359 comment =
"Number of pixels in Swath 1.";
5360 else if((*irv)->name ==
"npix2")
5361 comment =
"Number of pixels in Swath 2.";
5362 else if((*irv)->name ==
"npix3")
5363 comment =
"Number of pixels in Swath 3.";
5364 else if((*irv)->name ==
"npix4")
5365 comment =
"Number of pixels in Swath 4.";
5366 else if((*irv)->name ==
"ncolds1")
5367 comment =
"Maximum number of cold samples in Swath 1.";
5368 else if((*irv)->name ==
"ncolds2")
5369 comment =
"Maximum number of cold samples in Swath 2.";
5370 else if((*irv)->name ==
"nhots1")
5371 comment =
"Maximum number of hot samples in Swath 1.";
5372 else if((*irv)->name ==
"nhots2")
5373 comment =
"Maximum number of hot samples in Swath 2.";
5374 else if((*irv)->name ==
"ntherm")
5375 comment =
"Number of hot load thermisters.";
5376 else if((*irv)->name ==
"ntach")
5377 comment =
"Number of tachometer readings.";
5378 else if((*irv)->name ==
"nsamt"){
5379 comment =
"Number of sample types. ";
5380 comment = +
"The types are: total science GSDR, earthview,hot load, cold sky.";
5382 else if((*irv)->name ==
"nndiode")
5383 comment =
"Number of noise diodes.";
5384 else if((*irv)->name ==
"n7")
5385 comment =
"Number seven.";
5386 else if((*irv)->name ==
"nray")
5387 comment =
"Number of angle bins in each NS scan.";
5388 else if((*irv)->name ==
"nrayMS")
5389 comment =
"Number of angle bins in each MS scan.";
5390 else if((*irv)->name ==
"nrayHS")
5391 comment =
"Number of angle bins in each HS scan.";
5392 else if((*irv)->name ==
"nbin")
5393 comment =
"Number of range bins in each NS and MS ray. Bin interval is 125m.";
5394 else if((*irv)->name ==
"nbinHS")
5395 comment =
"Number of range bins in each HS ray. Bin interval is 250m.";
5396 else if((*irv)->name ==
"nbinSZP")
5397 comment =
"Number of range bins for sigmaZeroProfile.";
5398 else if((*irv)->name ==
"nbinSZPHS")
5399 comment =
"Number of range bins for sigmaZeroProfile in each HS scan.";
5400 else if((*irv)->name ==
"nNP")
5401 comment =
"Number of NP kinds.";
5402 else if((*irv)->name ==
"nearFar")
5403 comment =
"Near reference, Far reference.";
5404 else if((*irv)->name ==
"foreBack")
5405 comment =
"Forward, Backward.";
5406 else if((*irv)->name ==
"method")
5407 comment =
"Number of SRT methods.";
5408 else if((*irv)->name ==
"nNode")
5409 comment =
"Number of binNode.";
5410 else if((*irv)->name ==
"nDSD")
5411 comment =
"Number of DSD parameters. Parameters are N0 and D0";
5412 else if((*irv)->name ==
"LS")
5413 comment =
"Liquid, solid.";
5419 Add_Str_Attr(attr,attrname,comment);
5420 (*irv)->attrs.push_back(attr);
5426 if(product_type == GPMS_L3 || product_type == GPMM_L3) {
5427 if ((*irv)->cvartype == CV_NONLATLON_MISS) {
5430 const string attrname =
"comment";
5434 if((*irv)->name ==
"chn")
5435 comment =
"Number of channels:Ku,Ka,KaHS,DPR.";
5436 else if((*irv)->name ==
"inst")
5437 comment =
"Number of instruments:Ku,Ka,KaHS.";
5438 else if((*irv)->name ==
"tim")
5439 comment =
"Number of hours(local time).";
5440 else if((*irv)->name ==
"ang"){
5441 comment =
"Number of angles.The meaning of ang is different for each channel.";
5443 "For Ku channel all indices are used with the meaning 0,1,2,..6 =angle bins 24,";
5445 "(20,28),(16,32),(12,36),(8,40),(3,44),and (0,48).";
5447 "For Ka channel 4 indices are used with the meaning 0,1,2,3 = angle bins 12,(8,16),";
5449 "(4,20),and (0,24). For KaHS channel 4 indices are used with the meaning 0,1,2,3 =";
5450 comment +=
"angle bins(11,2),(7,16),(3,20),and (0.23).";
5453 else if((*irv)->name ==
"rt")
5454 comment =
"Number of rain types: stratiform, convective,all.";
5455 else if((*irv)->name ==
"st")
5456 comment =
"Number of surface types:ocean,land,all.";
5457 else if((*irv)->name ==
"bin"){
5458 comment =
"Number of bins in histogram. The thresholds are different for different";
5459 comment +=
" variables. see the file specification for this algorithm.";
5461 else if((*irv)->name ==
"nvar") {
5462 comment =
"Number of phase bins. Bins are counts of phase less than 100, ";
5463 comment +=
"counts of phase greater than or equal to 100 and less than 200, ";
5464 comment +=
"counts of phase greater than or equal to 200.";
5466 else if((*irv)->name ==
"AD")
5467 comment =
"Ascending or descending half of the orbit.";
5473 Add_Str_Attr(attr,attrname,comment);
5474 (*irv)->attrs.push_back(attr);
5481 if ((*irv)->cvartype == CV_SPECIAL) {
5482 if((*irv)->name ==
"nlayer" || (*irv)->name ==
"hgt"
5483 || (*irv)->name ==
"nalt") {
5485 string unit_value =
"km";
5486 Add_Str_Attr(attr,attr2_new_name,unit_value);
5487 (*irv)->attrs.push_back(attr);
5490 string attr1_axis=
"axis";
5491 string attr1_value =
"Z";
5492 Add_Str_Attr(attr1,attr1_axis,attr1_value);
5493 (*irv)->attrs.push_back(attr1);
5496 string attr2_positive=
"positive";
5497 string attr2_value =
"up";
5498 Add_Str_Attr(attr2,attr2_positive,attr2_value);
5499 (*irv)->attrs.push_back(attr2);
5502 if((*irv)->name ==
"hgt" || (*irv)->name ==
"nalt"){
5504 string comment =
"Number of heights above the earth ellipsoid";
5505 Add_Str_Attr(attr1,
"comment",comment);
5506 (*irv)->attrs.push_back(attr1);
5516 const string fill_value_attr_name =
"_FillValue";
5517 vector<HDF5CF::Var *>::const_iterator it_v;
5518 vector<HDF5CF::Attribute *>::const_iterator ira;
5520 for (it_v =
vars.begin();
5521 it_v !=
vars.end(); ++it_v) {
5523 bool has_fillvalue =
false;
5524 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5525 if (fill_value_attr_name == (*ira)->name){
5526 has_fillvalue =
true;
5533 if (has_fillvalue !=
true ) {
5535 if(H5FLOAT32 == (*it_v)->dtype) {
5537 float _FillValue = -9999.9;
5538 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5539 (*it_v)->attrs.push_back(attr);
5549GMFile:: Correct_GPM_L1_LatLon_units(
Var *var,
const string unit_value) {
5551 BESDEBUG(
"h5",
"Coming to Correct_GPM_L1_LatLon_units()"<<endl);
5552 const string Unit_name =
"Units";
5553 const string unit_name =
"units";
5556 for(
auto ira = var->attrs.begin(); ira!= var->attrs.end();) {
5557 if(unit_name == (*ira)->name) {
5559 ira = var->attrs.erase(ira);
5561 else if(Unit_name == (*ira)->name) {
5563 ira = var->attrs.erase(ira);
5572 Add_Str_Attr(attr,unit_name,unit_value);
5573 var->attrs.push_back(attr);
5580GMFile:: Add_Aqu_Attrs() {
5582 BESDEBUG(
"h5",
"Coming to Add_Aqu_Attrs()"<<endl);
5583 vector<HDF5CF::Var *>::const_iterator it_v;
5584 vector<HDF5CF::Attribute *>::const_iterator ira;
5586 const string orig_longname_attr_name =
"Parameter";
5587 const string longname_attr_name =
"long_name";
5588 string longname_value;
5591 const string orig_units_attr_name =
"Units";
5592 const string units_attr_name =
"units";
5595 const string orig_valid_min_attr_name =
"Data Minimum";
5596 const string valid_min_attr_name =
"valid_min";
5597 float valid_min_value = 0;
5599 const string orig_valid_max_attr_name =
"Data Maximum";
5600 const string valid_max_attr_name =
"valid_max";
5601 float valid_max_value = 0;
5606 const string fill_value_attr_name =
"_FillValue";
5607 float _FillValue = -32767.0;
5609 for (ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
5610 if (orig_longname_attr_name == (*ira)->name) {
5611 Retrieve_H5_Attr_Value(*ira,
"/");
5612 longname_value.resize((*ira)->value.size());
5613 copy((*ira)->value.begin(),(*ira)->value.end(),longname_value.begin());
5616 else if (orig_units_attr_name == (*ira)->name) {
5617 Retrieve_H5_Attr_Value(*ira,
"/");
5618 units_value.resize((*ira)->value.size());
5619 copy((*ira)->value.begin(),(*ira)->value.end(),units_value.begin());
5622 else if (orig_valid_min_attr_name == (*ira)->name) {
5623 Retrieve_H5_Attr_Value(*ira,
"/");
5624 memcpy(&valid_min_value,(
void*)(&((*ira)->value[0])),(*ira)->value.size());
5627 else if (orig_valid_max_attr_name == (*ira)->name) {
5628 Retrieve_H5_Attr_Value(*ira,
"/");
5629 memcpy(&valid_max_value,(
void*)(&((*ira)->value[0])),(*ira)->value.size());
5636 bool has_long_name =
false;
5637 bool has_units =
false;
5638 bool has_valid_min =
false;
5639 bool has_valid_max =
false;
5640 bool has_fillvalue =
false;
5642 for (it_v =
vars.begin(); it_v !=
vars.end(); ++it_v) {
5643 if (
"l3m_data" == (*it_v)->name) {
5644 for (ira = (*it_v)->attrs.begin(); ira != (*it_v)->attrs.end(); ++ira) {
5645 if (longname_attr_name == (*ira)->name)
5646 has_long_name =
true;
5647 else if(units_attr_name == (*ira)->name)
5649 else if(valid_min_attr_name == (*ira)->name)
5650 has_valid_min =
true;
5651 else if(valid_max_attr_name == (*ira)->name)
5652 has_valid_max =
true;
5653 else if(fill_value_attr_name == (*ira)->name)
5654 has_fillvalue =
true;
5662 for (it_v =
vars.begin(); it_v !=
vars.end(); ++it_v) {
5663 if (
"l3m_data" == (*it_v)->name) {
5667 if(
false == has_long_name) {
5669 Add_Str_Attr(attr,longname_attr_name,longname_value);
5670 (*it_v)->attrs.push_back(attr);
5674 if(
false == has_units) {
5676 Add_Str_Attr(attr,units_attr_name,units_value);
5677 (*it_v)->attrs.push_back(attr);
5681 if(
false == has_valid_min) {
5683 Add_One_Float_Attr(attr,valid_min_attr_name,valid_min_value);
5684 (*it_v)->attrs.push_back(attr);
5688 if(
false == has_valid_max) {
5690 Add_One_Float_Attr(attr,valid_max_attr_name,valid_max_value);
5691 (*it_v)->attrs.push_back(attr);
5695 if(
false == has_fillvalue) {
5697 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5698 (*it_v)->attrs.push_back(attr);
5708GMFile:: Add_SeaWiFS_Attrs() {
5710 BESDEBUG(
"h5",
"Coming to Add_SeaWiFS_Attrs()"<<endl);
5713 const string fill_value_attr_name =
"_FillValue";
5714 float _FillValue = -999.0;
5715 const string valid_range_attr_name =
"valid_range";
5716 vector<HDF5CF::Var *>::const_iterator it_v;
5717 vector<HDF5CF::Attribute *>::const_iterator ira;
5720 for (it_v =
vars.begin(); it_v !=
vars.end(); ++it_v) {
5721 if (H5FLOAT32 == (*it_v)->dtype) {
5722 bool has_fillvalue =
false;
5723 bool has_validrange =
false;
5724 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5725 if (fill_value_attr_name == (*ira)->name){
5726 has_fillvalue =
true;
5730 else if(valid_range_attr_name == (*ira)->name) {
5731 has_validrange =
true;
5737 if (has_fillvalue !=
true && has_validrange !=
true ) {
5739 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5740 (*it_v)->attrs.push_back(attr);
5751 string co_attrname =
"coordinates";
5752 string co_attrvalue=
"";
5753 string unit_attrname =
"units";
5754 string nonll_unit_attrvalue =
"level";
5755 string lat_unit_attrvalue =
"degrees_north";
5756 string lon_unit_attrvalue =
"degrees_east";
5758 for (
auto ircv = this->cvars.begin();
5759 ircv != this->cvars.end(); ++ircv) {
5762 if ((*ircv)->cvartype == CV_NONLATLON_MISS) {
5764 Add_Str_Attr(attr,unit_attrname,nonll_unit_attrvalue);
5765 (*ircv)->attrs.push_back(attr);
5768 else if ((*ircv)->cvartype == CV_LAT_MISS) {
5773 Add_Str_Attr(attr,unit_attrname,lat_unit_attrvalue);
5774 (*ircv)->attrs.push_back(attr);
5778 else if ((*ircv)->cvartype == CV_LON_MISS) {
5780 Add_Str_Attr(attr,unit_attrname,lon_unit_attrvalue);
5781 (*ircv)->attrs.push_back(attr);
5786 if(product_type == Mea_SeaWiFS_L2)
5790 else if(product_type == GPM_L1) {
5791 Handle_GPM_l1_Coor_Attr();
5795 else if (
true == iscoard) {
5802 for (
auto ircv = this->cvars.begin();
5803 ircv != this->cvars.end(); ++ircv) {
5804 if((*ircv)->rank == 2) {
5807 if(gp_latname == (*ircv)->name)
5808 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5809 else if(gp_lonname ==(*ircv)->name)
5810 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5815 string ll2d_dimname0,ll2d_dimname1;
5816 bool has_ll2d_coords =
false;
5817 for (
auto ircv = this->cvars.begin();
5818 ircv != this->cvars.end(); ++ircv) {
5819 if((*ircv)->rank == 2) {
5821 ll2d_dimname0 = (*ircv)->getDimensions()[0]->name;
5822 ll2d_dimname1 = (*ircv)->getDimensions()[1]->name;
5823 if(ll2d_dimname0 !=
"" && ll2d_dimname1 !=
"")
5824 has_ll2d_coords =
true;
5829 if(
true == has_ll2d_coords) {
5831 for (
auto irv = this->
vars.begin();
5832 irv != this->vars.end(); ++irv) {
5834 bool coor_attr_keep_exist =
false;
5837 if(((*irv)->rank >=2)) {
5839 short ll2dim_flag = 0;
5840 for (
auto ird = (*irv)->dims.begin();
5841 ird != (*irv)->dims.end(); ++ ird) {
5842 if((*ird)->name == ll2d_dimname0)
5844 else if((*ird)->name == ll2d_dimname1)
5848 if(ll2dim_flag != 2)
5849 coor_attr_keep_exist =
true;
5852 if(product_type == OSMAPL2S)
5853 coor_attr_keep_exist =
true;
5855 if (
false == coor_attr_keep_exist) {
5856 for (
auto ira =(*irv)->attrs.begin();
5857 ira !=(*irv)->attrs.end();) {
5858 if ((*ira)->newname == co_attrname) {
5860 ira = (*irv)->attrs.erase(ira);
5868 for (
auto ird = (*irv)->dims.begin();
5869 ird != (*irv)->dims.end(); ++ ird) {
5870 for (
auto ircv = this->cvars.begin();
5871 ircv != this->cvars.end(); ++ircv) {
5872 if ((*ird)->name == (*ircv)->cfdimname)
5873 co_attrvalue = (co_attrvalue.empty())
5874 ?(*ircv)->newname:co_attrvalue +
" "+(*ircv)->newname;
5878 if (
false == co_attrvalue.empty()) {
5880 Add_Str_Attr(attr,co_attrname,co_attrvalue);
5881 (*irv)->attrs.push_back(attr);
5884 co_attrvalue.clear();
5896 BESDEBUG(
"h5",
"GMFile::Coming to Handle_Coor_Attr()"<<endl);
5897 string co_attrname =
"coordinates";
5898 string co_attrvalue=
"";
5899 string unit_attrname =
"units";
5900 string nonll_unit_attrvalue =
"level";
5901 string lat_unit_attrvalue =
"degrees_north";
5902 string lon_unit_attrvalue =
"degrees_east";
5906 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
5908 if ((*ircv)->cvartype == CV_NONLATLON_MISS) {
5910 Add_Str_Attr(attr,unit_attrname,nonll_unit_attrvalue);
5911 (*ircv)->attrs.push_back(attr);
5913 else if ((*ircv)->cvartype == CV_LAT_MISS) {
5915 Add_Str_Attr(attr,unit_attrname,lat_unit_attrvalue);
5916 (*ircv)->attrs.push_back(attr);
5918 else if ((*ircv)->cvartype == CV_LON_MISS) {
5920 Add_Str_Attr(attr,unit_attrname,lon_unit_attrvalue);
5921 (*ircv)->attrs.push_back(attr);
5926 if(product_type == Mea_SeaWiFS_L2)
5930 else if(product_type == GPM_L1) {
5931 Handle_GPM_l1_Coor_Attr();
5936 else if(product_type == General_Product && gproduct_pattern == GENERAL_LATLON_COOR_ATTR){
5937 Handle_LatLon_With_CoordinateAttr_Coor_Attr();
5941 else if (
true == iscoard) {
5945 if(grp_cv_paths.size() >0) {
5946 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
5947 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) != grp_cv_paths.end()){
5950 Flatten_VarPath_In_Coordinates_Attr(*irv);
5958 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
5960 if((*ircv)->rank == 2 && (*ircv)->cvartype == CV_EXIST) {
5969 if(gp_latname == (*ircv)->name) {
5971 if(
false == Is_geolatlon(gp_latname,
true))
5972 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5974 else if(gp_lonname ==(*ircv)->name) {
5976 if(
false == Is_geolatlon(gp_lonname,
false))
5977 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5985 if(
true == Is_geolatlon((*ircv)->name,
true))
5986 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5987 else if(
true == Is_geolatlon((*ircv)->name,
false))
5988 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5994 if(grp_cv_paths.size() >0) {
5995 for (
auto irv = this->
vars.begin();
5996 irv != this->vars.end(); ++irv) {
5997 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) != grp_cv_paths.end()){
6000 Flatten_VarPath_In_Coordinates_Attr(*irv);
6006 bool has_ll2d_coords =
false;
6009 if(General_Product == this->product_type && GENERAL_DIMSCALE == this->gproduct_pattern)
6010 has_ll2d_coords =
true;
6012 string ll2d_dimname0;
6013 string ll2d_dimname1;
6014 for (
auto ircv = this->cvars.begin();
6015 ircv != this->cvars.end(); ++ircv) {
6016 if((*ircv)->rank == 2) {
6018 ll2d_dimname0 = (*ircv)->getDimensions()[0]->name;
6019 ll2d_dimname1 = (*ircv)->getDimensions()[1]->name;
6020 if(ll2d_dimname0 !=
"" && ll2d_dimname1 !=
"")
6021 has_ll2d_coords =
true;
6028 if(
true == has_ll2d_coords) {
6036 bool force_flatten_coor_attr = HDF5RequestHandler::get_force_flatten_coor_attr();
6040 bool has_coor_attr_ge_2d_vars =
false;
6041 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
6042 if((*irv)->rank >=2){
6043 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
6045 if((*ira)->name == co_attrname) {
6046 has_coor_attr_ge_2d_vars =
true;
6050 if(has_coor_attr_ge_2d_vars ==
true)
6057 bool is_hybrid_eos5=
false;
6058 if(force_flatten_coor_attr ==
true && has_coor_attr_ge_2d_vars ==
true)
6059 is_hybrid_eos5 = Is_Hybrid_EOS5();
6061 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
6063 bool has_coor =
false;
6064 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
6066 if((*ira)->name == co_attrname) {
6073 if(
true == force_flatten_coor_attr &&
true == has_coor) {
6075 if(is_hybrid_eos5 ==
true) {
6076 Flatten_VarPath_In_Coordinates_Attr_EOS5((*irv));
6080 Flatten_VarPath_In_Coordinates_Attr((*irv));
6083 else if(((*irv)->rank >=2) && (has_coor_attr_ge_2d_vars ==
false ||
false == force_flatten_coor_attr)) {
6085 bool coor_attr_keep_exist =
false;
6088 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) == grp_cv_paths.end())
6091 coor_attr_keep_exist = Check_Var_2D_CVars(*irv);
6093 coor_attr_keep_exist =
true;
6097 if(product_type == OSMAPL2S)
6098 coor_attr_keep_exist =
true;
6101 if (
false == coor_attr_keep_exist) {
6102 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();) {
6103 if ((*ira)->newname == co_attrname) {
6105 ira = (*irv)->attrs.erase(ira);
6113 for (
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ ird) {
6114 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end(); ++ircv) {
6115 if ((*ird)->name == (*ircv)->cfdimname)
6116 co_attrvalue = (co_attrvalue.empty())
6117 ?(*ircv)->newname:co_attrvalue +
" "+(*ircv)->newname;
6121 if (
false == co_attrvalue.empty()) {
6123 Add_Str_Attr(attr,co_attrname,co_attrvalue);
6124 (*irv)->attrs.push_back(attr);
6127 co_attrvalue.clear();
6128 (*irv)->coord_attr_add_path =
false;
6136void GMFile:: Handle_GPM_l1_Coor_Attr() {
6138 BESDEBUG(
"h5",
"Coming to Handle_GPM_l1_Coor_Attr()"<<endl);
6152 string co_attrname =
"coordinates";
6153 string co_attrvalue=
"";
6156 set<string> cvar_2d_dimset;
6158 pair<map<string,string>::iterator,
bool>mapret;
6161 map<string,string>cfdimname_to_cvar2dname;
6164 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
6167 if((*irv)->rank == 2) {
6175 for(
auto ird = (*irv)->dims.begin(); ird != (*irv)->dims.end(); ++ird)
6176 cvar_2d_dimset.insert((*ird)->name);
6179 mapret = cfdimname_to_cvar2dname.insert(pair<string,string>((*irv)->cfdimname,(*irv)->newname));
6180 if (
false == mapret.second)
6181 throw4(
"The cf dimension name ",(*irv)->cfdimname,
" should map to 2-D coordinate variable",
6187 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
6190 if((*irv)->rank >=2) {
6194 short have_2d_dimnames_flag = 0;
6195 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
6196 if (cvar_2d_dimset.find((*ird)->name)!=cvar_2d_dimset.end())
6197 have_2d_dimnames_flag++;
6201 if(have_2d_dimnames_flag >=2) {
6205 if((*irv)->fullpath.size() > (*irv)->name.size())
6206 var_path=(*irv)->fullpath.substr(0,(*irv)->fullpath.size()-(*irv)->name.size());
6208 throw4(
"The variable full path ",(*irv)->fullpath,
" doesn't contain the variable name ",
6212 short cv_2d_flag = 0;
6215 vector<string> cv_2d_names;
6218 set<string> cv_2d_dimnames;
6221 for(map<string,string>::const_iterator itm = cfdimname_to_cvar2dname.begin();
6222 itm != cfdimname_to_cvar2dname.end();++itm) {
6225 string reduced_dimname = HDF5CFUtil::obtain_string_after_lastslash(itm->first);
6227 if(itm->first.size() <= reduced_dimname.size())
6228 throw2(
"The cf dim. name of this dimension is not right.",itm->first);
6230 cfdim_path= itm->first.substr(0,itm->first.size() - reduced_dimname.size());
6239 if(var_path == cfdim_path) {
6240 for (
auto ird = (*irv)->dims.begin(); ird!=(*irv)->dims.end();++ird) {
6241 if(reduced_dimname == (*ird)->name) {
6243 cv_2d_names.push_back(itm->second);
6244 cv_2d_dimnames.insert((*ird)->name);
6256 if(cv_2d_flag != 2) {
6259 for(map<string,string>::const_iterator itm = cfdimname_to_cvar2dname.begin();
6260 itm != cfdimname_to_cvar2dname.end();++itm) {
6262 string reduced_dimname = HDF5CFUtil::obtain_string_after_lastslash(itm->first);
6264 if(itm->first.size() <= reduced_dimname.size())
6265 throw2(
"The cf dim. name of this dimension is not right.",itm->first);
6267 cfdim_path= itm->first.substr(0,itm->first.size() - reduced_dimname.size());
6276 if(var_path.find(cfdim_path)!=string::npos) {
6277 for (
auto ird = (*irv)->dims.begin(); ird!=(*irv)->dims.end();++ird) {
6278 if(reduced_dimname == (*ird)->name) {
6280 cv_2d_names.push_back(itm->second);
6281 cv_2d_dimnames.insert((*ird)->name);
6290 if(2 == cv_2d_flag) {
6293 co_attrvalue = cv_2d_names[0] +
" " + cv_2d_names[1];
6294 if((*irv)->rank >2) {
6295 for (
auto ird = (*irv)->dims.begin(); ird !=(*irv)->dims.end();++ird) {
6298 if(cv_2d_dimnames.find((*ird)->name) == cv_2d_dimnames.end())
6299 co_attrvalue = co_attrvalue +
" " +(*ird)->newname;
6303 Add_Str_Attr(attr,co_attrname,co_attrvalue);
6304 (*irv)->attrs.push_back(attr);
6305 (*irv)->coord_attr_add_path =
false;
6313void GMFile::Handle_LatLon_With_CoordinateAttr_Coor_Attr() {
6315 BESDEBUG(
"h5",
"Coming to Handle_LatLon_With_CoordinateAttr_Coor_Attr()"<<endl);
6316 string co_attrname =
"coordinates";
6319 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
6320 if((*irv)->rank >= 2) {
6321 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end(); ++ira) {
6322 if((*ira)->name == co_attrname) {
6325 string coor_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
6326 if(Coord_Match_LatLon_NameSize(coor_value) ==
true)
6327 Flatten_VarPath_In_Coordinates_Attr(*irv);
6331 else if(Coord_Match_LatLon_NameSize_Same_Group(coor_value,HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) ==
true)
6332 Add_VarPath_In_Coordinates_Attr(*irv,coor_value);
6344bool GMFile::Coord_Match_LatLon_NameSize(
const string & coord_values) {
6346 BESDEBUG(
"h5",
"Coming to Coord_Match_LatLon_NameSize()"<<endl);
6347 bool ret_value =
false;
6348 vector<string> coord_values_vec;
6350 int match_lat_name_pair_index = -1;
6351 int match_lon_name_pair_index = -2;
6352 int num_match_lat = 0;
6353 int num_match_lon = 0;
6357 HDF5CFUtil::Split_helper(coord_values_vec,coord_values,sep);
6360 if((coord_values_vec[0])[0] !=
'/') {
6361 for(
auto irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6362 if(((*irs).find_first_of(
'/'))!=string::npos) {
6363 *irs =
'/' + (*irs);
6369 for(
auto irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6373 for(
auto ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
6374 if((*irs) == (*ivs).name1){
6375 match_lat_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6378 else if ((*irs) == (*ivs).name2) {
6379 match_lon_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6385 if((match_lat_name_pair_index == match_lon_name_pair_index) && (num_match_lat ==1) && (num_match_lon ==1))
6394bool GMFile::Coord_Match_LatLon_NameSize_Same_Group(
const string &coord_values,
const string &var_path) {
6396 BESDEBUG(
"h5",
"Coming to Coord_Match_LatLon_NameSize_Same_Group()"<<endl);
6397 bool ret_value =
false;
6398 vector<string> coord_values_vec;
6400 int match_lat_name_pair_index = -1;
6401 int match_lon_name_pair_index = -2;
6402 int num_match_lat = 0;
6403 int num_match_lon = 0;
6405 HDF5CFUtil::Split_helper(coord_values_vec,coord_values,sep);
6408 for(
auto irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6410 for(
auto ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
6411 string lat_name = HDF5CFUtil::obtain_string_after_lastslash((*ivs).name1);
6412 string lat_path = HDF5CFUtil::obtain_string_before_lastslash((*ivs).name1);
6413 string lon_name = HDF5CFUtil::obtain_string_after_lastslash((*ivs).name2);
6414 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*ivs).name2);
6415 if((*irs) == lat_name && lat_path == var_path){
6416 match_lat_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6419 else if ((*irs) == lon_name && lon_path == var_path) {
6420 match_lon_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6426 if((match_lat_name_pair_index == match_lon_name_pair_index) && (num_match_lat ==1) && (num_match_lon ==1))
6433void GMFile::Add_VarPath_In_Coordinates_Attr(
Var *var,
const string &coor_value) {
6435 BESDEBUG(
"h5",
"Coming to Add_VarPath_In_Coordinates_Attr()"<<endl);
6436 string new_coor_value;
6438 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var->fullpath) ;
6439 string var_flatten_path = get_CF_string(var_path);
6442 size_t ele_start_pos = 0;
6443 size_t cur_pos = coor_value.find_first_of(sep);
6444 while(cur_pos !=string::npos) {
6445 string tempstr = coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
6446 tempstr = var_flatten_path + tempstr;
6447 new_coor_value += tempstr + sep;
6448 ele_start_pos = cur_pos+1;
6449 cur_pos = coor_value.find_first_of(sep,cur_pos+1);
6452 if(ele_start_pos == 0)
6453 new_coor_value = var_flatten_path + coor_value;
6455 new_coor_value += var_flatten_path + coor_value.substr(ele_start_pos);
6457 string coor_attr_name =
"coordinates";
6458 Replace_Var_Str_Attr(var,coor_attr_name,new_coor_value);
6459 var->coord_attr_add_path =
false;
6464void GMFile:: Create_Missing_CV(
GMCVar *GMcvar,
const string& dimname) {
6466 BESDEBUG(
"h5",
"GMFile::Coming to Create_Missing_CV()"<<endl);
6468 GMcvar->name = dimname;
6469 GMcvar->newname = GMcvar->name;
6470 GMcvar->fullpath = GMcvar->name;
6472 GMcvar->dtype = H5INT32;
6473 hsize_t gmcvar_dimsize = dimname_to_dimsize[dimname];
6474 bool unlimited_flag = dimname_to_unlimited[dimname];
6476 gmcvar_dim->unlimited_dim = unlimited_flag;
6477 gmcvar_dim->name = dimname;
6478 gmcvar_dim->newname = dimname;
6479 GMcvar->dims.push_back(gmcvar_dim);
6480 GMcvar->cfdimname = dimname;
6481 GMcvar->cvartype = CV_NONLATLON_MISS;
6482 GMcvar->product_type = product_type;
6487bool GMFile::Is_netCDF_Dimension(
Var *var) {
6489 string netcdf_dim_mark =
"This is a netCDF dimension but not a netCDF variable";
6491 bool is_only_dimension =
false;
6493 for(
auto ira = var->attrs.begin(); ira != var->attrs.end();ira++) {
6495 if (
"NAME" == (*ira)->name) {
6497 Retrieve_H5_Attr_Value(*ira,var->fullpath);
6499 name_value.resize((*ira)->value.size());
6500 copy((*ira)->value.begin(),(*ira)->value.end(),name_value.begin());
6503 if (0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark))
6504 is_only_dimension =
true;
6510 return is_only_dimension;
6520GMFile::Is_Hybrid_EOS5() {
6522 bool has_group_hdfeos =
false;
6523 bool has_group_hdfeos_info =
false;
6529 for (
auto irg = this->
groups.begin(); irg != this->groups.end(); ++ irg) {
6530 if (
"/HDFEOS" == (*irg)->path)
6531 has_group_hdfeos =
true;
6532 else if(
"/HDFEOS INFORMATION" == (*irg)->path) {
6533 for(
auto ira = (*irg)->attrs.begin();
6534 ira != (*irg)->attrs.end();ira++) {
6535 if(
"HDFEOSVersion" == (*ira)->name)
6536 has_group_hdfeos_info =
true;
6539 if(
true == has_group_hdfeos &&
true == has_group_hdfeos_info)
6544 if(
true == has_group_hdfeos &&
true == has_group_hdfeos_info)
6550void GMFile::Handle_Hybrid_EOS5() {
6552 string eos_str=
"HDFEOS_";
6553 string eos_info_str=
"HDFEOS_INFORMATION_";
6554 string grid_str=
"GRIDS_";
6555 string swath_str=
"SWATHS_";
6556 string zas_str=
"ZAS_";
6557 string df_str=
"Data_Fields_";
6558 string gf_str=
"Geolocation_Fields_";
6559 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
6560 string temp_var_name = (*irv)->newname;
6562 bool remove_eos = Remove_EOS5_Strings(temp_var_name);
6564 if(
true == remove_eos)
6565 (*irv)->newname = get_CF_string(temp_var_name);
6567 string::size_type eos_info_pos = temp_var_name.find(eos_info_str);
6568 if(eos_info_pos !=string::npos)
6569 (*irv)->newname = temp_var_name.erase(eos_info_pos,eos_info_str.size());
6571 if(Remove_EOS5_Strings_NonEOS_Fields(temp_var_name)==
true)
6572 (*irv)->newname = get_CF_string(temp_var_name);
6578 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
6579 for (
auto ird = (*irv)->dims.begin(); ird!=(*irv)->dims.end(); ++ird) {
6580 string temp_dim_name = (*ird)->newname;
6581 bool remove_eos = Remove_EOS5_Strings(temp_dim_name);
6583 if(
true == remove_eos)
6584 (*ird)->newname = get_CF_string(temp_dim_name);
6586 string::size_type eos_info_pos = temp_dim_name.find(eos_info_str);
6587 if(eos_info_pos !=string::npos)
6588 (*ird)->newname = temp_dim_name.erase(eos_info_pos,eos_info_str.size());
6590 if(Remove_EOS5_Strings_NonEOS_Fields(temp_dim_name)==
true)
6591 (*ird)->newname = get_CF_string(temp_dim_name);
6598 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); ++irv) {
6599 string temp_var_name = (*irv)->newname;
6601 bool remove_eos = Remove_EOS5_Strings(temp_var_name);
6603 if(
true == remove_eos)
6604 (*irv)->newname = get_CF_string(temp_var_name);
6606 string::size_type eos_info_pos = temp_var_name.find(eos_info_str);
6607 if(eos_info_pos !=string::npos)
6608 (*irv)->newname = temp_var_name.erase(eos_info_pos,eos_info_str.size());
6610 if(Remove_EOS5_Strings_NonEOS_Fields(temp_var_name)==
true)
6611 (*irv)->newname = get_CF_string(temp_var_name);
6616 for (
auto irv = this->cvars.begin(); irv != this->cvars.end(); irv++) {
6617 for (
auto ird = (*irv)->dims.begin(); ird!=(*irv)->dims.end(); ++ird) {
6618 string temp_dim_name = (*ird)->newname;
6619 bool remove_eos = Remove_EOS5_Strings(temp_dim_name);
6621 if(
true == remove_eos)
6622 (*ird)->newname = get_CF_string(temp_dim_name);
6624 string::size_type eos_info_pos = temp_dim_name.find(eos_info_str);
6625 if(eos_info_pos !=string::npos)
6626 (*ird)->newname = temp_dim_name.erase(eos_info_pos,eos_info_str.size());
6628 if(Remove_EOS5_Strings_NonEOS_Fields(temp_dim_name)==
true)
6629 (*ird)->newname = get_CF_string(temp_dim_name);
6638 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
6639 for(
auto ira = (*irv)->attrs.begin(); ira != (*irv)->attrs.end();ira++) {
6642 if((*ira)->name ==
"coordinates") {
6643 string cor_values((*ira)->value.begin(),(*ira)->value.end()) ;
6644 bool change_cor_values =
false;
6646 if(cor_values.find(eos_str)==0) {
6647 if(cor_values.find(grid_str)!=string::npos) {
6648 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6649 cor_values = HDF5CFUtil::remove_substrings(cor_values,grid_str);
6650 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6651 if(new_cor_values.size() < cor_values.size()){
6652 change_cor_values =
true;
6653 cor_values = new_cor_values;
6656 else if(cor_values.find(zas_str)!=string::npos) {
6657 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6658 cor_values = HDF5CFUtil::remove_substrings(cor_values,zas_str);
6659 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6660 if(new_cor_values.size() < cor_values.size()){
6661 change_cor_values =
true;
6662 cor_values = new_cor_values;
6665 else if(cor_values.find(swath_str)!=string::npos) {
6666 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6667 cor_values = HDF5CFUtil::remove_substrings(cor_values,swath_str);
6668 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6669 if(new_cor_values.size() < cor_values.size()){
6670 change_cor_values =
true;
6671 cor_values = new_cor_values;
6674 new_cor_values = HDF5CFUtil::remove_substrings(cor_values,gf_str);
6675 if(new_cor_values.size() < cor_values.size()){
6676 change_cor_values =
true;
6677 cor_values = new_cor_values;
6682 if(
true == change_cor_values) {
6683 (*ira)->value.resize(cor_values.size());
6684 (*ira)->fstrsize=cor_values.size();
6685 (*ira)->strsize[0] = cor_values.size();
6686 copy(cor_values.begin(), cor_values.end(), (*ira)->value.begin());
6687 (*irv)->coord_attr_add_path =
false;
6698bool GMFile:: Remove_EOS5_Strings(
string &var_name) {
6700 string eos_str=
"HDFEOS_";
6701 string grid_str=
"GRIDS_";
6702 string swath_str=
"SWATHS_";
6703 string zas_str=
"ZAS_";
6704 string df_str=
"Data_Fields_";
6705 string gf_str=
"Geolocation_Fields_";
6706 string temp_var_name = var_name;
6708 bool remove_eos =
false;
6710 string::size_type eos_pos = temp_var_name.find(eos_str);
6711 if(eos_pos!=string::npos) {
6712 temp_var_name.erase(eos_pos,eos_str.size());
6714 string::size_type grid_pos=temp_var_name.find(grid_str);
6715 string::size_type grid_df_pos=string::npos;
6716 if(grid_pos!=string::npos)
6717 grid_df_pos = temp_var_name.find(df_str,grid_pos);
6718 string::size_type zas_pos = string::npos;
6719 string::size_type zas_df_pos=string::npos;
6720 if(grid_pos==string::npos || grid_df_pos ==string::npos)
6721 zas_pos=temp_var_name.find(zas_str);
6722 if(zas_pos!=string::npos)
6723 zas_df_pos=temp_var_name.find(df_str,zas_pos);
6725 if(grid_pos !=string::npos && grid_df_pos!=string::npos) {
6726 temp_var_name.erase(grid_pos,grid_str.size());
6727 grid_df_pos = temp_var_name.find(df_str);
6728 temp_var_name.erase(grid_df_pos,df_str.size());
6731 else if(zas_pos!=string::npos && zas_df_pos!=string::npos){
6732 temp_var_name.erase(zas_pos,zas_str.size());
6733 zas_df_pos = temp_var_name.find(df_str);
6734 temp_var_name.erase(zas_df_pos,df_str.size());
6739 string::size_type swath_pos=temp_var_name.find(swath_str);
6740 string::size_type swath_df_pos=string::npos;
6741 if(swath_pos!=string::npos)
6742 swath_df_pos=temp_var_name.find(df_str,swath_pos);
6744 string::size_type swath_gf_pos=string::npos;
6745 if(swath_pos!=string::npos && swath_df_pos == string::npos)
6746 swath_gf_pos=temp_var_name.find(gf_str,swath_pos);
6748 if(swath_pos !=string::npos) {
6750 if(swath_df_pos!=string::npos) {
6751 temp_var_name.erase(swath_pos,swath_str.size());
6752 swath_df_pos = temp_var_name.find(df_str);
6753 temp_var_name.erase(swath_df_pos,df_str.size());
6756 else if(swath_gf_pos!=string::npos) {
6757 temp_var_name.erase(swath_pos,swath_str.size());
6758 swath_gf_pos = temp_var_name.find(gf_str);
6759 temp_var_name.erase(swath_gf_pos,gf_str.size());
6765 if(
true == remove_eos)
6766 var_name = temp_var_name;
6771bool GMFile:: Remove_EOS5_Strings_NonEOS_Fields(
string &var_name) {
6773 string eos_str=
"HDFEOS_";
6774 string grid_str=
"GRIDS_";
6775 string swath_str=
"SWATHS_";
6776 string zas_str=
"ZAS_";
6777 string temp_var_name = var_name;
6779 bool remove_eos =
false;
6781 string::size_type eos_pos = temp_var_name.find(eos_str);
6782 if(eos_pos!=string::npos) {
6783 temp_var_name.erase(eos_pos,eos_str.size());
6787 if(temp_var_name.find(grid_str)==0)
6788 temp_var_name.erase(0,grid_str.size());
6789 else if(temp_var_name.find(swath_str)==0)
6790 temp_var_name.erase(0,swath_str.size());
6791 else if(temp_var_name.find(zas_str)==0)
6792 temp_var_name.erase(0,zas_str.size());
6794 if(
true == remove_eos)
6795 var_name = temp_var_name;
6816 if(this->unsupported_var_dtype ==
true) {
6819 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end();) {
6820 if((*ircv)->newname.find(
"FakeDim")==0) {
6821 bool var_has_fakedim =
false;
6822 for (
auto irv2 = this->
vars.begin(); irv2 != this->vars.end(); irv2++) {
6823 for (
auto ird = (*irv2)->dims.begin(); ird !=(*irv2)->dims.end(); ird++) {
6824 if((*ird)->newname == (*ircv)->newname){
6825 var_has_fakedim =
true;
6829 if(var_has_fakedim ==
true)
6832 if(var_has_fakedim ==
false) {
6835 ircv = this->cvars.erase(ircv);
6857 if(
true == this->have_nc4_non_coord) {
6858 string nc4_non_coord=
"_nc4_non_coord_";
6859 size_t nc4_non_coord_size= nc4_non_coord.size();
6860 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); irv++) {
6861 if((*irv)->name.find(nc4_non_coord)==0)
6862 (*irv)->newname = (*irv)->newname.substr(nc4_non_coord_size,(*irv)->newname.size()-nc4_non_coord_size);
6865 for (
auto ircv = this->cvars.begin(); ircv != this->cvars.end();++ircv) {
6866 if((*ircv)->name.find(nc4_non_coord)==0)
6867 (*ircv)->newname = (*ircv)->newname.substr(nc4_non_coord_size,(*ircv)->newname.size()-nc4_non_coord_size);
6875 BESDEBUG(
"h5",
"GMFile::Coming to Add_Path_Coor_Attr()"<<endl);
6876 string co_attrname =
"coordinates";
6877 for (
auto irv = this->
vars.begin(); irv != this->vars.end(); ++irv) {
6878 if((*irv)->coord_attr_add_path ==
true) {
6879 for (
auto ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
6881 if((*ira)->name == co_attrname) {
6882 string coor_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
6884 vector<string>cvalue_vec;
6885 HDF5CFUtil::Split_helper(cvalue_vec,coor_value,sep);
6886 string new_coor_value;
6887 for (
int i = 0; i<cvalue_vec.size();i++) {
6888 HDF5CFUtil::cha_co(cvalue_vec[i],(*irv)->fullpath);
6889 cvalue_vec[i] = get_CF_string(cvalue_vec[i]);
6891 new_coor_value = cvalue_vec[i];
6893 new_coor_value += sep+cvalue_vec[i];
6902 Replace_Var_Str_Attr((*irv),co_attrname,new_coor_value);
6917GMFile::release_standalone_GMCVar_vector(vector<GMCVar*>&tempgc_vars){
6919 for (
auto i = tempgc_vars.begin(); i != tempgc_vars.end(); ) {
6921 i = tempgc_vars.erase(i);
6928GMFile::add_ignored_info_attrs(
bool is_grp,
bool is_first){
6932GMFile::add_ignored_info_objs(
bool is_dim_related,
bool is_first) {
6939GMFile::ignored_dimscale_ref_list(
Var *var) {
6941 bool ignored_dimscale =
true;
6942 if(General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern) {
6944 bool has_dimscale =
false;
6945 bool has_reference_list =
false;
6947 for(
auto ira = var->attrs.begin(); ira != var->attrs.end();ira++) {
6949 if((*ira)->name ==
"REFERENCE_LIST" &&
6950 false == HDF5CFUtil::cf_strict_support_type((*ira)->getType()))
6951 has_reference_list =
true;
6952 if((*ira)->name ==
"CLASS") {
6953 Retrieve_H5_Attr_Value(*ira,var->fullpath);
6955 class_value.resize((*ira)->value.size());
6956 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
6960 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
6961 has_dimscale =
true;
6965 if(
true == has_dimscale &&
true == has_reference_list) {
6966 ignored_dimscale=
false;
6972 return ignored_dimscale;
This class specifies the core engineering of mapping HDF5 to DAP by following CF.
include the entry functions to execute the handlers
This class represents one attribute.
This class repersents one dimension of an HDF5 dataset(variable).
This class retrieves all information from an HDF5 file.
std::vector< Group * > groups
Non-root group vectors.
virtual void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for datasets.
virtual void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
virtual void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes.
virtual void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes.
std::vector< Var * > vars
Var vectors.
virtual void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name.
virtual void Retrieve_H5_Info(const char *path, hid_t file_id, bool)
std::vector< Attribute * > root_attrs
Root attribute vectors.
virtual void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes.
virtual void Flatten_Obj_Name(bool)
Flatten the object name.
virtual bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
This class is a derived class of CVar. It represents a coordinate variable for general HDF5 files.
void Add_Supplement_Attrs(bool) override
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
void Add_Path_Coord_Attr()
Update the coordinate attribute to include path and also flatten.
void Handle_Obj_NameClashing(bool)
Handle object name clashing for general NASA HDF5 products.
void Remove_Unused_FakeDimVars()
Unsupported datatype array may generate FakeDim. Remove them.
void Update_Product_Type()
Update "product type" attributes for general HDF5 products.
bool Have_Grid_Mapping_Attrs() override
Check if having Grid Mapping Attrs.
void Handle_SpVar_Attr() override
Handle special variable attributes for general NASA HDF5 products.
void Handle_DimNameClashing() override
void Handle_Grid_Mapping_Vars() override
Handle Grid Mapping Vars.
void Adjust_H5_Attr_Value(Attribute *attr)
Adjust attribute values for general HDF5 products.
void Retrieve_H5_CVar_Supported_Attr_Values() override
Retrieve coordinate variable attributes.
void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr) override
Retrieve DDS information from the HDF5 file; real implementation for general HDF5 products.
void Handle_SpVar() override
Handle special variables for general NASA HDF5 products.
void Remove_Unneeded_Objects()
Remove unneeded objects.
void Handle_CVar() override
Handle coordinate variables for general NASA HDF5 products.
void Add_Dim_Name()
Add dimension name.
void Retrieve_H5_Supported_Attr_Values() override
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
void Handle_Coor_Attr() override
Handle "coordinates" attributes for general HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
void Handle_Unsupported_Dspace(bool) override
Handle unsupported HDF5 dataspaces for general HDF5 products.
void Handle_Unsupported_Others(bool) override
Handle other unmapped objects/attributes for general HDF5 products.
void Handle_Unsupported_Dtype(bool) override
Handle unsupported HDF5 datatypes for general HDF5 products.
void Flatten_Obj_Name(bool include_attr) override
Flatten the object name for general NASA HDF5 products.
void Adjust_Dim_Name() override
Adjust dimension name for general NASA HDF5 products.
void Adjust_Obj_Name() override
Adjust object names based on different general NASA HDF5 products.
This class is a derived class of Var. It represents a special general HDF5 product(currently ACOS and...
This class represents one HDF5 dataset(CF variable)
const std::vector< Dimension * > & getDimensions() const
Get the list of the dimensions.
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)