39 #include "h5apicompatible.h"
45 using namespace HDF5CF;
48 GMCVar::GMCVar(
Var*var) {
50 BESDEBUG(
"h5",
"Coming to GMCVar()"<<endl);
51 newname = var->newname;
53 fullpath = var->fullpath;
55 total_elems = var->total_elems;
57 unsupported_attr_dtype = var->unsupported_attr_dtype;
58 unsupported_dspace = var->unsupported_dspace;
60 for (vector<Attribute*>::iterator ira = var->attrs.begin();
61 ira!=var->attrs.end(); ++ira) {
63 attr->name = (*ira)->name;
64 attr->newname = (*ira)->newname;
65 attr->dtype =(*ira)->dtype;
66 attr->count =(*ira)->count;
67 attr->strsize = (*ira)->strsize;
68 attr->fstrsize = (*ira)->fstrsize;
69 attr->value =(*ira)->value;
70 attrs.push_back(attr);
73 for (vector<Dimension*>::iterator ird = var->dims.begin();
74 ird!=var->dims.end(); ++ird) {
76 dim->name = (*ird)->name;
77 dim->newname = (*ird)->newname;
78 dim->unlimited_dim = (*ird)->unlimited_dim;
81 product_type = General_Product;
85 GMCVar::GMCVar(
GMCVar*cvar) {
87 newname = cvar->newname;
89 fullpath = cvar->fullpath;
92 unsupported_attr_dtype = cvar->unsupported_attr_dtype;
93 unsupported_dspace = cvar->unsupported_dspace;
95 for (vector<Attribute*>::iterator ira = cvar->attrs.begin();
96 ira!=cvar->attrs.end(); ++ira) {
98 attr->name = (*ira)->name;
99 attr->newname = (*ira)->newname;
100 attr->dtype =(*ira)->dtype;
101 attr->count =(*ira)->count;
102 attr->strsize = (*ira)->strsize;
103 attr->fstrsize = (*ira)->fstrsize;
104 attr->value =(*ira)->value;
105 attrs.push_back(attr);
108 for (vector<Dimension*>::iterator ird = cvar->dims.begin();
109 ird!=cvar->dims.end(); ++ird) {
113 dim->name = (*ird)->name;
114 dim->newname = (*ird)->newname;
118 GMcvar->cfdimname = latdim0;
119 GMcvar->cvartype = CV_EXIST;
120 GMcvar->product_type = product_type;
127 GMSPVar::GMSPVar(
Var*var) {
129 BESDEBUG(
"h5",
"Coming to GMSPVar()"<<endl);
130 fullpath = var->fullpath;
132 total_elems = var->total_elems;
133 unsupported_attr_dtype = var->unsupported_attr_dtype;
134 unsupported_dspace = var->unsupported_dspace;
142 for (vector<Attribute*>::iterator ira = var->attrs.begin();
143 ira!=var->attrs.end(); ++ira) {
145 attr->name = (*ira)->name;
146 attr->newname = (*ira)->newname;
147 attr->dtype =(*ira)->dtype;
148 attr->count =(*ira)->count;
149 attr->strsize = (*ira)->strsize;
150 attr->fstrsize = (*ira)->fstrsize;
151 attr->value =(*ira)->value;
152 attrs.push_back(attr);
155 for (vector<Dimension*>::iterator ird = var->dims.begin();
156 ird!=var->dims.end(); ++ird) {
158 dim->name = (*ird)->name;
159 dim->newname = (*ird)->newname;
160 dim->unlimited_dim = (*ird)->unlimited_dim;
166 GMFile::GMFile(
const char*file_fullpath, hid_t file_id, H5GCFProduct product_type, GMPattern gproduct_pattern):
167 File(file_fullpath,file_id), product_type(product_type),gproduct_pattern(gproduct_pattern),iscoard(false),have_nc4_non_coord(false)
176 if (!this->cvars.empty()){
177 for (vector<GMCVar *>:: const_iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i) {
182 if (!this->spvars.empty()){
183 for (vector<GMSPVar *>:: const_iterator i= this->spvars.begin(); i!=this->spvars.end(); ++i) {
191 string GMFile::get_CF_string(
string s) {
198 return File::get_CF_string(s);
199 else if (General_Product == product_type && OTHERGMS == gproduct_pattern) {
201 if(
true == HDF5RequestHandler::get_keep_var_leading_underscore())
202 return File::get_CF_string(s);
205 return File::get_CF_string(s);
211 return File::get_CF_string(s);
217 hid_t file_id,
bool include_attr) {
219 BESDEBUG(
"h5",
"Coming to Retrieve_H5_Info()"<<endl);
222 if (product_type == Mea_SeaWiFS_L2 || product_type == Mea_SeaWiFS_L3
223 || GPMS_L3 == product_type || GPMM_L3 == product_type || GPM_L1 == product_type || OBPG_L3 == product_type
224 || Mea_Ozone == product_type || General_Product == product_type)
237 BESDEBUG(
"h5",
"Coming to Update_Product_Type()"<<endl);
238 if(GPMS_L3 == this->product_type || GPMM_L3 == this->product_type) {
241 Check_General_Product_Pattern();
242 if(GENERAL_DIMSCALE == this->gproduct_pattern){
243 if(GPMS_L3 == this->product_type) {
244 for (vector<Var *>::iterator irv = this->
vars.begin();
245 irv != this->vars.end(); ++irv)
246 (*irv)->newname = (*irv)->name;
248 this->product_type = General_Product;
252 else if(General_Product == this->product_type)
253 Check_General_Product_Pattern();
259 BESDEBUG(
"h5",
"Coming to Remove_Unneeded_Objects()"<<endl);
260 if(General_Product == this->product_type) {
261 string file_path = this->path;
262 if(HDF5CFUtil::obtain_string_after_lastslash(file_path).find(
"OMPS-NPP")==0)
263 Remove_OMPSNPP_InputPointers();
265 if((General_Product == this->product_type) && (GENERAL_DIMSCALE == this->gproduct_pattern)) {
266 set<string> nc4_non_coord_set;
267 string nc4_non_coord=
"_nc4_non_coord_";
268 size_t nc4_non_coord_size= nc4_non_coord.size();
269 for (vector<Var *>::iterator irv = this->
vars.begin();
270 irv != this->vars.end(); ++irv) {
271 if((*irv)->name.find(nc4_non_coord)==0)
272 nc4_non_coord_set.insert((*irv)->name.substr(nc4_non_coord_size,(*irv)->name.size()-nc4_non_coord_size));
276 for (vector<Var *>::iterator irv = this->
vars.begin();
277 irv != this->vars.end();) {
278 if(nc4_non_coord_set.find((*irv)->name)!=nc4_non_coord_set.end()){
280 irv=this->
vars.erase(irv);
286 if(nc4_non_coord_set.size()!=0)
287 this->have_nc4_non_coord =
true;
291 void GMFile::Remove_OMPSNPP_InputPointers() {
295 for (vector<Group *>::iterator irg = this->
groups.begin();
296 irg != this->groups.end(); ) {
297 if((*irg)->path.find(
"/InputPointers")==0) {
299 irg = this->
groups.erase(irg);
306 for (vector<Var *>::iterator irv = this->
vars.begin();
307 irv != this->vars.end(); ) {
308 if((*irv)->fullpath.find(
"/InputPointers")==0) {
310 irv = this->
vars.erase(irv);
319 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
320 ircv != this->cvars.end(); ++ircv) {
322 if ((*ircv)->cvartype != CV_NONLATLON_MISS){
323 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
324 ira != (*ircv)->attrs.end(); ++ira) {
325 Retrieve_H5_Attr_Value(*ira,(*ircv)->fullpath);
334 BESDEBUG(
"h5",
"Coming to Retrieve_H5_Supported_Attr_Values()"<<endl);
340 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
341 ircv != this->cvars.end(); ++ircv) {
343 if ((*ircv)->cvartype != CV_NONLATLON_MISS){
344 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
345 ira != (*ircv)->attrs.end(); ++ira) {
346 Retrieve_H5_Attr_Value(*ira,(*ircv)->fullpath);
352 for (vector<GMSPVar *>::iterator irspv = this->spvars.begin();
353 irspv != this->spvars.end(); ++irspv) {
355 for (vector<Attribute *>::iterator ira = (*irspv)->attrs.begin();
356 ira != (*irspv)->attrs.end(); ++ira) {
357 Retrieve_H5_Attr_Value(*ira,(*irspv)->fullpath);
368 BESDEBUG(
"h5",
"Coming to Adjust_H5_Attr_Value()"<<endl);
369 if (product_type == ACOS_L2S_OR_OCO2_L1B) {
370 if ((
"Type" == attr->name) && (H5VSTRING == attr->dtype)) {
371 string orig_attrvalues(attr->value.begin(),attr->value.end());
372 if (orig_attrvalues !=
"Signed64")
return;
373 string new_attrvalues =
"Signed32";
377 attr->value.resize(new_attrvalues.size());
378 copy(new_attrvalues.begin(),new_attrvalues.end(),attr->value.begin());
386 BESDEBUG(
"h5",
"Coming to Handle_Unsupported_Dtype()"<<endl);
387 if(
true == check_ignored) {
388 Gen_Unsupported_Dtype_Info(include_attr);
391 Handle_GM_Unsupported_Dtype(include_attr);
395 void GMFile:: Handle_GM_Unsupported_Dtype(
bool include_attr) {
397 BESDEBUG(
"h5",
"Coming to Handle_GM_Unsupported_Dtype()"<<endl);
398 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
399 ircv != this->cvars.end(); ) {
400 if (
true == include_attr) {
401 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
402 ira != (*ircv)->attrs.end(); ) {
403 H5DataType temp_dtype = (*ira)->getType();
404 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
406 ira = (*ircv)->attrs.erase(ira);
413 H5DataType temp_dtype = (*ircv)->getType();
414 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
422 ircv = this->cvars.erase(ircv);
429 for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
430 ircv != this->spvars.end(); ) {
432 if (
true == include_attr) {
433 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
434 ira != (*ircv)->attrs.end(); ) {
435 H5DataType temp_dtype = (*ira)->getType();
436 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
438 ira = (*ircv)->attrs.erase(ira);
445 H5DataType temp_dtype = (*ircv)->getType();
446 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype)) {
448 ircv = this->spvars.erase(ircv);
458 void GMFile:: Gen_Unsupported_Dtype_Info(
bool include_attr) {
460 BESDEBUG(
"h5",
"GMFile::Coming to Gen_Unsupported_Dtype_Info()"<<endl);
461 if(
true == include_attr) {
463 File::Gen_Group_Unsupported_Dtype_Info();
464 File::Gen_Var_Unsupported_Dtype_Info();
465 Gen_VarAttr_Unsupported_Dtype_Info();
471 void GMFile:: Gen_VarAttr_Unsupported_Dtype_Info() {
473 BESDEBUG(
"h5",
"GMFile::Coming to Gen_Unsupported_Dtype_Info()"<<endl);
475 if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
476 || (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type) || (Mea_SeaWiFS_L3 == this->product_type)
477 || (OBPG_L3 == this->product_type)) {
478 Gen_DimScale_VarAttr_Unsupported_Dtype_Info();
482 File::Gen_VarAttr_Unsupported_Dtype_Info();
485 Gen_GM_VarAttr_Unsupported_Dtype_Info();
490 void GMFile:: Gen_GM_VarAttr_Unsupported_Dtype_Info(){
492 BESDEBUG(
"h5",
"GMFile::Coming to Gen_GM_VarAttr_Unsupported_Dtype_Info()"<<endl);
493 if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
494 || (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type) || (Mea_SeaWiFS_L3 == this->product_type)
495 || (OBPG_L3 == this->product_type)) {
497 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
498 irv != this->cvars.end(); ++irv) {
501 bool is_ignored = ignored_dimscale_ref_list((*irv));
502 if (
false == (*irv)->attrs.empty()) {
503 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
504 ira != (*irv)->attrs.end(); ++ira) {
505 H5DataType temp_dtype = (*ira)->getType();
506 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
510 if ((
"DIMENSION_LIST" !=(*ira)->name) &&
511 (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
512 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
518 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
519 irv != this->spvars.end(); ++irv) {
522 bool is_ignored = ignored_dimscale_ref_list((*irv));
523 if (
false == (*irv)->attrs.empty()) {
525 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
526 ira != (*irv)->attrs.end(); ++ira) {
527 H5DataType temp_dtype = (*ira)->getType();
528 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
532 if ((
"DIMENSION_LIST" !=(*ira)->name) &&
533 (
"REFERENCE_LIST" != (*ira)->name ||
true == is_ignored))
534 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
542 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
543 irv != this->cvars.end(); ++irv) {
544 if (
false == (*irv)->attrs.empty()) {
546 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
547 ira != (*irv)->attrs.end(); ++ira) {
548 H5DataType temp_dtype = (*ira)->getType();
549 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
550 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
557 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
558 irv != this->spvars.end(); ++irv) {
559 if (
false == (*irv)->attrs.empty()) {
561 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
562 ira != (*irv)->attrs.end(); ++ira) {
563 H5DataType temp_dtype = (*ira)->getType();
564 if (
false == HDF5CFUtil::cf_strict_support_type(temp_dtype) || temp_dtype == H5INT64 || temp_dtype == H5UINT64) {
565 this->add_ignored_info_attrs(
false,(*irv)->fullpath,(*ira)->name);
579 BESDEBUG(
"h5",
"Coming to GMFile:Handle_Unsupported_Dspace()"<<endl);
580 if(
true == check_ignored)
581 Gen_Unsupported_Dspace_Info();
584 Handle_GM_Unsupported_Dspace(include_attr);
589 void GMFile:: Handle_GM_Unsupported_Dspace(
bool include_attr) {
591 BESDEBUG(
"h5",
"Coming to GMFile:Handle_GM_Unsupported_Dspace()"<<endl);
592 if(
true == this->unsupported_var_dspace) {
593 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
594 ircv != this->cvars.end(); ) {
595 if (
true == (*ircv)->unsupported_dspace ) {
603 ircv = this->cvars.erase(ircv);
610 for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
611 ircv != this->spvars.end(); ) {
613 if (
true == (*ircv)->unsupported_dspace) {
615 ircv = this->spvars.erase(ircv);
624 if(
true == include_attr) {
625 if(
true == this->unsupported_var_attr_dspace) {
626 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
627 ircv != this->cvars.end(); ++ircv) {
628 if (
false == (*ircv)->attrs.empty()) {
629 if (
true == (*ircv)->unsupported_attr_dspace) {
630 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
631 ira != (*ircv)->attrs.end(); ) {
632 if (0 == (*ira)->count) {
634 ira = (*ircv)->attrs.erase(ira);
644 for (vector<GMSPVar *>::iterator ircv = this->spvars.begin();
645 ircv != this->spvars.end(); ++ircv) {
646 if (
false == (*ircv)->attrs.empty()) {
647 if (
true == (*ircv)->unsupported_attr_dspace) {
648 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
649 ira != (*ircv)->attrs.end(); ) {
650 if (0 == (*ira)->count) {
652 ira = (*ircv)->attrs.erase(ira);
667 void GMFile:: Gen_Unsupported_Dspace_Info() {
669 File::Gen_Unsupported_Dspace_Info();
676 BESDEBUG(
"h5",
"Coming to GMFile:Handle_Unsupported_Others()"<<endl);
681 if(General_Product != this->product_type
682 || (General_Product == this->product_type && OTHERGMS != this->gproduct_pattern)){
685 if((General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern)
686 || (Mea_Ozone == this->product_type) || (Mea_SeaWiFS_L2 == this->product_type)
687 || (Mea_SeaWiFS_L3 == this->product_type)
688 || (OBPG_L3 == this->product_type))
690 remove_netCDF_internal_attributes(include_attr);
691 if(include_attr ==
true) {
693 for (vector<Attribute *>::iterator ira = this->
root_attrs.begin(); ira != this->root_attrs.end();) {
695 if((*ira)->name ==
"_nc3_strict") {
700 else if((*ira)->name ==
"_NCProperties") {
708 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
709 irv != this->cvars.end(); ++irv) {
710 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
711 ira != (*irv)->attrs.end();) {
712 if((*ira)->name ==
"CLASS") {
713 string class_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
717 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
719 ira = (*irv)->attrs.erase(ira);
726 else if((*ira)->name ==
"NAME") {
728 ira =(*irv)->attrs.erase(ira);
732 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
733 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
735 ira =(*irv)->attrs.erase(ira);
738 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
739 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
741 ira =(*irv)->attrs.erase(ira);
749 else if((*ira)->name ==
"_Netcdf4Dimid") {
751 ira =(*irv)->attrs.erase(ira);
754 else if((*ira)->name ==
"_nc3_strict") {
756 ira =(*irv)->attrs.erase(ira);
769 if(
true == this->check_ignored &&
true == include_attr) {
770 if(
true == HDF5RequestHandler::get_drop_long_string()){
771 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
772 irv != this->cvars.end(); ++irv) {
773 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
774 ira != (*irv)->attrs.end();++ira) {
775 if(
true == Check_DropLongStr((*irv),(*ira))) {
776 this->add_ignored_droplongstr_hdr();
777 this->add_ignored_var_longstr_info((*irv),(*ira));
782 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
783 irv != this->spvars.end(); ++irv) {
784 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
785 ira != (*irv)->attrs.end();++ira) {
786 if(
true == Check_DropLongStr((*irv),(*ira))) {
787 this->add_ignored_droplongstr_hdr();
788 this->add_ignored_var_longstr_info((*irv),(*ira));
797 if(
false == this->have_ignored)
798 this->add_no_ignored_info();
805 BESDEBUG(
"h5",
"Coming to GMFile:Add_Dim_Name()"<<endl);
806 switch(product_type) {
809 Add_Dim_Name_Mea_SeaWiFS();
812 Add_Dim_Name_Aqu_L3();
815 Add_Dim_Name_OSMAPL2S();
817 case ACOS_L2S_OR_OCO2_L1B:
818 Add_Dim_Name_ACOS_L2S_OCO2_L1B();
821 Add_Dim_Name_Mea_Ozonel3z();
829 Add_Dim_Name_OBPG_L3();
831 case General_Product:
832 Add_Dim_Name_General_Product();
835 throw1(
"Cannot generate dim. names for unsupported datatype");
840 for (vector<Var*>::iterator irv2 = this->
vars.begin();
841 irv2 != this->vars.end(); irv2++) {
842 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
843 ird !=(*irv2)->dims.end(); ird++) {
844 cerr<<
"Dimension name afet Add_Dim_Name "<<(*ird)->newname <<endl;
852 void GMFile::Add_Dim_Name_OBPG_L3() {
854 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_OBPG_L3()"<<endl);
857 Check_General_Product_Pattern();
858 Add_Dim_Name_General_Product();
862 void GMFile::Add_Dim_Name_Mea_SeaWiFS() {
864 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Mea_SeaWiFS()"<<endl);
865 pair<set<string>::iterator,
bool> setret;
866 if (Mea_SeaWiFS_L3 == product_type)
868 for (vector<Var *>::iterator irv = this->
vars.begin();
869 irv != this->vars.end(); ++irv) {
870 Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
871 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
872 ird !=(*irv)->dims.end();++ird) {
873 setret = dimnamelist.insert((*ird)->name);
874 if (
true == setret.second)
875 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
879 if (
true == dimnamelist.empty())
880 throw1(
"This product should have the dimension names, but no dimension names are found");
884 void GMFile::Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(
Var* var)
887 BESDEBUG(
"h5",
"Coming to Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
889 bool has_dimlist =
false;
890 bool has_class =
false;
891 bool has_reflist =
false;
893 for(vector<Attribute *>::iterator ira = var->attrs.begin();
894 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 (vector<Dimension *>::iterator ird= var->dims.begin();
937 ird != var->dims.end(); ++ird) {
938 Add_One_FakeDim_Name(*ird);
939 setsizeret = fakedimsize.insert((*ird)->size);
940 if (
false == setsizeret.second)
941 Adjust_Duplicate_FakeDim_Name(*ird);
945 for (
int i = 0; i < var->dims.size(); ++i) {
946 Add_One_FakeDim_Name((var->dims)[i]);
947 bool gotoMainLoop =
false;
948 for (
int j =i-1; j>=0 && !gotoMainLoop; --j) {
949 if (((var->dims)[i])->size == ((var->dims)[j])->size){
950 Adjust_Duplicate_FakeDim_Name((var->dims)[i]);
961 void GMFile::Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(
Var *var,
Attribute*dimlistattr)
964 BESDEBUG(
"h5",
"Coming to Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
965 ssize_t objnamelen = -1;
972 hid_t amemtype_id = -1;
973 hid_t aspace_id = -1;
977 if(NULL == 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[0]) <0)
1006 throw2(
"Cannot obtain the referenced object for the variable ",var->name);
1009 vector<char> objname;
1010 int vlbuf_index = 0;
1013 for (vector<Dimension *>::iterator ird = var->dims.begin();
1014 ird != var->dims.end(); ++ird) {
1016 if(vlbuf[vlbuf_index].p== NULL)
1017 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);
1022 if ((objnamelen= H5Iget_name(ref_dset,NULL,0))<=0)
1023 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
1024 objname.resize(objnamelen+1);
1025 if ((objnamelen= H5Iget_name(ref_dset,&objname[0],objnamelen+1))<=0)
1026 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
1028 string objname_str = string(objname.begin(),objname.end());
1029 string trim_objname = objname_str.substr(0,objnamelen);
1030 (*ird)->name = string(trim_objname.begin(),trim_objname.end());
1032 pair<set<string>::iterator,
bool> setret;
1033 setret = dimnamelist.insert((*ird)->name);
1034 if (
true == setret.second)
1035 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1036 (*ird)->newname = (*ird)->name;
1043 if(vlbuf.size()!= 0) {
1045 if ((aspace_id = H5Aget_space(attr_id)) < 0)
1046 throw2(
"Cannot get hdf5 dataspace id for the attribute ",dimlistattr->name);
1048 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)&vlbuf[0])<0)
1049 throw2(
"Cannot successfully clean up the variable length memory for the variable ",var->name);
1051 H5Sclose(aspace_id);
1056 H5Tclose(amemtype_id);
1067 if(amemtype_id != -1)
1068 H5Tclose(amemtype_id);
1071 H5Sclose(aspace_id);
1085 void GMFile::Add_Dim_Name_Mea_Ozonel3z() {
1087 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Mea_Ozonel3z()"<<endl);
1089 bool use_dimscale =
false;
1091 for (vector<Group *>::iterator irg = this->
groups.begin();
1092 irg != this->groups.end(); ++ irg) {
1093 if (
"/Dimensions" == (*irg)->path) {
1094 use_dimscale =
true;
1099 if (
false == use_dimscale) {
1101 bool has_dimlist =
false;
1102 bool has_class =
false;
1103 bool has_reflist =
false;
1105 for (vector<Var *>::iterator irv = this->
vars.begin();
1106 irv != this->vars.end(); irv++) {
1108 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1109 ira != (*irv)->attrs.end();ira++) {
1110 if (
"DIMENSION_LIST" == (*ira)->name)
1113 if (
true == has_dimlist)
1117 if (
true == has_dimlist) {
1118 for (vector<Var *>::iterator irv = this->
vars.begin();
1119 irv != this->vars.end(); irv++) {
1121 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1122 ira != (*irv)->attrs.end();ira++) {
1123 if (
"CLASS" == (*ira)->name)
1125 if (
"REFERENCE_LIST" == (*ira)->name)
1127 if (
true == has_class &&
true == has_reflist)
1131 if (
true == has_class &&
1132 true == has_reflist)
1136 if (
true == has_class &&
true == has_reflist)
1137 use_dimscale =
true;
1141 if (
true == use_dimscale) {
1143 pair<set<string>::iterator,
bool> setret;
1144 for (vector<Var *>::iterator irv = this->
vars.begin();
1145 irv != this->vars.end(); ++irv) {
1146 Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
1147 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
1148 ird !=(*irv)->dims.end();++ird) {
1149 setret = dimnamelist.insert((*ird)->name);
1150 if(
true == setret.second)
1151 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1155 if (
true == dimnamelist.empty())
1156 throw1(
"This product should have the dimension names, but no dimension names are found");
1162 multimap<hsize_t,string> ozonedimsize_to_dimname;
1163 pair<multimap<hsize_t,string>::iterator,multimap<hsize_t,string>::iterator> mm_er_ret;
1164 multimap<hsize_t,string>::iterator irmm;
1166 for (vector<Var *>::iterator irv = this->
vars.begin();
1167 irv != this->vars.end(); ++irv) {
1168 bool is_cv = check_cv((*irv)->name);
1169 if (
true == is_cv) {
1170 if ((*irv)->dims.size() != 1)
1171 throw3(
"The coordinate variable", (*irv)->name,
" must be one dimension for the zonal average product");
1172 ozonedimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[0]->size,(*irv)->fullpath));
1176 set<hsize_t> fakedimsize;
1177 pair<set<hsize_t>::iterator,
bool> setsizeret;
1178 pair<set<string>::iterator,
bool> setret;
1179 pair<set<string>::iterator,
bool> tempsetret;
1180 set<string> tempdimnamelist;
1181 bool fakedimflag =
false;
1183 for (vector<Var *>::iterator irv = this->
vars.begin();
1184 irv != this->vars.end(); ++irv) {
1186 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
1187 ird != (*irv)->dims.end(); ++ird) {
1190 mm_er_ret = ozonedimsize_to_dimname.equal_range((*ird)->size);
1191 for (irmm = mm_er_ret.first; irmm!=mm_er_ret.second;irmm++) {
1192 setret = tempdimnamelist.insert(irmm->second);
1193 if (
true == setret.second) {
1194 (*ird)->name = irmm->second;
1195 (*ird)->newname = (*ird)->name;
1196 setret = dimnamelist.insert((*ird)->name);
1197 if(setret.second) Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1198 fakedimflag =
false;
1203 if (
true == fakedimflag) {
1204 Add_One_FakeDim_Name(*ird);
1205 setsizeret = fakedimsize.insert((*ird)->size);
1206 if (
false == setsizeret.second)
1207 Adjust_Duplicate_FakeDim_Name(*ird);
1211 tempdimnamelist.clear();
1212 fakedimsize.clear();
1218 bool GMFile::check_cv(
string & varname) {
1220 BESDEBUG(
"h5",
"Coming to check_cv()"<<endl);
1221 const string lat_name =
"Latitude";
1222 const string time_name =
"Time";
1223 const string ratio_pressure_name =
"MixingRatioPressureLevels";
1224 const string profile_pressure_name =
"ProfilePressureLevels";
1225 const string wave_length_name =
"Wavelength";
1227 if (lat_name == varname)
1229 else if (time_name == varname)
1231 else if (ratio_pressure_name == varname)
1233 else if (profile_pressure_name == varname)
1235 else if (wave_length_name == varname)
1242 void GMFile::Add_Dim_Name_GPM()
1245 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_GPM()"<<endl);
1247 pair<set<string>::iterator,
bool> setret;
1259 for (vector<Var *>::iterator irv = this->
vars.begin();
1260 irv != this->vars.end(); irv++) {
1262 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1263 ira != (*irv)->attrs.end(); ++ira) {
1265 if(
"DimensionNames" == (*ira)->name) {
1267 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1268 string dimname_value((*ira)->value.begin(),(*ira)->value.end());
1270 vector<string> ind_elems;
1274 if(ind_elems.size() != (
size_t)((*irv)->getRank())) {
1275 throw2(
"The number of dims obtained from the <DimensionNames> attribute is not equal to the rank ",
1279 for(
unsigned int i = 0; i<ind_elems.size(); ++i) {
1281 ((*irv)->dims)[i]->name = ind_elems[i];
1285 if(((*irv)->dims)[i]->name==
""){
1286 Add_One_FakeDim_Name(((*irv)->dims)[i]);
1289 string fakedim =
"FakeDim";
1290 stringstream sdim_count;
1291 sdim_count << dim_count;
1292 fakedim = fakedim + sdim_count.str();
1294 ((*irv)->dims)[i]->name = fakedim;
1295 ((*irv)->dims)[i]->newname = fakedim;
1296 ind_elems[i] = fakedim;
1301 ((*irv)->dims)[i]->newname = ind_elems[i];
1302 setret = dimnamelist.insert(((*irv)->dims)[i]->name);
1304 if (
true == setret.second) {
1305 Insert_One_NameSizeMap_Element(((*irv)->dims)[i]->name,
1306 ((*irv)->dims)[i]->size,
1307 ((*irv)->dims)[i]->unlimited_dim);
1310 if(dimname_to_dimsize[((*irv)->dims)[i]->name] !=((*irv)->dims)[i]->size)
1311 throw5(
"Dimension ",((*irv)->dims)[i]->name,
"has two sizes",
1312 ((*irv)->dims)[i]->size,dimname_to_dimsize[((*irv)->dims)[i]->name]);
1324 if(
false == has_dim_name_attr) {
1326 throw4(
"The variable ", (*irv)->name,
" doesn't have the DimensionNames attribute.",
1327 "We currently don't support this case. Please report to the NASA data center.");
1336 void GMFile::Add_Dim_Name_Aqu_L3()
1338 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Aqu_L3()"<<endl);
1339 for (vector<Var *>::iterator irv = this->
vars.begin();
1340 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";
1365 void 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 (vector<Var *>::iterator irv = this->
vars.begin();
1380 irv != this->vars.end(); ++irv) {
1381 tempvarname = (*irv)->name;
1382 if ((tempvarname.size() > key.size())&&
1383 (key == tempvarname.substr(tempvarname.size()-key.size(),key.size()))){
1384 if ((*irv)->dims.size() !=2)
1385 throw1(
"Currently only 2D lat/lon is supported for OSMAPL2S");
1386 osmapl2sdimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[0]->size,osmapl2sdim0));
1387 osmapl2sdimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[1]->size,osmapl2sdim1));
1392 set<hsize_t> fakedimsize;
1393 pair<set<hsize_t>::iterator,
bool> setsizeret;
1394 pair<set<string>::iterator,
bool> setret;
1395 pair<set<string>::iterator,
bool> tempsetret;
1396 set<string> tempdimnamelist;
1397 bool fakedimflag =
false;
1400 for (vector<Var *>::iterator irv = this->
vars.begin();
1401 irv != this->vars.end(); ++irv) {
1403 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
1404 ird != (*irv)->dims.end(); ++ird) {
1407 mm_er_ret = osmapl2sdimsize_to_dimname.equal_range((*ird)->size);
1408 for (irmm = mm_er_ret.first; irmm!=mm_er_ret.second;irmm++) {
1409 setret = tempdimnamelist.insert(irmm->second);
1410 if (setret.second) {
1411 (*ird)->name = irmm->second;
1412 (*ird)->newname = (*ird)->name;
1413 setret = dimnamelist.insert((*ird)->name);
1414 if(setret.second) Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1415 fakedimflag =
false;
1420 if (
true == fakedimflag) {
1421 Add_One_FakeDim_Name(*ird);
1422 setsizeret = fakedimsize.insert((*ird)->size);
1423 if (!setsizeret.second)
1424 Adjust_Duplicate_FakeDim_Name(*ird);
1427 tempdimnamelist.clear();
1428 fakedimsize.clear();
1433 void GMFile::Add_Dim_Name_ACOS_L2S_OCO2_L1B(){
1435 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_ACOS_L2S_OCO2_L1B()"<<endl);
1436 for (vector<Var *>::iterator irv = this->
vars.begin();
1437 irv != this->vars.end(); ++irv) {
1439 set<hsize_t> fakedimsize;
1440 pair<set<hsize_t>::iterator,
bool> setsizeret;
1441 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1442 ird != (*irv)->dims.end(); ++ird) {
1443 Add_One_FakeDim_Name(*ird);
1444 setsizeret = fakedimsize.insert((*ird)->size);
1445 if (
false == setsizeret.second)
1446 Adjust_Duplicate_FakeDim_Name(*ird);
1452 void GMFile::Add_Dim_Name_General_Product(){
1454 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_General_Product()"<<endl);
1457 if (GENERAL_DIMSCALE == this->gproduct_pattern){
1458 Add_Dim_Name_Dimscale_General_Product();
1461 else if (GENERAL_LATLON2D == this->gproduct_pattern)
1462 Add_Dim_Name_LatLon2D_General_Product();
1464 else if (GENERAL_LATLON1D == this->gproduct_pattern || GENERAL_LATLON_COOR_ATTR == this->gproduct_pattern)
1465 Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product();
1478 void GMFile::Check_General_Product_Pattern() {
1480 BESDEBUG(
"h5",
"Coming to Check_General_Product_Pattern()"<<endl);
1481 if(
false == Check_Dimscale_General_Product_Pattern()) {
1482 if(
false == Check_LatLon2D_General_Product_Pattern())
1483 if(
false == Check_LatLon1D_General_Product_Pattern())
1484 Check_LatLon_With_Coordinate_Attr_General_Product_Pattern();
1491 bool GMFile::Check_Dimscale_General_Product_Pattern() {
1493 BESDEBUG(
"h5",
"Coming to Check_Dimscale_General_Product_Pattern()"<<endl);
1494 bool ret_value =
false;
1495 bool has_dimlist =
false;
1496 bool has_dimscalelist =
false;
1499 for (vector<Var *>::iterator irv = this->
vars.begin();
1500 irv != this->vars.end(); ++irv) {
1501 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1502 ira != (*irv)->attrs.end();ira++) {
1503 if (
"DIMENSION_LIST" == (*ira)->name) {
1508 if (
true == has_dimlist)
1517 for (vector<Var *>::iterator irv = this->
vars.begin();
1518 irv != this->vars.end(); ++irv) {
1521 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1522 ira != (*irv)->attrs.end();ira++) {
1523 if (
"CLASS" == (*ira)->name) {
1525 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1527 class_value.resize((*ira)->value.size());
1528 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
1532 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
1533 has_dimscalelist =
true;
1539 if (
true == has_dimscalelist)
1544 if (
true == has_dimlist &&
true == has_dimscalelist) {
1545 this->gproduct_pattern = GENERAL_DIMSCALE;
1555 bool GMFile::Check_LatLon2D_General_Product_Pattern() {
1557 BESDEBUG(
"h5",
"Coming to Check_LatLon2D_General_Product_Pattern()"<<endl);
1558 bool ret_value =
false;
1560 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"latitude",
"longitude");
1561 if(
false == ret_value) {
1562 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"Latitude",
"Longitude");
1563 if(
false == ret_value) {
1564 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"lat",
"lon");
1565 if(
false == ret_value)
1566 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"cell_lat",
"cell_lon");
1571 if(
true == ret_value)
1572 this->gproduct_pattern = GENERAL_LATLON2D;
1579 bool GMFile::Check_LatLon2D_General_Product_Pattern_Name_Size(
const string & latname,
const string & lonname) {
1581 BESDEBUG(
"h5",
"Coming to Check_LatLon2D_General_Product_Pattern_Name_Size()"<<endl);
1582 bool ret_value =
false;
1583 bool ll_flag =
false;
1585 vector<size_t>lat_size(2,0);
1586 vector<size_t>lon_size(2,0);
1588 const string designed_group1 =
"/";
1589 const string designed_group2 =
"/Geolocation/";
1591 bool lat_flag_g1 =
false;
1592 bool lon_flag_g1 =
false;
1593 bool lat_flag_g2 =
false;
1594 bool lon_flag_g2 =
false;
1600 lat_flag_g1 = is_var_under_group(latname,designed_group1,2,lat_size);
1601 lon_flag_g1 = is_var_under_group(lonname,designed_group1,2,lon_size);
1602 if(lat_flag_g1 ==
true && lon_flag_g1 ==
true) {
1605 lat_flag_g2 = is_var_under_group(latname,designed_group2,2,lat_size);
1606 if(lat_flag_g2 ==
false) {
1607 lon_flag_g2 = is_var_under_group(lonname,designed_group2,2,lon_size);
1608 if(lon_flag_g2 ==
false)
1612 else if(lat_flag_g1 ==
false && lon_flag_g1 ==
false) {
1613 lat_flag_g2 = is_var_under_group(latname,designed_group2,2,lat_size);
1614 if(lat_flag_g2 ==
true) {
1615 lon_flag_g2 = is_var_under_group(lonname,designed_group2,2,lon_size);
1616 if(lon_flag_g2 ==
true)
1624 for (vector<Var *>::iterator irv = this->
vars.begin();
1625 irv != this->vars.end(); ++irv) {
1627 if((*irv)->rank == 2) {
1628 if((*irv)->name == latname) {
1631 string lat_path =HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1637 bool has_right_lat =
false;
1638 if(
"/" == lat_path ||
"/Geolocation/" == lat_path)
1639 if(
"/" == lat_path ||
"/Geolocation/" == lat_path) {
1641 lat_size[0] = (*irv)->getDimensions()[0]->size;
1642 lat_size[1] = (*irv)->getDimensions()[1]->size;
1646 else if((*irv)->name == lonname) {
1647 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1648 if(
"/" == lon_path ||
"/Geolocation/" == lon_path) {
1650 lon_size[0] = (*irv)->getDimensions()[0]->size;
1651 lon_size[1] = (*irv)->getDimensions()[1]->size;
1664 if(
true == ll_flag) {
1666 bool latlon_size_match =
true;
1667 for (
unsigned int size_index = 0; size_index <lat_size.size();size_index++) {
1668 if(lat_size[size_index] != lon_size[size_index]){
1669 latlon_size_match =
false;
1673 if (
true == latlon_size_match) {
1675 gp_latname = latname;
1676 gp_lonname = lonname;
1689 bool GMFile::Check_LatLon1D_General_Product_Pattern() {
1691 BESDEBUG(
"h5",
"Coming to Check_LatLon1D_General_Product_Pattern()"<<endl);
1692 bool ret_value =
false;
1694 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"latitude",
"longitude");
1695 if(
false == ret_value) {
1696 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"Latitude",
"Longitude");
1697 if(
false == ret_value) {
1698 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"lat",
"lon");
1699 if(
false == ret_value)
1700 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"cell_lat",
"cell_lon");
1704 if(
true == ret_value)
1705 this->gproduct_pattern = GENERAL_LATLON1D;
1712 bool GMFile::Check_LatLon1D_General_Product_Pattern_Name_Size(
const string & latname,
const string & lonname) {
1714 BESDEBUG(
"h5",
"Coming to Check_LatLon1D_General_Product_Pattern_Name_Size()"<<endl);
1715 bool ret_value =
false;
1717 size_t lat_size = 0;
1718 size_t lon_size = 0;
1720 for (vector<Var *>::iterator irv = this->
vars.begin();
1721 irv != this->vars.end(); ++irv) {
1723 if((*irv)->rank == 1) {
1724 if((*irv)->name == latname) {
1726 string lat_path =HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1730 if(
"/" == lat_path ||
"/Geolocation/" == lat_path) {
1732 lat_size = (*irv)->getDimensions()[0]->size;
1735 else if((*irv)->name == lonname) {
1736 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1737 if(
"/" == lon_path ||
"/Geolocation/" == lon_path) {
1739 lon_size = (*irv)->getDimensions()[0]->size;
1749 bool latlon_size_match_grid =
true;
1755 if(lat_size == lon_size) {
1758 latlon_size_match_grid =
false;
1762 for (vector<Var *>::iterator irv = this->
vars.begin();
1763 irv != this->vars.end(); ++irv) {
1764 if((*irv)->rank >=2) {
1765 short ll_size_flag = 0;
1766 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1767 ird != (*irv)->dims.end(); ++ird) {
1768 if(lat_size == (*ird)->size) {
1770 if(2 == ll_size_flag){
1775 if(2 == ll_size_flag) {
1776 latlon_size_match_grid =
true;
1785 if (
true == latlon_size_match_grid) {
1786 gp_latname = latname;
1787 gp_lonname = lonname;
1797 bool GMFile::Check_LatLon_With_Coordinate_Attr_General_Product_Pattern() {
1799 BESDEBUG(
"h5",
"Coming to Check_LatLon_With_Coordinate_Attr_General_Product_Pattern()"<<endl);
1800 bool ret_value =
false;
1801 string co_attrname =
"coordinates";
1802 string co_attrvalue=
"";
1803 string unit_attrname =
"units";
1804 string lat_unit_attrvalue =
"degrees_north";
1805 string lon_unit_attrvalue =
"degrees_east";
1807 bool coor_has_lat_flag =
false;
1808 bool coor_has_lon_flag =
false;
1810 vector<Var*> tempvar_lat;
1811 vector<Var*> tempvar_lon;
1814 for (vector<Var *>::iterator irv = this->
vars.begin();
1815 irv != this->vars.end(); ++irv) {
1816 if((*irv)->rank >=2) {
1817 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
1818 ira !=(*irv)->attrs.end();++ira) {
1822 if((*ira)->name == co_attrname) {
1823 Retrieve_H5_Attr_Value((*ira),(*irv)->fullpath);
1824 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
1825 vector<string> coord_values;
1827 HDF5CFUtil::Split_helper(coord_values,orig_attr_value,sep);
1829 for(vector<string>::iterator irs=coord_values.begin();irs!=coord_values.end();++irs) {
1830 string coord_value_suffix1;
1831 string coord_value_suffix2;
1832 string coord_value_suffix3;
1834 if((*irs).size() >=3) {
1837 coord_value_suffix1 = (*irs).substr((*irs).size()-3,3);
1840 if((*irs).size() >=8){
1841 coord_value_suffix2 = (*irs).substr((*irs).size()-8,8);
1842 if((*irs).size() >=9)
1843 coord_value_suffix3 = (*irs).substr((*irs).size()-9,9);
1848 if(coord_value_suffix1==
"lat" || coord_value_suffix2 ==
"latitude" || coord_value_suffix2 ==
"Latitude")
1849 coor_has_lat_flag =
true;
1850 else if(coord_value_suffix1==
"lon" || coord_value_suffix3 ==
"longitude" || coord_value_suffix3 ==
"Longitude")
1851 coor_has_lon_flag =
true;
1854 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag)
1858 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag)
1861 coor_has_lat_flag =
false;
1862 coor_has_lon_flag =
false;
1868 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag) {
1870 for (vector<Var *>::iterator irv = this->
vars.begin();
1871 irv != this->vars.end(); ++irv) {
1872 bool var_is_lat =
false;
1873 bool var_is_lon =
false;
1875 string varname = (*irv)->name;
1879 if(varname.size() >=3) {
1880 ll_ssuffix = varname.substr(varname.size()-3,3);
1881 if(varname.size() >=8) {
1882 ll_lsuffix1 = varname.substr(varname.size()-8,8);
1883 if(varname.size() >=9)
1884 ll_lsuffix2 = varname.substr(varname.size()-9,9);
1887 if(ll_ssuffix==
"lat" || ll_lsuffix1 ==
"latitude" || ll_lsuffix1 ==
"Latitude")
1889 else if(ll_ssuffix==
"lon" || ll_lsuffix2 ==
"longitude" || ll_lsuffix2 ==
"Longitude")
1893 if(
true == var_is_lat) {
1894 if((*irv)->rank > 0) {
1895 Var * lat =
new Var(*irv);
1896 tempvar_lat.push_back(lat);
1899 else if(
true == var_is_lon) {
1900 if((*irv)->rank >0) {
1901 Var * lon =
new Var(*irv);
1902 tempvar_lon.push_back(lon);
1912 for(vector<Var*>:: iterator irlat = tempvar_lat.begin(); irlat!=tempvar_lat.end();++irlat) {
1915 if((*irlat)->rank == 1)
1916 Build_lat1D_latlon_candidate(*irlat,tempvar_lon);
1919 else if((*irlat)->rank >1)
1920 Build_latg1D_latlon_candidate(*irlat,tempvar_lon);
1924 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
1925 cerr<<
"struct lat lon names are " <<(*ivs).name1 <<
" and " << (*ivs).name2 <<endl;
1932 Build_unique_latlon_candidate();
1946 if(latloncv_candidate_pairs.size() >0) {
1947 int num_1d_rank = 0;
1948 int num_2d_rank = 0;
1949 int num_g2d_rank = 0;
1950 vector<struct Name_Size_2Pairs> temp_1d_latlon_pairs;
1951 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin();
1952 ivs!=latloncv_candidate_pairs.end();++ivs) {
1953 if(1 == (*ivs).rank) {
1955 temp_1d_latlon_pairs.push_back(*ivs);
1957 else if(2 == (*ivs).rank)
1959 else if((*ivs).rank >2)
1964 if (num_2d_rank !=0)
1966 else if(num_1d_rank!=0) {
1970 for(vector<struct Name_Size_2Pairs>::iterator ivs=temp_1d_latlon_pairs.begin();
1971 ivs!=temp_1d_latlon_pairs.end();++ivs) {
1972 if((*ivs).size1 != (*ivs).size2) {
1983 for (vector<Var *>::iterator irv = this->
vars.begin();
1984 irv != this->vars.end(); ++irv) {
1985 if((*irv)->rank >=2) {
1986 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
1987 ira !=(*irv)->attrs.end();++ira) {
1989 if((*ira)->name == co_attrname) {
1990 Retrieve_H5_Attr_Value((*ira),(*irv)->fullpath);
1991 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
1992 vector<string> coord_values;
1994 HDF5CFUtil::Split_helper(coord_values,orig_attr_value,sep);
1995 bool has_lat_flag =
false;
1996 bool has_lon_flag =
false;
1997 for (vector<string>::iterator itcv=coord_values.begin();itcv!=coord_values.end();++itcv) {
1998 if((*ivs).name1 == (*itcv))
1999 has_lat_flag =
true;
2000 else if((*ivs).name2 == (*itcv))
2001 has_lon_flag =
true;
2004 if(
true == has_lat_flag &&
true == has_lon_flag) {
2005 short has_same_ll_size = 0;
2006 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();ird!=(*irv)->dims.end();++ird){
2007 if((*ird)->size == (*ivs).size1)
2010 if(has_same_ll_size!=2){
2017 if(
false == ret_value)
2022 if(
true == ret_value)
2029 release_standalone_var_vector(tempvar_lat);
2030 release_standalone_var_vector(tempvar_lon);
2034 if(
true == ret_value)
2035 cerr<<
"This product is the coordinate type "<<endl;
2038 if(
true == ret_value)
2039 this->gproduct_pattern = GENERAL_LATLON_COOR_ATTR;
2045 void GMFile::Build_lat1D_latlon_candidate(
Var *lat,
const vector<Var*> &lon_vec) {
2047 BESDEBUG(
"h5",
"Coming to Build_lat1D_latlon_candidate()"<<endl);
2048 set<string> lon_candidate_path;
2049 vector< pair<string,hsize_t> > lon_path_size_vec;
2052 for(vector<Var *>::const_iterator irlon = lon_vec.begin(); irlon!=lon_vec.end();++irlon) {
2054 if (lat->rank == (*irlon)->rank) {
2055 pair<string,hsize_t>lon_path_size;
2056 lon_path_size.first = (*irlon)->fullpath;
2057 lon_path_size.second = (*irlon)->getDimensions()[0]->size;
2058 lon_path_size_vec.push_back(lon_path_size);
2063 if(lon_path_size_vec.size() == 1) {
2066 latlon_pair.name1 = lat->fullpath;
2067 latlon_pair.name2 = lon_path_size_vec[0].first;
2069 latlon_pair.size2 = lon_path_size_vec[0].second;
2070 latlon_pair.rank = lat->rank;
2071 latloncv_candidate_pairs.push_back(latlon_pair);
2074 else if(lon_path_size_vec.size() >1) {
2078 string lat_path = HDF5CFUtil::obtain_string_before_lastslash(lat->fullpath);
2079 pair<string,hsize_t> lon_final_path_size;
2080 short num_lon_match = 0;
2081 for(vector <pair<string,hsize_t> >::iterator islon =lon_path_size_vec.begin();islon!=lon_path_size_vec.end();++islon) {
2083 if(HDF5CFUtil::obtain_string_before_lastslash((*islon).first)==lat_path) {
2085 if(1 == num_lon_match)
2086 lon_final_path_size = *islon;
2087 else if(num_lon_match > 1)
2091 if(num_lon_match ==1) {
2093 latlon_pair.name1 = lat->fullpath;
2094 latlon_pair.name2 = lon_final_path_size.first;
2096 latlon_pair.size2 = lon_final_path_size.second;
2097 latlon_pair.rank = lat->rank;
2098 latloncv_candidate_pairs.push_back(latlon_pair);
2105 void GMFile::Build_latg1D_latlon_candidate(
Var *lat,
const vector<Var*> & lon_vec) {
2107 BESDEBUG(
"h5",
"Coming to Build_latg1D_latlon_candidate()"<<endl);
2108 set<string> lon_candidate_path;
2111 for(vector<Var*>:: const_iterator irlon = lon_vec.begin(); irlon!=lon_vec.end();++irlon) {
2113 if (lat->rank == (*irlon)->rank) {
2116 bool same_dim =
true;
2117 for(
int dim_index = 0; dim_index <lat->rank; dim_index++) {
2119 (*irlon)->getDimensions()[dim_index]->size){
2124 if(
true == same_dim)
2125 lon_candidate_path.insert((*irlon)->fullpath);
2130 if(lon_candidate_path.size() > 1) {
2132 string lat_path = HDF5CFUtil::obtain_string_before_lastslash(lat->fullpath);
2133 vector <string> lon_final_candidate_path_vec;
2134 for(set<string>::iterator islon_path =lon_candidate_path.begin();islon_path!=lon_candidate_path.end();++islon_path) {
2137 if(HDF5CFUtil::obtain_string_before_lastslash(*islon_path)==lat_path)
2138 lon_final_candidate_path_vec.push_back(*islon_path);
2141 if(lon_final_candidate_path_vec.size() == 1) {
2145 latlon_pair.name1 = lat->fullpath;
2146 latlon_pair.name2 = lon_final_candidate_path_vec[0];
2149 latlon_pair.rank = lat->rank;
2150 latloncv_candidate_pairs.push_back(latlon_pair);
2152 else if(lon_final_candidate_path_vec.size() >1) {
2159 string lat_name = HDF5CFUtil::obtain_string_after_lastslash(lat->fullpath);
2160 string lat_name_prefix1;
2161 string lat_name_prefix2;
2164 if(lat_name.size() >3) {
2165 lat_name_prefix1 = lat_name.substr(0,lat_name.size()-3);
2166 if(lat_name.size() >8)
2167 lat_name_prefix2 = lat_name.substr(0,lat_name.size()-8);
2169 string lon_name_prefix1;
2170 string lon_name_prefix2;
2172 for(vector<string>::iterator ilon = lon_final_candidate_path_vec.begin(); ilon!=lon_final_candidate_path_vec.end();++ilon) {
2173 string lon_name = HDF5CFUtil::obtain_string_after_lastslash(*ilon);
2174 if(lon_name.size() >3) {
2175 lon_name_prefix1 = lon_name.substr(0,lon_name.size()-3);
2176 if(lon_name.size() >9)
2177 lon_name_prefix2 = lon_name.substr(0,lon_name.size()-9);
2179 if((lat_name_prefix1 !=
"" && lat_name_prefix1 == lon_name_prefix1) ||
2180 (lat_name_prefix2 !=
"" && lat_name_prefix2 == lon_name_prefix2)) {
2183 latlon_pair.name1 = lat->fullpath;
2184 latlon_pair.name2 = *ilon;
2187 latlon_pair.rank = lat->rank;
2188 latloncv_candidate_pairs.push_back(latlon_pair);
2195 else if(lon_candidate_path.size() == 1) {
2199 latlon_pair.name1 = lat->fullpath;
2200 latlon_pair.name2 = *(lon_candidate_path.begin());
2203 latlon_pair.rank = lat->rank;
2204 latloncv_candidate_pairs.push_back(latlon_pair);
2212 void GMFile::Build_unique_latlon_candidate() {
2214 BESDEBUG(
"h5",
"Coming to Build_unique_latlon_candidate()"<<endl);
2215 set<int> duplicate_index;
2216 for(
unsigned int i= 0; i<latloncv_candidate_pairs.size();i++) {
2217 for(
unsigned int j=i+1;j<latloncv_candidate_pairs.size();j++) {
2218 if(latloncv_candidate_pairs[i].name2 == latloncv_candidate_pairs[j].name2) {
2219 duplicate_index.insert(i);
2220 duplicate_index.insert(j);
2226 for(set<int>::reverse_iterator its= duplicate_index.rbegin();its!=duplicate_index.rend();++its) {
2227 latloncv_candidate_pairs[*its] = latloncv_candidate_pairs.back();
2228 latloncv_candidate_pairs.pop_back();
2235 bool GMFile::Check_LatLonName_General_Product(
int ll_rank) {
2237 if(ll_rank <1 || ll_rank >2)
2238 throw2(
"Only support rank = 1 or 2 lat/lon case for the general product. The current rank is ",ll_rank);
2239 bool ret_value =
false;
2240 size_t lat2D_dimsize0 = 0;
2241 size_t lat2D_dimsize1 = 0;
2242 size_t lon2D_dimsize0 = 0;
2243 size_t lon2D_dimsize1 = 0;
2246 vector<short>ll_flag(3,0);
2248 vector<size_t>lat_size;
2249 vector<size_t>lon_size;
2254 lat_size.assign(6,0);
2255 lon_size.assign(6,0);
2258 for (vector<Var *>::iterator irv = this->
vars.begin();
2259 irv != this->vars.end(); ++irv) {
2261 if((*irv)->rank == ll_rank) {
2262 if((*irv)->name ==
"lat") {
2265 lat_size[0] = (*irv)->getDimensions()[0]->size;
2266 lat_size[1] = (*irv)->getDimensions()[1]->size;
2271 else if((*irv)->name ==
"lon") {
2274 lon_size[0] = (*irv)->getDimensions()[0]->size;
2275 lon_size[1] = (*irv)->getDimensions()[1]->size;
2280 else if((*irv)->name ==
"latitude"){
2283 lat_size[2] = (*irv)->getDimensions()[0]->size;
2284 lat_size[3] = (*irv)->getDimensions()[1]->size;
2288 else if((*irv)->name ==
"longitude"){
2291 lon_size[2] = (*irv)->getDimensions()[0]->size;
2292 lon_size[3] = (*irv)->getDimensions()[1]->size;
2297 else if((*irv)->name ==
"Latitude"){
2300 lat_size[4] = (*irv)->getDimensions()[0]->size;
2301 lat_size[5] = (*irv)->getDimensions()[1]->size;
2306 else if((*irv)->name ==
"Longitude"){
2309 lon_size[4] = (*irv)->getDimensions()[0]->size;
2310 lon_size[5] = (*irv)->getDimensions()[1]->size;
2316 int total_llflag = 0;
2317 for (
int i = 0; i < ll_flag.size();i++)
2322 if(1 == total_llflag) {
2323 bool latlon_size_match =
true;
2325 for (
int size_index = 0; size_index <lat_size.size();size_index++) {
2326 if(lat_size[size_index] != lon_size[size_index]){
2327 latlon_size_match =
false;
2333 if(
true == latlon_size_match) {
2335 if(2 == ll_flag[0]) {
2339 else if ( 2 == ll_flag[1]) {
2340 gp_latname =
"latitude";
2341 gp_lonname =
"longitude";
2344 else if (2 == ll_flag[2]){
2345 gp_latname =
"Latitude";
2346 gp_lonname =
"Longitude";
2356 void GMFile::Add_Dim_Name_LatLon2D_General_Product() {
2358 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_LatLon2D_General_Product()"<<endl);
2361 size_t latdimsize0 = 0;
2362 size_t latdimsize1 = 0;
2365 for (vector<Var *>::iterator irv = this->
vars.begin();
2366 irv != this->vars.end(); ++irv) {
2368 set<hsize_t> fakedimsize;
2369 pair<set<hsize_t>::iterator,
bool> setsizeret;
2370 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2371 ird != (*irv)->dims.end(); ++ird) {
2372 Add_One_FakeDim_Name(*ird);
2373 setsizeret = fakedimsize.insert((*ird)->size);
2376 if (
false == setsizeret.second)
2377 Adjust_Duplicate_FakeDim_Name(*ird);
2382 if((*irv)->name == gp_latname) {
2383 if((*irv)->rank != 2) {
2384 throw4(
"coordinate variables ",gp_latname,
2385 " must have rank 2 for the 2-D latlon case , the current rank is ",
2388 latdimname0 = (*irv)->getDimensions()[0]->name;
2389 latdimsize0 = (*irv)->getDimensions()[0]->size;
2391 latdimname1 = (*irv)->getDimensions()[1]->name;
2392 latdimsize1 = (*irv)->getDimensions()[1]->size;
2399 for (vector<Var *>::iterator irv = this->
vars.begin();
2400 irv != this->vars.end(); ++irv) {
2401 int lat_dim0_index = 0;
2402 int lat_dim1_index = 0;
2403 bool has_lat_dims_size =
false;
2405 for (
unsigned int dim_index = 0; dim_index <(*irv)->dims.size(); dim_index++) {
2408 if(((*irv)->dims[dim_index])->size == latdimsize0) {
2411 lat_dim0_index = dim_index;
2412 for(
unsigned int dim_index2 = dim_index+1;dim_index2 < (*irv)->dims.size();dim_index2++) {
2413 if(((*irv)->dims[dim_index2])->size == latdimsize1) {
2414 lat_dim1_index = dim_index2;
2415 has_lat_dims_size =
true;
2420 if(
true == has_lat_dims_size)
2424 if(
true == has_lat_dims_size) {
2425 ((*irv)->dims[lat_dim0_index])->name = latdimname0;
2428 ((*irv)->dims[lat_dim1_index])->name = latdimname1;
2439 set<string>tempdimnamelist;
2441 for (vector<Var *>::iterator irv = this->
vars.begin();
2442 irv != this->
vars.end(); ++irv) {
2443 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2444 ird != (*irv)->dims.end(); ++ird)
2445 tempdimnamelist.insert((*ird)->name);
2450 set<string>finaldimnamelist;
2451 string finaldimname_base =
"FakeDim";
2453 for(
unsigned int i = 0; i<tempdimnamelist.size();i++) {
2454 stringstream sfakedimindex;
2456 string finaldimname = finaldimname_base + sfakedimindex.str();
2457 finaldimnamelist.insert(finaldimname);
2462 if(finaldimnamelist != tempdimnamelist) {
2463 map<string,string> tempdimname_to_finaldimname;
2464 set<string>:: iterator tempit = tempdimnamelist.begin();
2465 set<string>:: iterator finalit = finaldimnamelist.begin();
2466 while(tempit != tempdimnamelist.end()) {
2467 tempdimname_to_finaldimname[*tempit] = *finalit;
2473 for (vector<Var *>::iterator irv = this->
vars.begin();
2474 irv != this->
vars.end(); ++irv) {
2475 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2476 ird != (*irv)->dims.end(); ++ird) {
2477 if(tempdimname_to_finaldimname.find((*ird)->name) !=tempdimname_to_finaldimname.end()){
2478 (*ird)->name = tempdimname_to_finaldimname[(*ird)->name];
2481 throw3(
"The dimension names ",(*ird)->name,
"cannot be found in the dim. name list.");
2487 dimnamelist.clear();
2488 dimnamelist = finaldimnamelist;
2491 dimname_to_dimsize.clear();
2492 for (vector<Var *>::iterator irv = this->
vars.begin();
2493 irv != this->vars.end(); ++irv) {
2494 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2495 ird != (*irv)->dims.end(); ++ird) {
2496 if(finaldimnamelist.find((*ird)->name)!=finaldimnamelist.end()) {
2497 dimname_to_dimsize[(*ird)->name] = (*ird)->size;
2498 dimname_to_unlimited[(*ird)->name] = (*ird)->unlimited_dim;
2499 finaldimnamelist.erase((*ird)->name);
2503 if(
true == finaldimnamelist.empty())
2508 for (vector<Var *>::iterator irv = this->
vars.begin();
2509 irv != this->vars.end(); ++irv) {
2510 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2511 ird != (*irv)->dims.end(); ++ird) {
2512 (*ird)->newname = (*ird)->name;
2520 void GMFile::Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product() {
2522 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product()"<<endl);
2524 for (vector<Var *>::iterator irv = this->
vars.begin();
2525 irv != this->vars.end(); ++irv) {
2527 set<hsize_t> fakedimsize;
2528 pair<set<hsize_t>::iterator,
bool> setsizeret;
2529 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2530 ird != (*irv)->dims.end(); ++ird) {
2531 Add_One_FakeDim_Name(*ird);
2532 setsizeret = fakedimsize.insert((*ird)->size);
2534 if (
false == setsizeret.second)
2535 Adjust_Duplicate_FakeDim_Name(*ird);
2541 void GMFile::Add_Dim_Name_Dimscale_General_Product() {
2543 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Dimscale_General_Product()"<<endl);
2545 pair<set<string>::iterator,
bool> setret;
2546 this->iscoard =
true;
2548 for (vector<Var *>::iterator irv = this->
vars.begin();
2549 irv != this->vars.end(); ++irv) {
2552 Handle_UseDimscale_Var_Dim_Names_General_Product((*irv));
2555 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
2556 ird !=(*irv)->dims.end();++ird) {
2557 setret = dimnamelist.insert((*ird)->name);
2558 if (
true == setret.second)
2559 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
2563 if (
true == dimnamelist.empty())
2564 throw1(
"This product should have the dimension names, but no dimension names are found");
2569 void GMFile::Handle_UseDimscale_Var_Dim_Names_General_Product(
Var *var) {
2571 BESDEBUG(
"h5",
"Coming to Handle_UseDimscale_Var_Dim_Names_General_Product()"<<endl);
2573 bool has_dimlist =
false;
2574 bool has_dimclass =
false;
2576 for(vector<Attribute *>::iterator ira = var->attrs.begin();
2577 ira != var->attrs.end();ira++) {
2578 if (
"DIMENSION_LIST" == (*ira)->name) {
2582 if (
"CLASS" == (*ira)->name) {
2584 Retrieve_H5_Attr_Value(*ira,var->fullpath);
2586 class_value.resize((*ira)->value.size());
2587 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
2591 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2592 has_dimclass =
true;
2600 if (
true == has_dimlist)
2601 Add_UseDimscale_Var_Dim_Names_General_Product(var,dimlistattr);
2604 else if(
true == has_dimclass) {
2605 if (var->dims.size() !=1)
2606 throw2(
"Currently dimension scale dataset must be 1 dimension, this is not true for the dataset ",
2611 (var->dims)[0]->name = var->fullpath;
2612 (var->dims)[0]->newname = var->fullpath;
2613 pair<set<string>::iterator,
bool> setret;
2614 setret = dimnamelist.insert((var->dims)[0]->name);
2615 if (
true == setret.second)
2616 Insert_One_NameSizeMap_Element((var->dims)[0]->name,(var->dims)[0]->size,(var->dims)[0]->unlimited_dim);
2622 set<hsize_t> fakedimsize;
2623 pair<set<hsize_t>::iterator,
bool> setsizeret;
2624 for (vector<Dimension *>::iterator ird= var->dims.begin();
2625 ird != var->dims.end(); ++ird) {
2626 Add_One_FakeDim_Name(*ird);
2627 setsizeret = fakedimsize.insert((*ird)->size);
2629 if (
false == setsizeret.second)
2630 Adjust_Duplicate_FakeDim_Name(*ird);
2637 void GMFile::Add_UseDimscale_Var_Dim_Names_General_Product(
Var *var,
Attribute*dimlistattr)
2640 BESDEBUG(
"h5",
"Coming to Add_UseDimscale_Var_Dim_Names_General_Product()"<<endl);
2641 ssize_t objnamelen = -1;
2644 vector<hvl_t> vlbuf;
2648 hid_t atype_id = -1;
2649 hid_t amemtype_id = -1;
2650 hid_t aspace_id = -1;
2651 hid_t ref_dset = -1;
2653 if(NULL == dimlistattr)
2654 throw2(
"Cannot obtain the dimension list attribute for variable ",var->name);
2656 else if (0==var->rank)
2657 throw2(
"The number of dimension should NOT be 0 for the variable ",var->name);
2662 vlbuf.resize(var->rank);
2664 dset_id = H5Dopen(this->fileid,(var->fullpath).c_str(),H5P_DEFAULT);
2666 throw2(
"Cannot open the dataset ",var->fullpath);
2668 attr_id = H5Aopen(dset_id,(dimlistattr->name).c_str(),H5P_DEFAULT);
2670 throw4(
"Cannot open the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
2672 atype_id = H5Aget_type(attr_id);
2674 throw4(
"Cannot obtain the datatype of the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
2676 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
2678 if (amemtype_id < 0)
2679 throw2(
"Cannot obtain the memory datatype for the attribute ",dimlistattr->name);
2682 if (H5Aread(attr_id,amemtype_id,&vlbuf[0]) <0)
2683 throw2(
"Cannot obtain the referenced object for the variable ",var->name);
2686 vector<char> objname;
2687 int vlbuf_index = 0;
2690 for (vector<Dimension *>::iterator ird = var->dims.begin();
2691 ird != var->dims.end(); ++ird) {
2693 if(vlbuf[vlbuf_index].p== NULL)
2694 throw4(
"The dimension doesn't exist. Var name is ",var->name,
"; the dimension index is ",vlbuf_index);
2695 rbuf =((hobj_ref_t*)vlbuf[vlbuf_index].p)[0];
2696 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0)
2697 throw2(
"Cannot dereference from the DIMENSION_LIST attribute for the variable ",var->name);
2699 if ((objnamelen= H5Iget_name(ref_dset,NULL,0))<=0)
2700 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
2701 objname.resize(objnamelen+1);
2702 if ((objnamelen= H5Iget_name(ref_dset,&objname[0],objnamelen+1))<=0)
2703 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
2705 string objname_str = string(objname.begin(),objname.end());
2711 string trim_objname = objname_str.substr(0,objnamelen);
2712 (*ird)->name = string(trim_objname.begin(),trim_objname.end());
2714 pair<set<string>::iterator,
bool> setret;
2715 setret = dimnamelist.insert((*ird)->name);
2716 if (
true == setret.second)
2717 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
2718 (*ird)->newname = (*ird)->name;
2726 if(vlbuf.size()!= 0) {
2728 if ((aspace_id = H5Aget_space(attr_id)) < 0)
2729 throw2(
"Cannot get hdf5 dataspace id for the attribute ",dimlistattr->name);
2731 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)&vlbuf[0])<0)
2732 throw2(
"Cannot successfully clean up the variable length memory for the variable ",var->name);
2734 H5Sclose(aspace_id);
2739 H5Tclose(amemtype_id);
2749 if(amemtype_id != -1)
2750 H5Tclose(amemtype_id);
2753 H5Sclose(aspace_id);
2770 BESDEBUG(
"h5",
"GMFile:: Coming to Handle_CVar()"<<endl);
2776 if (General_Product == this->product_type ||
2777 ACOS_L2S_OR_OCO2_L1B == this->product_type) {
2778 if (GENERAL_DIMSCALE == this->gproduct_pattern)
2779 Handle_CVar_Dimscale_General_Product();
2780 else if (GENERAL_LATLON1D == this->gproduct_pattern)
2781 Handle_CVar_LatLon1D_General_Product();
2782 else if (GENERAL_LATLON2D == this->gproduct_pattern)
2783 Handle_CVar_LatLon2D_General_Product();
2787 else if (Mea_SeaWiFS_L2 == this->product_type ||
2788 Mea_SeaWiFS_L3 == this->product_type)
2789 Handle_CVar_Mea_SeaWiFS();
2790 else if (Aqu_L3 == this->product_type)
2791 Handle_CVar_Aqu_L3();
2792 else if (OBPG_L3 == this->product_type)
2793 Handle_CVar_OBPG_L3();
2794 else if (OSMAPL2S == this->product_type)
2795 Handle_CVar_OSMAPL2S();
2796 else if (Mea_Ozone == this->product_type)
2797 Handle_CVar_Mea_Ozone();
2798 else if (GPMS_L3 == this->product_type || GPMM_L3 == this->product_type)
2799 Handle_CVar_GPM_L3();
2800 else if (GPM_L1 == this->product_type)
2801 Handle_CVar_GPM_L1();
2805 void GMFile::Handle_CVar_GPM_L1() {
2807 BESDEBUG(
"h5",
"Coming to Handle_CVar_GPM_L1()"<<endl);
2810 for (vector<Var *>::iterator irv = this->
vars.begin();
2811 irv != this->vars.end(); ++irv) {
2812 if((*irv)->name==
"AlgorithmRuntimeInfo") {
2814 this->
vars.erase(irv);
2827 set<string> ll_dim_set;
2828 for (vector<Var *>::iterator irv = this->
vars.begin();
2829 irv != this->vars.end(); ) {
2830 if((*irv)->rank == 2 && (*irv)->name ==
"Latitude") {
2832 size_t lat_pos = (*irv)->fullpath.rfind(
"Latitude");
2833 string lat_path = (*irv)->fullpath.substr(0,lat_pos);
2834 GMcvar->cfdimname = lat_path + ((*irv)->dims)[0]->name;
2835 ll_dim_set.insert(((*irv)->dims)[0]->name);
2836 GMcvar->cvartype = CV_EXIST;
2837 GMcvar->product_type = product_type;
2838 this->cvars.push_back(GMcvar);
2840 irv = this->
vars.erase(irv);
2843 if((*irv)->rank == 2 && (*irv)->name ==
"Longitude") {
2845 size_t lon_pos = (*irv)->fullpath.rfind(
"Longitude");
2846 string lon_path = (*irv)->fullpath.substr(0,lon_pos);
2847 GMcvar->cfdimname = lon_path + ((*irv)->dims)[1]->name;
2848 ll_dim_set.insert(((*irv)->dims)[1]->name);
2849 GMcvar->cvartype = CV_EXIST;
2850 GMcvar->product_type = product_type;
2851 this->cvars.push_back(GMcvar);
2853 irv = this->
vars.erase(irv);
2862 set<string> cvdimset;
2863 pair<set<string>::iterator,
bool> setret;
2864 for (vector<Var *>::iterator irv = this->
vars.begin();
2865 irv != this->
vars.end(); ++irv) {
2866 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();
2867 ird != (*irv)->dims.end(); ++ird) {
2868 setret = cvdimset.insert((*ird)->name);
2869 cerr<<
"var name is "<<(*irv)->fullpath <<endl;
2870 if (
true == setret.second) {
2871 cerr<<
"dim name is "<<(*ird)->name <<endl;
2872 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size);
2881 for (map<string,hsize_t>::const_iterator itd = dimname_to_dimsize.begin();
2882 itd!=dimname_to_dimsize.end();++itd) {
2885 if((ll_dim_set.find(itd->first)) == ll_dim_set.end()) {
2887 Create_Missing_CV(GMcvar,itd->first);
2888 this->cvars.push_back(GMcvar);
2895 void GMFile::Handle_CVar_GPM_L3() {
2897 BESDEBUG(
"h5",
"Coming to Handle_CVar_GPM_L3()"<<endl);
2902 for (map<string,hsize_t>::const_iterator itd = dimname_to_dimsize.begin();
2903 itd!=dimname_to_dimsize.end();++itd) {
2906 if(
"nlon" == itd->first ||
"nlat" == itd->first
2907 ||
"lnH" == itd->first ||
"ltH" == itd->first
2908 ||
"lnL" == itd->first ||
"ltL" == itd->first) {
2909 GMcvar->name = itd->first;
2910 GMcvar->newname = GMcvar->name;
2911 GMcvar->fullpath = GMcvar->name;
2913 GMcvar->dtype = H5FLOAT32;
2915 gmcvar_dim->name = GMcvar->name;
2916 gmcvar_dim->newname = gmcvar_dim->name;
2917 GMcvar->dims.push_back(gmcvar_dim);
2918 GMcvar->cfdimname = gmcvar_dim->name;
2919 if (
"nlat" ==GMcvar->name ||
"ltH" == GMcvar->name
2920 ||
"ltL" == GMcvar->name)
2921 GMcvar->cvartype = CV_LAT_MISS;
2922 else if (
"nlon" == GMcvar->name ||
"lnH" == GMcvar->name
2923 ||
"lnL" == GMcvar->name)
2924 GMcvar->cvartype = CV_LON_MISS;
2925 GMcvar->product_type = product_type;
2927 else if ((
"nlayer" == itd->first && (28 == itd->second || 19 == itd->second)) ||
2928 (
"hgt" == itd->first && 5 == itd->second) ||
2929 (
"nalt" == itd->first && 5 == itd->second)){
2930 GMcvar->name = itd->first;
2931 GMcvar->newname = GMcvar->name;
2932 GMcvar->fullpath = GMcvar->name;
2934 GMcvar->dtype = H5FLOAT32;
2936 gmcvar_dim->name = GMcvar->name;
2937 gmcvar_dim->newname = gmcvar_dim->name;
2938 GMcvar->dims.push_back(gmcvar_dim);
2939 GMcvar->cfdimname = gmcvar_dim->name;
2940 GMcvar->cvartype = CV_SPECIAL;
2941 GMcvar->product_type = product_type;
2944 Create_Missing_CV(GMcvar,itd->first);
2945 this->cvars.push_back(GMcvar);
2950 void GMFile::Handle_CVar_Mea_SeaWiFS() {
2952 BESDEBUG(
"h5",
"Coming to Handle_CVar_Mea_SeaWiFS()"<<endl);
2953 pair<set<string>::iterator,
bool> setret;
2954 set<string>tempdimnamelist = dimnamelist;
2956 for (set<string>::iterator irs = dimnamelist.begin();
2957 irs != dimnamelist.end();++irs) {
2958 for (vector<Var *>::iterator irv = this->
vars.begin();
2959 irv != this->vars.end(); ) {
2960 if ((*irs)== (*irv)->fullpath) {
2962 if (!iscoard && ((
"/natrack" == (*irs))
2963 ||
"/nxtrack" == (*irs))) {
2968 if((*irv)->dims.size()!=1)
2969 throw3(
"Coard coordinate variable ",(*irv)->name,
"is not 1D");
2972 tempdimnamelist.erase(*irs);
2974 GMcvar->cfdimname = *irs;
2975 GMcvar->cvartype = CV_EXIST;
2976 GMcvar->product_type = product_type;
2977 this->cvars.push_back(GMcvar);
2979 irv = this->
vars.erase(irv);
2982 else if(
false == iscoard) {
2985 if ((((*irs) ==
"/natrack") && ((*irv)->fullpath ==
"/latitude"))
2986 ||(((*irs) ==
"/nxtrack") && ((*irv)->fullpath ==
"/longitude"))) {
2987 tempdimnamelist.erase(*irs);
2989 GMcvar->cfdimname = *irs;
2990 GMcvar->cvartype = CV_EXIST;
2991 GMcvar->product_type = product_type;
2992 this->cvars.push_back(GMcvar);
2994 irv = this->
vars.erase(irv);
3010 for (set<string>::iterator irs = tempdimnamelist.begin();
3011 irs != tempdimnamelist.end();++irs) {
3013 Create_Missing_CV(GMcvar,*irs);
3014 this->cvars.push_back(GMcvar);
3019 void GMFile::Handle_CVar_OSMAPL2S() {
3021 BESDEBUG(
"h5",
"Coming to Handle_CVar_OSMAPL2S()"<<endl);
3022 pair<set<string>::iterator,
bool> setret;
3023 set<string>tempdimnamelist = dimnamelist;
3025 string key0 =
"_lat";
3026 string key1 =
"_lon";
3027 string osmapl2sdim0 =
"YDim";
3028 string osmapl2sdim1 =
"XDim";
3030 bool foundkey0 =
false;
3031 bool foundkey1 =
false;
3035 for (vector<Var *>::iterator irv = this->
vars.begin();
3036 irv != this->vars.end(); ) {
3038 tempvarname = (*irv)->name;
3040 if ((tempvarname.size() > key0.size())&&
3041 (key0 == tempvarname.substr(tempvarname.size()-key0.size(),key0.size()))){
3045 if (dimnamelist.find(osmapl2sdim0)== dimnamelist.end())
3046 throw5(
"variable ",tempvarname,
" must have dimension ",osmapl2sdim0,
" , but not found ");
3048 tempdimnamelist.erase(osmapl2sdim0);
3050 GMcvar->newname = GMcvar->name;
3051 GMcvar->cfdimname = osmapl2sdim0;
3052 GMcvar->cvartype = CV_EXIST;
3053 GMcvar->product_type = product_type;
3054 this->cvars.push_back(GMcvar);
3056 irv = this->
vars.erase(irv);
3059 else if ((tempvarname.size() > key1.size())&&
3060 (key1 == tempvarname.substr(tempvarname.size()-key1.size(),key1.size()))){
3064 if (dimnamelist.find(osmapl2sdim1)== dimnamelist.end())
3065 throw5(
"variable ",tempvarname,
" must have dimension ",osmapl2sdim1,
" , but not found ");
3067 tempdimnamelist.erase(osmapl2sdim1);
3070 GMcvar->newname = GMcvar->name;
3071 GMcvar->cfdimname = osmapl2sdim1;
3072 GMcvar->cvartype = CV_EXIST;
3073 GMcvar->product_type = product_type;
3074 this->cvars.push_back(GMcvar);
3076 irv = this->
vars.erase(irv);
3081 if (
true == foundkey0 &&
true == foundkey1)
3085 for (set<string>::iterator irs = tempdimnamelist.begin();
3086 irs != tempdimnamelist.end();++irs) {
3089 Create_Missing_CV(GMcvar,*irs);
3090 this->cvars.push_back(GMcvar);
3096 void GMFile::Handle_CVar_Aqu_L3() {
3098 BESDEBUG(
"h5",
"Coming to Handle_CVar_Aqu_L3()"<<endl);
3100 for (vector<Var *>::iterator irv = this->
vars.begin();
3101 irv != this->vars.end(); ++irv) {
3103 if (
"l3m_data" == (*irv)->name) {
3104 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
3105 ird != (*irv)->dims.end(); ++ird) {
3107 GMcvar->name = (*ird)->name;
3108 GMcvar->newname = GMcvar->name;
3109 GMcvar->fullpath = GMcvar->name;
3111 GMcvar->dtype = H5FLOAT32;
3113 gmcvar_dim->name = GMcvar->name;
3114 gmcvar_dim->newname = gmcvar_dim->name;
3115 GMcvar->dims.push_back(gmcvar_dim);
3116 GMcvar->cfdimname = gmcvar_dim->name;
3117 if (
"lat" ==GMcvar->name ) GMcvar->cvartype = CV_LAT_MISS;
3118 if (
"lon" == GMcvar->name ) GMcvar->cvartype = CV_LON_MISS;
3119 GMcvar->product_type = product_type;
3120 this->cvars.push_back(GMcvar);
3128 void GMFile::Handle_CVar_Mea_Ozone() {
3130 BESDEBUG(
"h5",
"Coming to Handle_CVar_Mea_Ozone()"<<endl);
3131 pair<set<string>::iterator,
bool> setret;
3132 set<string>tempdimnamelist = dimnamelist;
3134 if(
false == iscoard)
3135 throw1(
"Measure Ozone level 3 zonal average product must follow COARDS conventions");
3137 for (set<string>::iterator irs = dimnamelist.begin();
3138 irs != dimnamelist.end();++irs) {
3139 for (vector<Var *>::iterator irv = this->
vars.begin();
3140 irv != this->vars.end(); ) {
3141 if ((*irs)== (*irv)->fullpath) {
3143 if((*irv)->dims.size()!=1)
3144 throw3(
"Coard coordinate variable",(*irv)->name,
"is not 1D");
3147 tempdimnamelist.erase(*irs);
3149 GMcvar->cfdimname = *irs;
3150 GMcvar->cvartype = CV_EXIST;
3151 GMcvar->product_type = product_type;
3152 this->cvars.push_back(GMcvar);
3154 irv = this->
vars.erase(irv);
3162 for (set<string>::iterator irs = tempdimnamelist.begin();
3163 irs != tempdimnamelist.end();irs++) {
3166 Create_Missing_CV(GMcvar,*irs);
3167 this->cvars.push_back(GMcvar);
3172 void GMFile::Handle_CVar_Dimscale_General_Product() {
3174 BESDEBUG(
"h5",
"Coming to Handle_CVar_Dimscale_General_Product"<<endl);
3175 pair<set<string>::iterator,
bool> setret;
3176 set<string>tempdimnamelist = dimnamelist;
3178 for (set<string>::iterator irs = dimnamelist.begin();
3179 irs != dimnamelist.end();++irs) {
3180 for (vector<Var *>::iterator irv = this->
vars.begin();
3181 irv != this->vars.end(); ) {
3184 if ((*irs)== (*irv)->fullpath) {
3185 if((*irv)->dims.size()!=1)
3186 throw3(
"COARDS coordinate variable",(*irv)->name,
"is not 1D");
3189 tempdimnamelist.erase(*irs);
3191 GMcvar->cfdimname = *irs;
3194 bool is_netcdf_dimension = Is_netCDF_Dimension(*irv);
3198 if (
true == is_netcdf_dimension)
3199 GMcvar->cvartype = CV_FILLINDEX;
3201 GMcvar->cvartype = CV_EXIST;
3202 GMcvar->product_type = product_type;
3203 this->cvars.push_back(GMcvar);
3205 irv = this->
vars.erase(irv);
3214 Update_M2DLatLon_Dimscale_CVs();
3217 for (set<string>::iterator irs = tempdimnamelist.begin();
3218 irs != tempdimnamelist.end();irs++) {
3220 Create_Missing_CV(GMcvar,*irs);
3221 this->cvars.push_back(GMcvar);
3227 for (set<string>::iterator irs = dimnamelist.begin();
3228 irs != dimnamelist.end();irs++) {
3229 cerr<<
"dimension name is "<<(*irs)<<endl;
3238 void GMFile::Update_M2DLatLon_Dimscale_CVs() {
3240 BESDEBUG(
"h5",
"Coming to Update_M2DLatLon_Dimscale_CVs()"<<endl);
3242 if(
false == Check_1DGeolocation_Dimscale()) {
3245 vector<GMCVar*> tempcvar_1dlat;
3246 vector<GMCVar*> tempcvar_1dlon;
3249 Obtain_1DLatLon_CVs(tempcvar_1dlat,tempcvar_1dlon);
3252 vector<Var*> tempcvar_2dlat;
3253 vector<Var*> tempcvar_2dlon;
3259 map<string,int> latlon2d_path_to_index;
3262 Obtain_2DLatLon_Vars(tempcvar_2dlat,tempcvar_2dlon,latlon2d_path_to_index);
3265 for(vector<GMCVar *>::iterator irv = tempcvar_1dlat.begin();irv != tempcvar_1dlat.end();++irv)
3266 cerr<<
"1-D lat variable full path is "<<(*irv)->fullpath <<endl;
3267 for(vector<GMCVar *>::iterator irv = tempcvar_1dlon.begin();irv != tempcvar_1dlon.end();++irv)
3268 cerr<<
"1-D lon variable full path is "<<(*irv)->fullpath <<endl;
3270 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3271 cerr<<
"2-D lat variable full path is "<<(*irv)->fullpath <<endl;
3272 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3273 cerr<<
"2-D lon variable full path is "<<(*irv)->fullpath <<endl;
3277 Obtain_2DLLVars_With_Dims_not_1DLLCVars(tempcvar_2dlat,tempcvar_2dlon,tempcvar_1dlat,tempcvar_1dlon,latlon2d_path_to_index);
3280 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3281 cerr<<
"2-D Left lat variable full path is "<<(*irv)->fullpath <<endl;
3282 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3283 cerr<<
"2-D Left lon variable full path is "<<(*irv)->fullpath <<endl;
3288 Obtain_2DLLCVar_Candidate(tempcvar_2dlat,tempcvar_2dlon,latlon2d_path_to_index);
3291 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3292 cerr<<
"Final candidate 2-D Left lat variable full path is "<<(*irv)->fullpath <<endl;
3293 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3294 cerr<<
"Final candidate 2-D Left lon variable full path is "<<(*irv)->fullpath <<endl;
3299 vector<int> var2d_index;
3300 for (map<string,int>::const_iterator it= latlon2d_path_to_index.begin();it!=latlon2d_path_to_index.end();++it)
3301 var2d_index.push_back(it->second);
3303 Remove_2DLLCVar_Final_Candidate_from_Vars(var2d_index);
3306 if(tempcvar_2dlat.size()>0)
3311 set<string>dim_names_2d_cvs;
3313 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv){
3317 dim_names_2d_cvs.insert(lat->cfdimname);
3318 lat->cvartype = CV_EXIST;
3319 lat->product_type = product_type;
3320 this->cvars.push_back(lat);
3322 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv){
3326 dim_names_2d_cvs.insert(lon->cfdimname);
3327 lon->cvartype = CV_EXIST;
3328 lon->product_type = product_type;
3329 this->cvars.push_back(lon);
3335 for(vector<GMCVar*>::iterator ircv= this->cvars.begin();ircv !=this->cvars.end();) {
3336 if(1 == (*ircv)->rank) {
3337 if(dim_names_2d_cvs.find((*ircv)->cfdimname)!=dim_names_2d_cvs.end()) {
3338 if(CV_FILLINDEX == (*ircv)->cvartype) {
3340 ircv = this->cvars.erase(ircv);
3342 else if(CV_EXIST == (*ircv)->cvartype) {
3345 Var *var =
new Var(*ircv);
3346 this->
vars.push_back(var);
3350 ircv = this->cvars.erase(ircv);
3354 if(CV_LAT_MISS == (*ircv)->cvartype)
3355 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_LAT_MISS");
3356 else if(CV_LON_MISS == (*ircv)->cvartype)
3357 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_LON_MISS");
3358 else if(CV_NONLATLON_MISS == (*ircv)->cvartype)
3359 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_NONLATLON_MISS");
3360 else if(CV_MODIFY == (*ircv)->cvartype)
3361 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_MODIFY");
3362 else if(CV_SPECIAL == (*ircv)->cvartype)
3363 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_SPECIAL");
3365 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_UNSUPPORTED");
3382 for(set<string>::iterator irs = grp_cv_paths.begin();irs != grp_cv_paths.end();++irs) {
3383 cerr<<
"group path is "<< (*irs)<<endl;
3390 cerr<<
"File name is "<< this->path <<endl;
3391 cerr<<
"CV names are the following "<<endl;
3392 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i)
3393 cerr<<(*i)->fullpath <<endl;
3398 release_standalone_GMCVar_vector(tempcvar_1dlat);
3399 release_standalone_GMCVar_vector(tempcvar_1dlon);
3400 release_standalone_var_vector(tempcvar_2dlat);
3401 release_standalone_var_vector(tempcvar_2dlon);
3404 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i)
3405 cerr<<(*i)->fullpath <<endl;
3412 bool GMFile::Check_1DGeolocation_Dimscale() {
3414 BESDEBUG(
"h5",
"Coming to Check_1DGeolocation_Dimscale()"<<endl);
3415 bool has_only_1d_geolocation_cv =
false;
3416 bool has_1d_lat_cv_flag =
false;
3417 bool has_1d_lon_cv_flag =
false;
3420 hsize_t lat_size = 0;
3423 hsize_t lon_size = 0;
3426 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
3427 ircv != this->cvars.end(); ++ircv) {
3429 if((*ircv)->cvartype == CV_EXIST) {
3430 string attr_name =
"units";
3431 string lat_unit_value =
"degrees_north";
3432 string lon_unit_value =
"degrees_east";
3434 for(vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
3435 ira != (*ircv)->attrs.end();ira++) {
3437 if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) {
3438 lat_size = (*ircv)->getDimensions()[0]->size;
3439 lat_dimname = (*ircv)->getDimensions()[0]->name;
3440 has_1d_lat_cv_flag =
true;
3443 else if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value)){
3444 lon_size = (*ircv)->getDimensions()[0]->size;
3445 lon_dimname = (*ircv)->getDimensions()[0]->name;
3446 has_1d_lon_cv_flag =
true;
3455 if(
true == has_1d_lat_cv_flag ) {
3457 if(
true == has_1d_lon_cv_flag) {
3460 if(0 == this->
groups.size()) {
3464 if(lat_size == lon_size) {
3465 bool var_has_latdim =
false;
3466 bool var_has_londim =
false;
3467 for (vector<Var *>::iterator irv = this->
vars.begin();
3468 irv != this->vars.end(); ++irv) {
3469 if((*irv)->rank >= 2) {
3470 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
3471 ird !=(*irv)->dims.end();++ird) {
3472 if((*ird)->name == lat_dimname)
3473 var_has_latdim =
true;
3474 else if((*ird)->name == lon_dimname)
3475 var_has_londim =
true;
3477 if(
true == var_has_latdim &&
true == var_has_londim) {
3478 has_only_1d_geolocation_cv =
true;
3482 var_has_latdim =
false;
3483 var_has_londim =
false;
3489 has_only_1d_geolocation_cv =
true;
3493 bool has_2d_latname_flag =
false;
3494 bool has_2d_lonname_flag =
false;
3495 for (vector<Var *>::iterator irv = this->
vars.begin();
3496 irv != this->vars.end(); ++irv) {
3497 if((*irv)->rank == 2) {
3500 if(
true == Is_geolatlon((*irv)->name,
true))
3501 has_2d_latname_flag =
true;
3504 else if(
true == Is_geolatlon((*irv)->name,
false))
3505 has_2d_lonname_flag =
true;
3507 if((
true == has_2d_latname_flag) && (
true == has_2d_lonname_flag))
3512 if(has_2d_latname_flag !=
true || has_2d_lonname_flag !=
true) {
3515 has_2d_latname_flag =
false;
3516 has_2d_lonname_flag =
false;
3518 for (vector<Var *>::iterator irv = this->
vars.begin();
3519 irv != this->vars.end(); ++irv) {
3520 if((*irv)->rank == 2) {
3521 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
3522 ira != (*irv)->attrs.end(); ++ira) {
3524 if (
false == has_2d_latname_flag) {
3527 has_2d_latname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
true);
3528 if(
true == has_2d_latname_flag)
3530 else if(
false == has_2d_lonname_flag) {
3533 has_2d_lonname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
false);
3534 if(
true == has_2d_lonname_flag)
3538 else if(
false == has_2d_lonname_flag) {
3542 has_2d_lonname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
false);
3543 if(
true == has_2d_lonname_flag)
3547 if(
true == has_2d_latname_flag &&
true == has_2d_lonname_flag)
3554 if(has_2d_latname_flag !=
true || has_2d_lonname_flag !=
true)
3555 has_only_1d_geolocation_cv =
true;
3560 has_only_1d_geolocation_cv =
true;
3566 if(has_only_1d_geolocation_cv ==
true)
3567 cerr <<
"has only 1D lat/lon CVs. "<<endl;
3569 cerr<<
"Possibly has 2D lat/lon CVs. "<<endl;
3572 return has_only_1d_geolocation_cv;
3578 void GMFile::Obtain_1DLatLon_CVs(vector<GMCVar*> &cvar_1dlat,vector<GMCVar*> &cvar_1dlon) {
3580 BESDEBUG(
"h5",
"Coming to Obtain_1DLatLon_CVs()"<<endl);
3581 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
3582 ircv != this->cvars.end(); ++ircv) {
3584 if((*ircv)->cvartype == CV_EXIST) {
3586 string attr_name =
"units";
3587 string lat_unit_value =
"degrees_north";
3588 string lon_unit_value =
"degrees_east";
3590 for(vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
3591 ira != (*ircv)->attrs.end();ira++) {
3594 if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) {
3597 lat->cvartype = (*ircv)->cvartype;
3598 lat->product_type = (*ircv)->product_type;
3599 cvar_1dlat.push_back(lat);
3602 else if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value)){
3605 lon->cvartype = (*ircv)->cvartype;
3606 lon->product_type = (*ircv)->product_type;
3607 cvar_1dlon.push_back(lon);
3618 void GMFile::Obtain_2DLatLon_Vars(vector<Var*> &var_2dlat,vector<Var*> &var_2dlon,map<string,int> & latlon2d_path_to_index) {
3620 BESDEBUG(
"h5",
"Coming to Obtain_2DLatLon_Vars()"<<endl);
3621 for (vector<Var *>::iterator irv = this->
vars.begin();
3622 irv != this->vars.end(); ++irv) {
3623 if((*irv)->rank == 2) {
3626 if(
true == Is_geolatlon((*irv)->name,
true)) {
3627 Var *lat =
new Var(*irv);
3628 var_2dlat.push_back(lat);
3629 latlon2d_path_to_index[(*irv)->fullpath]= distance(this->
vars.begin(),irv);
3634 bool has_2dlat =
false;
3635 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
3636 ira != (*irv)->attrs.end(); ++ira) {
3639 if(
true == has_latlon_cf_units((*ira),(*irv)->fullpath,
true)) {
3640 Var *lat =
new Var(*irv);
3641 var_2dlat.push_back(lat);
3642 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3648 if(
true == has_2dlat)
3653 if(
true == Is_geolatlon((*irv)->name,
false)) {
3654 Var *lon =
new Var(*irv);
3655 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3656 var_2dlon.push_back(lon);
3659 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
3660 ira != (*irv)->attrs.end(); ++ira) {
3663 if(
true == has_latlon_cf_units((*ira),(*irv)->fullpath,
false)) {
3664 Var *lon =
new Var(*irv);
3665 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3666 var_2dlon.push_back(lon);
3677 void GMFile::Obtain_2DLLVars_With_Dims_not_1DLLCVars(vector<Var*> &var_2dlat,
3678 vector<Var*> &var_2dlon,
3679 vector<GMCVar*> &cvar_1dlat,
3680 vector<GMCVar*> &cvar_1dlon,
3681 map<string,int> &latlon2d_path_to_index) {
3683 BESDEBUG(
"h5",
"Coming to Obtain_2DLLVars_With_Dims_not_1DLLCVars()"<<endl);
3685 for(vector<Var *>::iterator irv = var_2dlat.begin();irv != var_2dlat.end();) {
3686 bool remove_2dlat =
false;
3687 for(vector<GMCVar *>::iterator ircv = cvar_1dlat.begin();ircv != cvar_1dlat.end();++ircv) {
3688 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
3689 ird!=(*irv)->dims.end(); ++ird) {
3690 if((*ird)->name == (*ircv)->getDimensions()[0]->name &&
3691 (*ird)->size == (*ircv)->getDimensions()[0]->size) {
3692 latlon2d_path_to_index.erase((*irv)->fullpath);
3694 irv = var_2dlat.erase(irv);
3695 remove_2dlat =
true;
3699 if(
true == remove_2dlat)
3703 if(
false == remove_2dlat)
3708 for(vector<Var *>::iterator irv = var_2dlon.begin();irv != var_2dlon.end();) {
3709 bool remove_2dlon =
false;
3710 for(vector<GMCVar *>::iterator ircv = cvar_1dlon.begin();ircv != cvar_1dlon.end();++ircv) {
3711 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
3712 ird!=(*irv)->dims.end(); ++ird) {
3713 if((*ird)->name == (*ircv)->getDimensions()[0]->name &&
3714 (*ird)->size == (*ircv)->getDimensions()[0]->size) {
3715 latlon2d_path_to_index.erase((*irv)->fullpath);
3717 irv = var_2dlon.erase(irv);
3718 remove_2dlon =
true;
3722 if(
true == remove_2dlon)
3726 if(
false == remove_2dlon)
3733 void GMFile::Obtain_2DLLCVar_Candidate(vector<Var*> &var_2dlat,
3734 vector<Var*> &var_2dlon,
3735 map<string,int>& latlon2d_path_to_index) {
3736 BESDEBUG(
"h5",
"Coming to Obtain_2DLLCVar_Candidate()"<<endl);
3739 vector<string> lon2d_group_paths;
3741 for(vector<Var *>::iterator irv_2dlat = var_2dlat.begin();irv_2dlat !=var_2dlat.end();) {
3742 for(vector<Var *>::iterator irv_2dlon = var_2dlon.begin();irv_2dlon != var_2dlon.end();++irv_2dlon) {
3743 if(((*irv_2dlat)->getDimensions()[0]->name == (*irv_2dlon)->getDimensions()[0]->name) &&
3744 ((*irv_2dlat)->getDimensions()[0]->size == (*irv_2dlon)->getDimensions()[0]->size) &&
3745 ((*irv_2dlat)->getDimensions()[1]->name == (*irv_2dlon)->getDimensions()[1]->name) &&
3746 ((*irv_2dlat)->getDimensions()[1]->size == (*irv_2dlon)->getDimensions()[1]->size))
3747 lon2d_group_paths.push_back(HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlon)->fullpath));
3751 if(0 == lon2d_group_paths.size()) {
3752 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3754 irv_2dlat = var_2dlat.erase(irv_2dlat);
3758 string lat2d_group_path = HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlat)->fullpath);
3761 short lon2d_has_lat2d_group_path_flag = 0;
3762 for(vector<string>::iterator ivs = lon2d_group_paths.begin();ivs!=lon2d_group_paths.end();++ivs) {
3763 if((*ivs)==lat2d_group_path)
3764 lon2d_has_lat2d_group_path_flag++;
3768 if(0 == lon2d_has_lat2d_group_path_flag) {
3769 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3771 irv_2dlat = var_2dlat.erase(irv_2dlat);
3774 else if (1== lon2d_has_lat2d_group_path_flag) {
3781 grp_cv_paths.insert(lat2d_group_path);
3782 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3784 irv_2dlat = var_2dlat.erase(irv_2dlat);
3789 lon2d_group_paths.clear();
3793 for(vector<Var *>::iterator irv_2dlat = var_2dlat.begin();irv_2dlat !=var_2dlat.end();++irv_2dlat)
3794 cerr<<
"2 left 2-D lat variable full path is: "<<(*irv_2dlat)->fullpath <<endl;
3800 vector<string> lat2d_group_paths;
3803 for(vector<Var *>::iterator irv_2dlon = var_2dlon.begin();irv_2dlon !=var_2dlon.end();) {
3804 for(vector<Var *>::iterator irv_2dlat = var_2dlat.begin();irv_2dlat != var_2dlat.end();++irv_2dlat) {
3805 if(((*irv_2dlat)->getDimensions()[0]->name == (*irv_2dlon)->getDimensions()[0]->name) &&
3806 ((*irv_2dlat)->getDimensions()[0]->size == (*irv_2dlon)->getDimensions()[0]->size) &&
3807 ((*irv_2dlat)->getDimensions()[1]->name == (*irv_2dlon)->getDimensions()[1]->name) &&
3808 ((*irv_2dlat)->getDimensions()[1]->size == (*irv_2dlon)->getDimensions()[1]->size))
3809 lat2d_group_paths.push_back(HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlat)->fullpath));
3813 if(0 == lat2d_group_paths.size()) {
3814 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3816 irv_2dlon = var_2dlon.erase(irv_2dlon);
3819 string lon2d_group_path = HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlon)->fullpath);
3822 short lat2d_has_lon2d_group_path_flag = 0;
3823 for(vector<string>::iterator ivs = lat2d_group_paths.begin();ivs!=lat2d_group_paths.end();++ivs) {
3824 if((*ivs)==lon2d_group_path)
3825 lat2d_has_lon2d_group_path_flag++;
3829 if(0 == lat2d_has_lon2d_group_path_flag) {
3830 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3832 irv_2dlon = var_2dlon.erase(irv_2dlon);
3835 else if (1== lat2d_has_lon2d_group_path_flag) {
3842 grp_cv_paths.insert(lon2d_group_path);
3843 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3845 irv_2dlon = var_2dlon.erase(irv_2dlon);
3849 lat2d_group_paths.clear();
3852 for(vector<Var*>::iterator itv = var_2dlat.begin(); itv!= var_2dlat.end();++itv) {
3853 cerr<<
"Before unique, 2-D CV latitude name is "<<(*itv)->fullpath <<endl;
3855 for(vector<Var*>::iterator itv = var_2dlon.begin(); itv!= var_2dlon.end();++itv) {
3856 cerr<<
"Before unique, 2-D CV longitude name is "<<(*itv)->fullpath <<endl;
3861 Obtain_unique_2dCV(var_2dlat,latlon2d_path_to_index);
3862 Obtain_unique_2dCV(var_2dlon,latlon2d_path_to_index);
3864 for(vector<Var*>::iterator itv = var_2dlat.begin(); itv!= var_2dlat.end();++itv) {
3865 cerr<<
"2-D CV latitude name is "<<(*itv)->fullpath <<endl;
3867 for(vector<Var*>::iterator itv = var_2dlon.begin(); itv!= var_2dlon.end();++itv) {
3868 cerr<<
"2-D CV longitude name is "<<(*itv)->fullpath <<endl;
3873 if(var_2dlat.size() != var_2dlon.size()) {
3874 throw1(
"Error in generating 2-D lat/lon CVs. The size of 2d-lat should be the same as that of 2d-lon.");
3880 void GMFile::Obtain_unique_2dCV(vector<Var*> &var_ll,map<string,int>&latlon2d_path_to_index){
3882 BESDEBUG(
"h5",
"Coming to Obtain_unique_2dCV()"<<endl);
3883 vector<bool> var_share_dims(var_ll.size(),
false);
3885 for(
unsigned int i = 0; i <var_ll.size();i++) {
3888 string var_ll_i_path = HDF5CFUtil::obtain_string_before_lastslash(var_ll[i]->fullpath);
3891 for(
unsigned int j = i+1; j<var_ll.size();j++) {
3892 if((var_ll[i]->getDimensions()[0]->name == var_ll[j]->getDimensions()[0]->name)
3893 ||(var_ll[i]->getDimensions()[0]->name == var_ll[j]->getDimensions()[1]->name)
3894 ||(var_ll[i]->getDimensions()[1]->name == var_ll[j]->getDimensions()[0]->name)
3895 ||(var_ll[i]->getDimensions()[1]->name == var_ll[j]->getDimensions()[1]->name)){
3896 string var_ll_j_path = HDF5CFUtil::obtain_string_before_lastslash(var_ll[j]->fullpath);
3903 if(var_ll_i_path.size() > var_ll_j_path.size()) {
3907 if(var_ll_i_path.compare(0,var_ll_j_path.size(),var_ll_j_path)==0) {
3908 var_share_dims[i] =
true;
3909 grp_cv_paths.insert(var_ll_i_path);
3912 var_share_dims[i] =
true;
3913 var_share_dims[j] =
true;
3915 grp_cv_paths.insert(var_ll_i_path);
3916 grp_cv_paths.insert(var_ll_j_path);
3919 else if (var_ll_i_path.size() == var_ll_j_path.size()) {
3920 var_share_dims[i] =
true;
3921 var_share_dims[j] =
true;
3922 if(var_ll_i_path == var_ll_j_path)
3923 grp_cv_paths.insert(var_ll_i_path);
3925 grp_cv_paths.insert(var_ll_i_path);
3926 grp_cv_paths.insert(var_ll_j_path);
3932 if(var_ll_j_path.compare(0,var_ll_i_path.size(),var_ll_i_path)==0) {
3933 var_share_dims[j] =
true;
3934 grp_cv_paths.insert(var_ll_j_path);
3937 var_share_dims[i] =
true;
3938 var_share_dims[j] =
true;
3940 grp_cv_paths.insert(var_ll_i_path);
3941 grp_cv_paths.insert(var_ll_j_path);
3951 for(vector<Var*>::iterator itv = var_ll.begin(); itv!= var_ll.end();) {
3952 if(
true == var_share_dims[var_index]) {
3953 latlon2d_path_to_index.erase((*itv)->fullpath);
3955 itv = var_ll.erase(itv);
3966 void GMFile::Remove_2DLLCVar_Final_Candidate_from_Vars(vector<int> &var2d_index) {
3968 BESDEBUG(
"h5",
"Coming to Remove_2DLLCVar_Final_Candidate_from_Vars()"<<endl);
3970 sort(var2d_index.begin(),var2d_index.end());
3971 vector<Var *>::iterator it = this->
vars.begin();
3977 for (
unsigned int i = 0; i <var2d_index.size();i++) {
3979 advance(it,var2d_index[i]);
3981 advance(it,var2d_index[i]-var2d_index[i-1]-1);
3983 if(it == this->
vars.end())
3984 throw1(
"Out of range to obtain 2D lat/lon variables");
3987 it = this->
vars.erase(it);
3995 bool GMFile::Check_Var_2D_CVars(
Var *var) {
3997 BESDEBUG(
"h5",
"Coming to Check_Var_2D_CVars()"<<endl);
3998 bool ret_value =
true;
3999 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4000 ircv != this->cvars.end(); ++ircv) {
4001 if((*ircv)->rank==2) {
4002 short first_dim_index = 0;
4003 short first_dim_times = 0;
4004 short second_dim_index = 0;
4005 short second_dim_times = 0;
4006 for (vector<Dimension *>::iterator ird = var->dims.begin();
4007 ird != var->dims.end(); ++ird) {
4008 if((*ird)->name == ((*ircv)->getDimensions()[0])->name) {
4009 first_dim_index = distance(var->dims.begin(),ird);
4012 else if((*ird)->name == ((*ircv)->getDimensions()[1])->name) {
4013 second_dim_index = distance(var->dims.begin(),ird);
4019 if(first_dim_times == 1 && second_dim_times == 1) {
4020 if(first_dim_index < second_dim_index) {
4033 bool GMFile::Flatten_VarPath_In_Coordinates_Attr(
Var *var) {
4035 BESDEBUG(
"h5",
"Coming to Flatten_VarPath_In_Coordinates_Attr()"<<endl);
4036 string co_attrname =
"coordinates";
4037 bool has_coor_attr =
false;
4038 string orig_coor_value;
4039 string flatten_coor_value;
4043 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end();) {
4047 if((*ira)->name == co_attrname) {
4048 Retrieve_H5_Attr_Value((*ira),var->fullpath);
4049 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
4050 orig_coor_value = orig_attr_value;
4051 has_coor_attr =
true;
4053 ira = var->attrs.erase(ira);
4060 if(
true == has_coor_attr) {
4063 size_t ele_start_pos = 0;
4064 size_t cur_pos = orig_coor_value.find_first_of(sc);
4065 while(cur_pos !=string::npos) {
4066 string tempstr = orig_coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
4067 tempstr = get_CF_string(tempstr);
4068 flatten_coor_value += tempstr + sc;
4069 ele_start_pos = cur_pos+1;
4070 cur_pos = orig_coor_value.find_first_of(sc,cur_pos+1);
4073 if(ele_start_pos == 0)
4074 flatten_coor_value = get_CF_string(orig_coor_value);
4076 flatten_coor_value += get_CF_string(orig_coor_value.substr(ele_start_pos));
4080 Add_Str_Attr(attr,co_attrname,flatten_coor_value);
4081 var->attrs.push_back(attr);
4091 bool GMFile::Flatten_VarPath_In_Coordinates_Attr_EOS5(
Var *var) {
4093 BESDEBUG(
"h5",
"Coming to Flatten_VarPath_In_Coordinates_Attr_EOS5()"<<endl);
4094 string co_attrname =
"coordinates";
4095 bool has_coor_attr =
false;
4096 string orig_coor_value;
4097 string flatten_coor_value;
4101 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end();) {
4105 if((*ira)->name == co_attrname) {
4106 Retrieve_H5_Attr_Value((*ira),var->fullpath);
4108 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
4109 orig_coor_value = orig_attr_value;
4110 has_coor_attr =
true;
4112 ira = var->attrs.erase(ira);
4119 if(
true == has_coor_attr) {
4123 size_t ele_start_pos = 0;
4125 size_t cur_pos = orig_coor_value.find_first_of(sc);
4126 while(cur_pos !=string::npos) {
4127 string tempstr = orig_coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
4130 tempstr = get_CF_string(tempstr);
4131 flatten_coor_value += tempstr + sc;
4132 ele_start_pos = cur_pos+1;
4133 cur_pos = orig_coor_value.find_first_of(sc,cur_pos+1);
4136 if(ele_start_pos == 0) {
4139 flatten_coor_value = get_CF_string(tempstr);
4142 flatten_coor_value += get_CF_string(orig_coor_value.substr(ele_start_pos));
4146 Add_Str_Attr(attr,co_attrname,flatten_coor_value);
4147 var->attrs.push_back(attr);
4159 bool GMFile::Check_2DLatLon_Dimscale(
string & latname,
string &lonname) {
4177 bool latlon_2d_cv_check1 =
false;
4180 latlon_2d_cv_check1 =
true;
4183 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4184 ircv != this->cvars.end(); ++ircv) {
4185 if((*ircv)->cvartype == CV_FILLINDEX){
4186 latlon_2d_cv_check1 =
true;
4192 bool latlon_2d_cv_check2 =
true;
4195 if(
true == latlon_2d_cv_check1) {
4196 BESDEBUG(
"h5",
"Coming to check if having 2d latlon coordinates for a netCDF-4 like product. "<<endl);
4199 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4200 ircv != this->cvars.end(); ++ircv) {
4201 if((*ircv)->cvartype == CV_EXIST) {
4202 for(vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
4203 ira != (*ircv)->attrs.end();ira++) {
4204 string attr_name =
"units";
4205 string lat_unit_value =
"degrees_north";
4206 string lon_unit_value =
"degrees_east";
4209 if((
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) ||
4210 (
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value))) {
4211 latlon_2d_cv_check2=
false;
4217 if(
false == latlon_2d_cv_check2)
4222 bool latlon_2d_cv_check3 =
true;
4225 if(
true == latlon_2d_cv_check1 &&
true == latlon_2d_cv_check2) {
4227 short latlon_flag = 0;
4228 short LatLon_flag = 0;
4229 short latilong_flag = 0;
4231 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4232 ircv != this->cvars.end(); ++ircv) {
4233 if((*ircv)->cvartype == CV_EXIST) {
4234 if((*ircv)->name ==
"lat")
4236 else if((*ircv)->name ==
"lon")
4238 else if((*ircv)->name ==
"latitude")
4240 else if((*ircv)->name ==
"longitude")
4242 else if((*ircv)->name ==
"Latitude")
4244 else if((*ircv)->name ==
"Longitude")
4249 if((2== latlon_flag) || (2 == latilong_flag) || (2 == LatLon_flag ))
4250 latlon_2d_cv_check3 =
false;
4253 bool latlon_2d =
false;
4254 short latlon_flag = 0;
4255 string latdim1,latdim2,londim1,londim2;
4257 short LatLon_flag = 0;
4258 string Latdim1,Latdim2,Londim1,Londim2;
4260 short latilong_flag = 0;
4261 string latidim1,latidim2,longdim1,longdim2;
4268 if(
true == latlon_2d_cv_check1 &&
true == latlon_2d_cv_check2 &&
true == latlon_2d_cv_check3) {
4270 for (vector<Var *>::iterator irv = this->
vars.begin();
4271 irv != this->vars.end(); ++irv) {
4274 if((*irv)->rank == 2) {
4275 if((*irv)->name ==
"lat") {
4277 latdim1 = (*irv)->getDimensions()[0]->name;
4278 latdim2 = (*irv)->getDimensions()[1]->name;
4281 else if((*irv)->name ==
"lon") {
4283 londim1 = (*irv)->getDimensions()[0]->name;
4284 londim2 = (*irv)->getDimensions()[1]->name;
4286 else if((*irv)->name ==
"latitude"){
4288 latidim1 = (*irv)->getDimensions()[0]->name;
4289 latidim2 = (*irv)->getDimensions()[1]->name;
4291 else if((*irv)->name ==
"longitude"){
4293 longdim1 = (*irv)->getDimensions()[0]->name;
4294 longdim2 = (*irv)->getDimensions()[1]->name;
4297 else if((*irv)->name ==
"Latitude"){
4299 Latdim1 = (*irv)->getDimensions()[0]->name;
4300 Latdim2 = (*irv)->getDimensions()[1]->name;
4303 else if((*irv)->name ==
"Longitude"){
4305 Londim1 = (*irv)->getDimensions()[0]->name;
4306 Londim2 = (*irv)->getDimensions()[1]->name;
4316 if(2 == latlon_flag) {
4317 if((2 == latilong_flag) || ( 2 == LatLon_flag))
4319 else if((latdim1 == londim1) && (latdim2 == londim2)) {
4325 else if ( 2 == latilong_flag) {
4326 if( 2 == LatLon_flag)
4328 else if ((latidim1 == longdim1) ||(latidim2 == longdim2)) {
4329 latname =
"latitude";
4330 lonname =
"longitude";
4334 else if (2 == LatLon_flag){
4335 if ((Latdim1 == Londim1) ||(Latdim2 == Londim2)) {
4336 latname =
"Latitude";
4337 lonname =
"Longitude";
4348 void GMFile::Update_2DLatLon_Dimscale_CV(
const string &latname,
const string &lonname) {
4353 for (vector<Var *>::iterator irv = this->
vars.begin();
4354 irv != this->vars.end(); ++irv) {
4356 if((*irv)->rank == 2) {
4359 if((*irv)->name == latname) {
4362 string latdim0 = (*irv)->getDimensions()[0]->name;
4366 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ) {
4367 if((*i)->cfdimname == latdim0) {
4368 if(CV_FILLINDEX == (*i)->cvartype) {
4370 i = this->cvars.erase(i);
4372 else if(CV_EXIST == (*i)->cvartype) {
4375 this->
vars.push_back(var);
4378 i = this->cvars.erase(i);
4382 if(CV_LAT_MISS == (*i)->cvartype)
4383 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_LAT_MISS");
4384 else if(CV_LON_MISS == (*i)->cvartype)
4385 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_LON_MISS");
4386 else if(CV_NONLATLON_MISS == (*i)->cvartype)
4387 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_NONLATLON_MISS");
4388 else if(CV_MODIFY == (*i)->cvartype)
4389 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_MODIFY");
4390 else if(CV_SPECIAL == (*i)->cvartype)
4391 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_SPECIAL");
4393 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_UNSUPPORTED");
4402 GMcvar->cfdimname = latdim0;
4403 GMcvar->cvartype = CV_EXIST;
4404 GMcvar->product_type = product_type;
4405 this->cvars.push_back(GMcvar);
4407 this->
vars.erase(irv);
4414 for (vector<Var *>::iterator irv = this->
vars.begin();
4415 irv != this->vars.end(); ++irv) {
4417 if((*irv)->rank == 2) {
4420 if((*irv)->name == lonname) {
4423 string londim0 = (*irv)->getDimensions()[1]->name;
4426 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ) {
4428 if((*i)->cfdimname == londim0) {
4429 if(CV_FILLINDEX == (*i)->cvartype) {
4431 i= this->cvars.erase(i);
4433 else if(CV_EXIST == (*i)->cvartype) {
4436 this->
vars.push_back(var);
4439 i = this->cvars.erase(i);
4442 if(CV_LAT_MISS == (*i)->cvartype)
4443 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_LAT_MISS");
4444 else if(CV_LON_MISS == (*i)->cvartype)
4445 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_LON_MISS");
4446 else if(CV_NONLATLON_MISS == (*i)->cvartype)
4447 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_NONLATLON_MISS");
4448 else if(CV_MODIFY == (*i)->cvartype)
4449 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_MODIFY");
4450 else if(CV_SPECIAL == (*i)->cvartype)
4451 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_SPECIAL");
4453 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_UNSUPPORTED");
4462 GMcvar->cfdimname = londim0;
4463 GMcvar->cvartype = CV_EXIST;
4464 GMcvar->product_type = product_type;
4465 this->cvars.push_back(GMcvar);
4467 this->
vars.erase(irv);
4476 void GMFile::Handle_CVar_LatLon1D_General_Product() {
4478 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon1D_General_Product()"<<endl);
4479 this->iscoard =
true;
4480 Handle_CVar_LatLon_General_Product();
4485 void GMFile::Handle_CVar_LatLon2D_General_Product() {
4487 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon2D_General_Product()"<<endl);
4488 Handle_CVar_LatLon_General_Product();
4494 void GMFile::Handle_CVar_LatLon_General_Product() {
4496 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon_General_Product()"<<endl);
4497 if((GENERAL_LATLON2D != this->gproduct_pattern)
4498 && GENERAL_LATLON1D != this->gproduct_pattern)
4499 throw1(
"This function only supports latlon 1D or latlon 2D general products");
4501 pair<set<string>::iterator,
bool> setret;
4502 set<string>tempdimnamelist = dimnamelist;
4504 for (vector<Var *>::iterator irv = this->
vars.begin();
4505 irv != this->vars.end(); ++irv) {
4508 if (gp_latname== (*irv)->name) {
4512 tempdimnamelist.erase(((*irv)->dims[0])->name);
4514 GMcvar->cfdimname = ((*irv)->dims[0])->name;
4515 GMcvar->cvartype = CV_EXIST;
4516 GMcvar->product_type = product_type;
4517 this->cvars.push_back(GMcvar);
4519 this->
vars.erase(irv);
4524 for (vector<Var *>::iterator irv = this->
vars.begin();
4525 irv != this->
vars.end(); ++irv) {
4528 if (gp_lonname== (*irv)->name) {
4534 if(GENERAL_LATLON2D == this->gproduct_pattern)
4535 londimname = ((*irv)->dims[1])->name;
4537 londimname = ((*irv)->dims[0])->name;
4539 tempdimnamelist.erase(londimname);
4541 GMcvar->cfdimname = londimname;
4542 GMcvar->cvartype = CV_EXIST;
4543 GMcvar->product_type = product_type;
4544 this->cvars.push_back(GMcvar);
4546 this->
vars.erase(irv);
4553 for (set<string>::iterator irs = tempdimnamelist.begin();
4554 irs != tempdimnamelist.end();irs++) {
4556 Create_Missing_CV(GMcvar,*irs);
4557 this->cvars.push_back(GMcvar);
4563 void GMFile::Handle_CVar_OBPG_L3() {
4565 BESDEBUG(
"h5",
"Coming to Handle_CVar_OBPG_L3()"<<endl);
4566 if (GENERAL_DIMSCALE == this->gproduct_pattern)
4567 Handle_CVar_Dimscale_General_Product();
4570 for (vector<Var *>::iterator irv = this->
vars.begin();
4571 irv != this->vars.end(); ++irv) {
4578 if((*irv)->rank == 2) {
4580 if(((*irv)->fullpath.find(
"/geophsical_data") == 0) || ((*irv)->dtype == H5FLOAT32)) {
4582 size_t lat_size = (*irv)->getDimensions()[0]->size;
4583 string lat_name = (*irv)->getDimensions()[0]->name;
4584 size_t lon_size = (*irv)->getDimensions()[1]->size;
4585 string lon_name = (*irv)->getDimensions()[1]->name;
4586 size_t temp_size = 0;
4588 H5DataType ll_dtype = (*irv)->dtype;
4591 if(lat_size >lon_size) {
4592 temp_size = lon_size;
4593 temp_name = lon_name;
4594 lon_size = lat_size;
4595 lon_name = lat_name;
4596 lat_size = temp_size;
4597 lat_name = temp_name;
4599 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4600 ircv != this->cvars.end(); ++ircv) {
4601 if((*ircv)->cvartype == CV_FILLINDEX) {
4602 if((*ircv)->getDimensions()[0]->size == lat_size &&
4603 (*ircv)->getDimensions()[0]->name == lat_name) {
4604 (*ircv)->cvartype = CV_LAT_MISS;
4605 (*ircv)->dtype = ll_dtype;
4606 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
4607 ira != (*ircv)->attrs.end(); ++ira) {
4608 if ((*ira)->name ==
"NAME") {
4610 (*ircv)->attrs.erase(ira);
4615 else if((*ircv)->getDimensions()[0]->size == lon_size &&
4616 (*ircv)->getDimensions()[0]->name == lon_name) {
4617 (*ircv)->cvartype = CV_LON_MISS;
4618 (*ircv)->dtype = ll_dtype;
4619 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
4620 ira != (*ircv)->attrs.end(); ++ira) {
4621 if ((*ira)->name ==
"NAME") {
4623 (*ircv)->attrs.erase(ira);
4642 BESDEBUG(
"h5",
"Coming to Handle_SpVar()"<<endl);
4643 if (ACOS_L2S_OR_OCO2_L1B == product_type)
4644 Handle_SpVar_ACOS_OCO2();
4645 else if(GPM_L1 == product_type) {
4648 for (vector<Var *>::iterator irv = this->
vars.begin();
4649 irv != this->vars.end(); ++irv) {
4650 if((*irv)->name==
"AlgorithmRuntimeInfo") {
4652 this->
vars.erase(irv);
4659 else if(GPMM_L3 == product_type || GPMS_L3 == product_type) {
4661 for (vector<Var *>::iterator irv = this->
vars.begin();
4662 irv != this->vars.end(); ) {
4663 if((*irv)->name==
"InputFileNames") {
4665 irv = this->
vars.erase(irv);
4667 else if((*irv)->name==
"InputAlgorithmVersions") {
4669 irv = this->
vars.erase(irv);
4671 else if((*irv)->name==
"InputGenerationDateTimes") {
4673 irv = this->
vars.erase(irv);
4686 void GMFile::Handle_SpVar_ACOS_OCO2() {
4688 BESDEBUG(
"h5",
"Coming to Handle_SpVar_ACOS_OCO2()"<<endl);
4691 for (vector<Var *>::iterator irv = this->
vars.begin();
4692 irv != this->vars.end(); ) {
4693 if (H5INT64 == (*irv)->getType()) {
4697 spvar->name = (*irv)->name +
"_Time";
4698 spvar->newname = (*irv)->newname+
"_Time";
4699 spvar->dtype = H5INT32;
4700 spvar->otype = (*irv)->getType();
4704 spvar->numofdbits = 6;
4705 this->spvars.push_back(spvar);
4709 spvar2->name = (*irv)->name +
"_Date";
4710 spvar2->newname = (*irv)->newname+
"_Date";
4711 spvar2->dtype = H5INT32;
4712 spvar2->otype = (*irv)->getType();
4716 spvar2->numofdbits = 8;
4717 this->spvars.push_back(spvar2);
4720 irv = this->
vars.erase(irv);
4732 BESDEBUG(
"h5",
"Coming to Adjust_Obj_Name()"<<endl);
4733 if(Mea_Ozone == product_type)
4734 Adjust_Mea_Ozone_Obj_Name();
4736 if(GPMS_L3 == product_type || GPMM_L3 == product_type)
4737 Adjust_GPM_L3_Obj_Name();
4741 for (vector<Var*>::iterator irv2 = this->
vars.begin();
4742 irv2 != this->vars.end(); irv2++) {
4743 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
4744 ird !=(*irv2)->dims.end(); ird++) {
4745 cerr<<
"Dimension name afet Adjust_Obj_Name "<<(*ird)->newname <<endl;
4753 void GMFile:: Adjust_GPM_L3_Obj_Name() {
4755 BESDEBUG(
"h5",
"Coming to Adjust_GPM_L3_Obj_Name()"<<endl);
4758 if(this->
groups.size() <= 1) {
4759 for (vector<Var *>::iterator irv = this->
vars.begin();
4760 irv != this->vars.end(); ++irv) {
4761 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4762 if (objnewname !=
"")
4763 (*irv)->newname = objnewname;
4767 for (vector<Var *>::iterator irv = this->
vars.begin();
4768 irv != this->vars.end(); ++irv) {
4769 size_t grid_group_path_pos = ((*irv)->newname.substr(1)).find_first_of(
"/");
4770 objnewname = ((*irv)->newname).substr(grid_group_path_pos+2);
4771 (*irv)->newname = objnewname;
4777 void GMFile:: Adjust_Mea_Ozone_Obj_Name() {
4779 BESDEBUG(
"h5",
"Coming to Adjust_Mea_Ozone_Obj_Name()"<<endl);
4781 for (vector<Var *>::iterator irv = this->
vars.begin();
4782 irv != this->vars.end(); ++irv) {
4783 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4784 if (objnewname !=
"")
4785 (*irv)->newname = objnewname;
4789 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4790 ird !=(*irv)->dims.end();++ird) {
4791 cerr<<
"Ozone dim. name "<<(*ird)->name <<endl;
4792 cerr<<
"Ozone dim. new name "<<(*ird)->newname <<endl;
4798 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4799 irv != this->cvars.end(); ++irv) {
4800 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4801 if (objnewname !=
"")
4802 (*irv)->newname = objnewname;
4805 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4806 ird !=(*irv)->dims.end();++ird) {
4807 cerr<<
"Ozone CV dim. name "<<(*ird)->name <<endl;
4808 cerr<<
"Ozone CV dim. new name "<<(*ird)->newname <<endl;
4817 BESDEBUG(
"h5",
"GMFile::Coming to Flatten_Obj_Name()"<<endl);
4822 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4823 irv != this->cvars.end(); ++irv) {
4824 (*irv)->newname = get_CF_string((*irv)->newname);
4826 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4827 ird != (*irv)->dims.end(); ++ird) {
4828 (*ird)->newname = get_CF_string((*ird)->newname);
4831 if (
true == include_attr) {
4832 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
4833 ira != (*irv)->attrs.end(); ++ira)
4834 (*ira)->newname = File::get_CF_string((*ira)->newname);
4841 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
4842 irv != this->spvars.end(); ++irv) {
4843 (*irv)->newname = get_CF_string((*irv)->newname);
4845 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4846 ird != (*irv)->dims.end(); ++ird)
4847 (*ird)->newname = get_CF_string((*ird)->newname);
4849 if (
true == include_attr) {
4850 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
4851 ira != (*irv)->attrs.end(); ++ira)
4852 (*ira)->newname = File::get_CF_string((*ira)->newname);
4859 for (vector<Var*>::iterator irv2 = this->
vars.begin();
4860 irv2 != this->vars.end(); irv2++) {
4861 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
4862 ird !=(*irv2)->dims.end(); ird++) {
4863 cerr<<
"Dimension name afet Flatten_Obj_Name "<<(*ird)->newname <<endl;
4875 BESDEBUG(
"h5",
"GMFile::Coming to Handle_Obj_NameClashing()"<<endl);
4879 set<string>objnameset;
4880 Handle_GMCVar_NameClashing(objnameset);
4881 Handle_GMSPVar_NameClashing(objnameset);
4882 File::Handle_GeneralObj_NameClashing(include_attr,objnameset);
4883 if (
true == include_attr) {
4884 Handle_GMCVar_AttrNameClashing();
4885 Handle_GMSPVar_AttrNameClashing();
4892 void GMFile::Handle_GMCVar_NameClashing(set<string> &objnameset ) {
4894 GMHandle_General_NameClashing(objnameset,this->cvars);
4898 void GMFile::Handle_GMSPVar_NameClashing(set<string> &objnameset ) {
4900 GMHandle_General_NameClashing(objnameset,this->spvars);
4904 void GMFile::Handle_GMCVar_AttrNameClashing() {
4906 BESDEBUG(
"h5",
"Coming to Handle_GMCVar_AttrNameClashing()"<<endl);
4907 set<string> objnameset;
4909 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4910 irv != this->cvars.end(); ++irv) {
4911 Handle_General_NameClashing(objnameset,(*irv)->attrs);
4917 void GMFile::Handle_GMSPVar_AttrNameClashing() {
4919 BESDEBUG(
"h5",
"Coming to Handle_GMSPVar_AttrNameClashing()"<<endl);
4920 set<string> objnameset;
4922 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
4923 irv != this->spvars.end(); ++irv) {
4924 Handle_General_NameClashing(objnameset,(*irv)->attrs);
4932 template<
class T>
void
4933 GMFile::GMHandle_General_NameClashing(set <string>&objnameset, vector<T*>& objvec) {
4935 BESDEBUG(
"h5",
"Coming to GMHandle_General_NameClashing()"<<endl);
4936 pair<set<string>::iterator,
bool> setret;
4937 set<string>::iterator iss;
4939 vector<string> clashnamelist;
4940 vector<string>::iterator ivs;
4942 map<int,int> cl_to_ol;
4946 typename vector<T*>::iterator irv;
4948 for (irv = objvec.begin();
4949 irv != objvec.end(); ++irv) {
4951 setret = objnameset.insert((*irv)->newname);
4952 if (
false == setret.second ) {
4953 clashnamelist.insert(clashnamelist.end(),(*irv)->newname);
4954 cl_to_ol[cl_index] = ol_index;
4963 for (ivs=clashnamelist.begin(); ivs!=clashnamelist.end(); ++ivs) {
4964 int clash_index = 1;
4965 string temp_clashname = *ivs +
'_';
4966 HDF5CFUtil::gen_unique_name(temp_clashname,objnameset,clash_index);
4967 *ivs = temp_clashname;
4972 for (
unsigned int i =0; i <clashnamelist.size(); i++)
4973 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
4981 BESDEBUG(
"h5",
"GMFile: Coming to Handle_DimNameClashing()"<<endl);
4983 if (ACOS_L2S_OR_OCO2_L1B == product_type)
4986 map<string,string>dimname_to_dimnewname;
4987 pair<map<string,string>::iterator,
bool>mapret;
4988 set<string> dimnameset;
4989 vector<Dimension*>vdims;
4990 set<string> dimnewnameset;
4991 pair<set<string>::iterator,
bool> setret;
4994 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4995 irv !=this->cvars.end(); ++irv) {
4996 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
4997 ird !=(*irv)->dims.end();++ird) {
4998 setret = dimnameset.insert((*ird)->name);
4999 if (
true == setret.second)
5000 vdims.push_back(*ird);
5007 for(vector<Var *>::iterator irv= this->
vars.begin();
5008 irv != this->vars.end();++irv) {
5009 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
5010 ird !=(*irv)->dims.end();++ird) {
5012 setret = dimnameset.insert((*ird)->name);
5013 if (setret.second) vdims.push_back(*ird);
5017 GMHandle_General_NameClashing(dimnewnameset,vdims);
5020 for (vector<Dimension*>::iterator ird = vdims.begin();ird!=vdims.end();++ird) {
5021 mapret = dimname_to_dimnewname.insert(pair<string,string>((*ird)->name,(*ird)->newname));
5022 if (
false == mapret.second)
5023 throw4(
"The dimension name ",(*ird)->name,
" should map to ",
5028 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5029 irv !=this->cvars.end(); ++irv)
5030 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
5031 ird!=(*irv)->dims.end();++ird)
5032 (*ird)->newname = dimname_to_dimnewname[(*ird)->name];
5034 for (vector<Var *>::iterator irv = this->
vars.begin();
5035 irv != this->vars.end(); ++irv)
5036 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
5037 ird !=(*irv)->dims.end();++ird)
5038 (*ird)->newname = dimname_to_dimnewname[(*ird)->name];
5045 BESDEBUG(
"h5",
"GMFile:Coming to Adjust_Dim_Name()"<<endl);
5048 for (vector<Var*>::iterator irv2 = this->
vars.begin();
5049 irv2 != this->vars.end(); irv2++) {
5050 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
5051 ird !=(*irv2)->dims.end(); ird++) {
5052 cerr<<
"Dimension new name "<<(*ird)->newname <<endl;
5058 if(
true == iscoard) {
5059 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5060 irv !=this->cvars.end(); ++irv) {
5062 cerr<<
"1D Cvariable name is "<<(*irv)->name <<endl;
5063 cerr<<
"1D Cvariable new name is "<<(*irv)->newname <<endl;
5064 cerr<<
"1D Cvariable dim name is "<<((*irv)->dims)[0]->name <<endl;
5065 cerr<<
"1D Cvariable dim new name is "<<((*irv)->dims)[0]->newname <<endl;
5067 if ((*irv)->dims.size()!=1)
5068 throw3(
"Coard coordinate variable ",(*irv)->name,
"is not 1D");
5069 if ((*irv)->newname != (((*irv)->dims)[0]->newname)) {
5070 ((*irv)->dims)[0]->newname = (*irv)->newname;
5073 for (vector<Var*>::iterator irv2 = this->
vars.begin();
5074 irv2 != this->
vars.end(); ++irv2) {
5075 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
5076 ird !=(*irv2)->dims.end(); ++ird) {
5081 if ((*ird)->name == ((*irv)->dims)[0]->name)
5082 (*ird)->newname = ((*irv)->dims)[0]->newname;
5091 for (vector<Var*>::iterator irv2 = this->
vars.begin();
5092 irv2 != this->
vars.end(); irv2++) {
5093 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
5094 ird !=(*irv2)->dims.end(); ird++) {
5095 cerr<<
"Dimension name afet Adjust_Dim_Name "<<(*ird)->newname <<endl;
5107 BESDEBUG(
"h5",
"GMFile::Coming to Add_Supplement_Attrs()"<<endl);
5108 if (General_Product == product_type ||
true == add_path) {
5112 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5113 irv != this->cvars.end(); ++irv) {
5114 if (((*irv)->cvartype == CV_EXIST) || ((*irv)->cvartype == CV_MODIFY)) {
5116 const string varname = (*irv)->name;
5117 const string attrname =
"origname";
5118 Add_Str_Attr(attr,attrname,varname);
5119 (*irv)->attrs.push_back(attr);
5123 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5124 irv != this->cvars.end(); ++irv) {
5125 if (((*irv)->cvartype == CV_EXIST) || ((*irv)->cvartype == CV_MODIFY)) {
5127 const string varname = (*irv)->fullpath;
5128 const string attrname =
"fullnamepath";
5129 Add_Str_Attr(attr,attrname,varname);
5130 (*irv)->attrs.push_back(attr);
5134 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
5135 irv != this->spvars.end(); ++irv) {
5137 const string varname = (*irv)->name;
5138 const string attrname =
"origname";
5139 Add_Str_Attr(attr,attrname,varname);
5140 (*irv)->attrs.push_back(attr);
5143 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
5144 irv != this->spvars.end(); ++irv) {
5146 const string varname = (*irv)->fullpath;
5147 const string attrname =
"fullnamepath";
5148 Add_Str_Attr(attr,attrname,varname);
5149 (*irv)->attrs.push_back(attr);
5153 if(GPM_L1 == product_type || GPMS_L3 == product_type || GPMM_L3 == product_type)
5155 else if (Aqu_L3 == product_type)
5157 else if (Mea_SeaWiFS_L2 == product_type || Mea_SeaWiFS_L3 == product_type)
5158 Add_SeaWiFS_Attrs();
5164 GMFile:: Add_GPM_Attrs() {
5166 BESDEBUG(
"h5",
"Coming to Add_GPM_Attrs()"<<endl);
5167 vector<HDF5CF::Var *>::const_iterator it_v;
5168 vector<HDF5CF::Attribute *>::const_iterator ira;
5169 const string attr_name_be_replaced =
"CodeMissingValue";
5170 const string attr_new_name =
"_FillValue";
5171 const string attr2_name_be_replaced =
"Units";
5172 const string attr2_new_name =
"units";
5177 for (it_v =
vars.begin(); it_v !=
vars.end(); ++it_v) {
5178 bool has_fvalue_attr =
false;
5179 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5180 if(attr_new_name == (*ira)->name) {
5181 has_fvalue_attr =
true;
5186 if(
false == has_fvalue_attr) {
5187 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5188 if(attr_name_be_replaced == (*ira)->name) {
5189 if((*ira)->dtype == H5FSTRING)
5190 Change_Attr_One_Str_to_Others((*ira),(*it_v));
5191 (*ira)->name = attr_new_name;
5192 (*ira)->newname = attr_new_name;
5200 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5201 irv != this->cvars.end(); ++irv) {
5202 bool has_fvalue_attr =
false;
5204 for(ira = (*irv)->attrs.begin(); ira!= (*irv)->attrs.end();ira++) {
5206 if(attr_new_name == (*ira)->name) {
5207 has_fvalue_attr =
true;
5211 if(
false == has_fvalue_attr) {
5212 for(ira = (*irv)->attrs.begin(); ira!= (*irv)->attrs.end();ira++) {
5214 if(attr_name_be_replaced == (*ira)->name) {
5215 if((*ira)->dtype == H5FSTRING)
5216 Change_Attr_One_Str_to_Others((*ira),(*irv));
5217 (*ira)->name = attr_new_name;
5218 (*ira)->newname = attr_new_name;
5225 if(product_type == GPM_L1) {
5227 if ((*irv)->cvartype == CV_EXIST) {
5228 if((*irv)->name.find(
"Latitude") !=string::npos) {
5229 string unit_value =
"degrees_north";
5230 Correct_GPM_L1_LatLon_units(*irv,unit_value);
5233 else if((*irv)->name.find(
"Longitude") !=string::npos) {
5234 string unit_value =
"degrees_east";
5235 Correct_GPM_L1_LatLon_units(*irv,unit_value);
5240 else if ((*irv)->cvartype == CV_NONLATLON_MISS) {
5243 const string attrname =
"comment";
5247 if((*irv)->name ==
"nchannel1")
5248 comment =
"Number of Swath S1 channels (10V 10H 19V 19H 23V 37V 37H 89V 89H).";
5249 else if((*irv)->name ==
"nchannel2")
5250 comment =
"Number of Swath S2 channels (166V 166H 183+/-3V 183+/-8V).";
5251 else if((*irv)->name ==
"nchan1")
5252 comment =
"Number of channels in Swath 1.";
5253 else if((*irv)->name ==
"nchan2")
5254 comment =
"Number of channels in Swath 2.";
5255 else if((*irv)->name ==
"VH")
5256 comment =
"Number of polarizations.";
5257 else if((*irv)->name ==
"GMIxyz")
5258 comment =
"x, y, z components in GMI instrument coordinate system.";
5259 else if((*irv)->name ==
"LNL")
5260 comment =
"Linear and non-linear.";
5261 else if((*irv)->name ==
"nscan")
5262 comment =
"Number of scans in the granule.";
5263 else if((*irv)->name ==
"nscan1")
5264 comment =
"Typical number of Swath S1 scans in the granule.";
5265 else if((*irv)->name ==
"nscan2")
5266 comment =
"Typical number of Swath S2 scans in the granule.";
5267 else if((*irv)->name ==
"npixelev")
5268 comment =
"Number of earth view pixels in one scan.";
5269 else if((*irv)->name ==
"npixelht")
5270 comment =
"Number of hot load pixels in one scan.";
5271 else if((*irv)->name ==
"npixelcs")
5272 comment =
"Number of cold sky pixels in one scan.";
5273 else if((*irv)->name ==
"npixelfr")
5274 comment =
"Number of full rotation earth view pixels in one scan.";
5275 else if((*irv)->name ==
"nfreq1")
5276 comment =
"Number of frequencies in Swath 1.";
5277 else if((*irv)->name ==
"nfreq2")
5278 comment =
"Number of frequencies in Swath 2.";
5279 else if((*irv)->name ==
"npix1")
5280 comment =
"Number of pixels in Swath 1.";
5281 else if((*irv)->name ==
"npix2")
5282 comment =
"Number of pixels in Swath 2.";
5283 else if((*irv)->name ==
"npix3")
5284 comment =
"Number of pixels in Swath 3.";
5285 else if((*irv)->name ==
"npix4")
5286 comment =
"Number of pixels in Swath 4.";
5287 else if((*irv)->name ==
"ncolds1")
5288 comment =
"Maximum number of cold samples in Swath 1.";
5289 else if((*irv)->name ==
"ncolds2")
5290 comment =
"Maximum number of cold samples in Swath 2.";
5291 else if((*irv)->name ==
"nhots1")
5292 comment =
"Maximum number of hot samples in Swath 1.";
5293 else if((*irv)->name ==
"nhots2")
5294 comment =
"Maximum number of hot samples in Swath 2.";
5295 else if((*irv)->name ==
"ntherm")
5296 comment =
"Number of hot load thermisters.";
5297 else if((*irv)->name ==
"ntach")
5298 comment =
"Number of tachometer readings.";
5299 else if((*irv)->name ==
"nsamt"){
5300 comment =
"Number of sample types. ";
5301 comment = +
"The types are: total science GSDR, earthview,hot load, cold sky.";
5303 else if((*irv)->name ==
"nndiode")
5304 comment =
"Number of noise diodes.";
5305 else if((*irv)->name ==
"n7")
5306 comment =
"Number seven.";
5307 else if((*irv)->name ==
"nray")
5308 comment =
"Number of angle bins in each NS scan.";
5309 else if((*irv)->name ==
"nrayMS")
5310 comment =
"Number of angle bins in each MS scan.";
5311 else if((*irv)->name ==
"nrayHS")
5312 comment =
"Number of angle bins in each HS scan.";
5313 else if((*irv)->name ==
"nbin")
5314 comment =
"Number of range bins in each NS and MS ray. Bin interval is 125m.";
5315 else if((*irv)->name ==
"nbinHS")
5316 comment =
"Number of range bins in each HS ray. Bin interval is 250m.";
5317 else if((*irv)->name ==
"nbinSZP")
5318 comment =
"Number of range bins for sigmaZeroProfile.";
5319 else if((*irv)->name ==
"nbinSZPHS")
5320 comment =
"Number of range bins for sigmaZeroProfile in each HS scan.";
5321 else if((*irv)->name ==
"nNP")
5322 comment =
"Number of NP kinds.";
5323 else if((*irv)->name ==
"nearFar")
5324 comment =
"Near reference, Far reference.";
5325 else if((*irv)->name ==
"foreBack")
5326 comment =
"Forward, Backward.";
5327 else if((*irv)->name ==
"method")
5328 comment =
"Number of SRT methods.";
5329 else if((*irv)->name ==
"nNode")
5330 comment =
"Number of binNode.";
5331 else if((*irv)->name ==
"nDSD")
5332 comment =
"Number of DSD parameters. Parameters are N0 and D0";
5333 else if((*irv)->name ==
"LS")
5334 comment =
"Liquid, solid.";
5340 Add_Str_Attr(attr,attrname,comment);
5341 (*irv)->attrs.push_back(attr);
5347 if(product_type == GPMS_L3 || product_type == GPMM_L3) {
5348 if ((*irv)->cvartype == CV_NONLATLON_MISS) {
5351 const string attrname =
"comment";
5355 if((*irv)->name ==
"chn")
5356 comment =
"Number of channels:Ku,Ka,KaHS,DPR.";
5357 else if((*irv)->name ==
"inst")
5358 comment =
"Number of instruments:Ku,Ka,KaHS.";
5359 else if((*irv)->name ==
"tim")
5360 comment =
"Number of hours(local time).";
5361 else if((*irv)->name ==
"ang"){
5362 comment =
"Number of angles.The meaning of ang is different for each channel.";
5364 "For Ku channel all indices are used with the meaning 0,1,2,..6 =angle bins 24,";
5366 "(20,28),(16,32),(12,36),(8,40),(3,44),and (0,48).";
5368 "For Ka channel 4 indices are used with the meaning 0,1,2,3 = angle bins 12,(8,16),";
5370 "(4,20),and (0,24). For KaHS channel 4 indices are used with the meaning 0,1,2,3 =";
5371 comment +=
"angle bins(11,2),(7,16),(3,20),and (0.23).";
5374 else if((*irv)->name ==
"rt")
5375 comment =
"Number of rain types: stratiform, convective,all.";
5376 else if((*irv)->name ==
"st")
5377 comment =
"Number of surface types:ocean,land,all.";
5378 else if((*irv)->name ==
"bin"){
5379 comment =
"Number of bins in histogram. The thresholds are different for different";
5380 comment +=
" variables. see the file specification for this algorithm.";
5382 else if((*irv)->name ==
"nvar") {
5383 comment =
"Number of phase bins. Bins are counts of phase less than 100, ";
5384 comment +=
"counts of phase greater than or equal to 100 and less than 200, ";
5385 comment +=
"counts of phase greater than or equal to 200.";
5387 else if((*irv)->name ==
"AD")
5388 comment =
"Ascending or descending half of the orbit.";
5394 Add_Str_Attr(attr,attrname,comment);
5395 (*irv)->attrs.push_back(attr);
5402 if ((*irv)->cvartype == CV_SPECIAL) {
5403 if((*irv)->name ==
"nlayer" || (*irv)->name ==
"hgt"
5404 || (*irv)->name ==
"nalt") {
5406 string unit_value =
"km";
5407 Add_Str_Attr(attr,attr2_new_name,unit_value);
5408 (*irv)->attrs.push_back(attr);
5411 string attr1_axis=
"axis";
5412 string attr1_value =
"Z";
5413 Add_Str_Attr(attr1,attr1_axis,attr1_value);
5414 (*irv)->attrs.push_back(attr1);
5417 string attr2_positive=
"positive";
5418 string attr2_value =
"up";
5419 Add_Str_Attr(attr2,attr2_positive,attr2_value);
5420 (*irv)->attrs.push_back(attr2);
5423 if((*irv)->name ==
"hgt" || (*irv)->name ==
"nalt"){
5425 string comment =
"Number of heights above the earth ellipsoid";
5426 Add_Str_Attr(attr1,
"comment",comment);
5427 (*irv)->attrs.push_back(attr1);
5437 const string fill_value_attr_name =
"_FillValue";
5438 vector<HDF5CF::Var *>::const_iterator it_v;
5439 vector<HDF5CF::Attribute *>::const_iterator ira;
5441 for (it_v =
vars.begin();
5442 it_v !=
vars.end(); ++it_v) {
5444 bool has_fillvalue =
false;
5445 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5446 if (fill_value_attr_name == (*ira)->name){
5447 has_fillvalue =
true;
5454 if (has_fillvalue !=
true ) {
5456 if(H5FLOAT32 == (*it_v)->dtype) {
5458 float _FillValue = -9999.9;
5459 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5460 (*it_v)->attrs.push_back(attr);
5470 GMFile:: Correct_GPM_L1_LatLon_units(
Var *var,
const string unit_value) {
5472 BESDEBUG(
"h5",
"Coming to Correct_GPM_L1_LatLon_units()"<<endl);
5473 const string Unit_name =
"Units";
5474 const string unit_name =
"units";
5476 vector<HDF5CF::Attribute *>::iterator ira;
5479 for(ira = var->attrs.begin(); ira!= var->attrs.end();) {
5480 if(unit_name == (*ira)->name) {
5482 ira = var->attrs.erase(ira);
5484 else if(Unit_name == (*ira)->name) {
5486 ira = var->attrs.erase(ira);
5495 Add_Str_Attr(attr,unit_name,unit_value);
5496 var->attrs.push_back(attr);
5503 GMFile:: Add_Aqu_Attrs() {
5505 BESDEBUG(
"h5",
"Coming to Add_Aqu_Attrs()"<<endl);
5506 vector<HDF5CF::Var *>::const_iterator it_v;
5507 vector<HDF5CF::Attribute *>::const_iterator ira;
5509 const string orig_longname_attr_name =
"Parameter";
5510 const string longname_attr_name =
"long_name";
5511 string longname_value;
5514 const string orig_units_attr_name =
"Units";
5515 const string units_attr_name =
"units";
5518 const string orig_valid_min_attr_name =
"Data Minimum";
5519 const string valid_min_attr_name =
"valid_min";
5520 float valid_min_value = 0;
5522 const string orig_valid_max_attr_name =
"Data Maximum";
5523 const string valid_max_attr_name =
"valid_max";
5524 float valid_max_value = 0;
5529 const string fill_value_attr_name =
"_FillValue";
5530 float _FillValue = -32767.0;
5532 for (ira = this->
root_attrs.begin(); ira != this->root_attrs.end(); ++ira) {
5533 if (orig_longname_attr_name == (*ira)->name) {
5534 Retrieve_H5_Attr_Value(*ira,
"/");
5535 longname_value.resize((*ira)->value.size());
5536 copy((*ira)->value.begin(),(*ira)->value.end(),longname_value.begin());
5539 else if (orig_units_attr_name == (*ira)->name) {
5540 Retrieve_H5_Attr_Value(*ira,
"/");
5541 units_value.resize((*ira)->value.size());
5542 copy((*ira)->value.begin(),(*ira)->value.end(),units_value.begin());
5545 else if (orig_valid_min_attr_name == (*ira)->name) {
5546 Retrieve_H5_Attr_Value(*ira,
"/");
5547 memcpy(&valid_min_value,(
void*)(&((*ira)->value[0])),(*ira)->value.size());
5550 else if (orig_valid_max_attr_name == (*ira)->name) {
5551 Retrieve_H5_Attr_Value(*ira,
"/");
5552 memcpy(&valid_max_value,(
void*)(&((*ira)->value[0])),(*ira)->value.size());
5559 bool has_long_name =
false;
5560 bool has_units =
false;
5561 bool has_valid_min =
false;
5562 bool has_valid_max =
false;
5563 bool has_fillvalue =
false;
5565 for (it_v =
vars.begin();
5566 it_v !=
vars.end(); ++it_v) {
5567 if (
"l3m_data" == (*it_v)->name) {
5568 for (ira = (*it_v)->attrs.begin(); ira != (*it_v)->attrs.end(); ++ira) {
5569 if (longname_attr_name == (*ira)->name)
5570 has_long_name =
true;
5571 else if(units_attr_name == (*ira)->name)
5573 else if(valid_min_attr_name == (*ira)->name)
5574 has_valid_min =
true;
5575 else if(valid_max_attr_name == (*ira)->name)
5576 has_valid_max =
true;
5577 else if(fill_value_attr_name == (*ira)->name)
5578 has_fillvalue =
true;
5586 for (it_v =
vars.begin();
5587 it_v !=
vars.end(); ++it_v) {
5588 if (
"l3m_data" == (*it_v)->name) {
5592 if(
false == has_long_name) {
5594 Add_Str_Attr(attr,longname_attr_name,longname_value);
5595 (*it_v)->attrs.push_back(attr);
5599 if(
false == has_units) {
5601 Add_Str_Attr(attr,units_attr_name,units_value);
5602 (*it_v)->attrs.push_back(attr);
5606 if(
false == has_valid_min) {
5608 Add_One_Float_Attr(attr,valid_min_attr_name,valid_min_value);
5609 (*it_v)->attrs.push_back(attr);
5613 if(
false == has_valid_max) {
5615 Add_One_Float_Attr(attr,valid_max_attr_name,valid_max_value);
5616 (*it_v)->attrs.push_back(attr);
5620 if(
false == has_fillvalue) {
5622 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5623 (*it_v)->attrs.push_back(attr);
5633 GMFile:: Add_SeaWiFS_Attrs() {
5635 BESDEBUG(
"h5",
"Coming to Add_SeaWiFS_Attrs()"<<endl);
5638 const string fill_value_attr_name =
"_FillValue";
5639 float _FillValue = -999.0;
5640 const string valid_range_attr_name =
"valid_range";
5641 vector<HDF5CF::Var *>::const_iterator it_v;
5642 vector<HDF5CF::Attribute *>::const_iterator ira;
5645 for (it_v =
vars.begin();
5646 it_v !=
vars.end(); ++it_v) {
5647 if (H5FLOAT32 == (*it_v)->dtype) {
5648 bool has_fillvalue =
false;
5649 bool has_validrange =
false;
5650 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5651 if (fill_value_attr_name == (*ira)->name){
5652 has_fillvalue =
true;
5656 else if(valid_range_attr_name == (*ira)->name) {
5657 has_validrange =
true;
5663 if (has_fillvalue !=
true && has_validrange !=
true ) {
5665 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5666 (*it_v)->attrs.push_back(attr);
5677 string co_attrname =
"coordinates";
5678 string co_attrvalue=
"";
5679 string unit_attrname =
"units";
5680 string nonll_unit_attrvalue =
"level";
5681 string lat_unit_attrvalue =
"degrees_north";
5682 string lon_unit_attrvalue =
"degrees_east";
5684 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5685 ircv != this->cvars.end(); ++ircv) {
5688 if ((*ircv)->cvartype == CV_NONLATLON_MISS) {
5690 Add_Str_Attr(attr,unit_attrname,nonll_unit_attrvalue);
5691 (*ircv)->attrs.push_back(attr);
5694 else if ((*ircv)->cvartype == CV_LAT_MISS) {
5699 Add_Str_Attr(attr,unit_attrname,lat_unit_attrvalue);
5700 (*ircv)->attrs.push_back(attr);
5704 else if ((*ircv)->cvartype == CV_LON_MISS) {
5706 Add_Str_Attr(attr,unit_attrname,lon_unit_attrvalue);
5707 (*ircv)->attrs.push_back(attr);
5712 if(product_type == Mea_SeaWiFS_L2)
5716 else if(product_type == GPM_L1) {
5717 Handle_GPM_l1_Coor_Attr();
5721 else if (
true == iscoard) {
5728 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5729 ircv != this->cvars.end(); ++ircv) {
5730 if((*ircv)->rank == 2) {
5733 if(gp_latname == (*ircv)->name)
5734 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5735 else if(gp_lonname ==(*ircv)->name)
5736 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5741 string ll2d_dimname0,ll2d_dimname1;
5742 bool has_ll2d_coords =
false;
5743 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5744 ircv != this->cvars.end(); ++ircv) {
5745 if((*ircv)->rank == 2) {
5747 ll2d_dimname0 = (*ircv)->getDimensions()[0]->name;
5748 ll2d_dimname1 = (*ircv)->getDimensions()[1]->name;
5749 if(ll2d_dimname0 !=
"" && ll2d_dimname1 !=
"")
5750 has_ll2d_coords =
true;
5755 if(
true == has_ll2d_coords) {
5757 for (vector<Var *>::iterator irv = this->
vars.begin();
5758 irv != this->vars.end(); ++irv) {
5760 bool coor_attr_keep_exist =
false;
5763 if(((*irv)->rank >=2)) {
5765 short ll2dim_flag = 0;
5766 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
5767 ird != (*irv)->dims.end(); ++ ird) {
5768 if((*ird)->name == ll2d_dimname0)
5770 else if((*ird)->name == ll2d_dimname1)
5774 if(ll2dim_flag != 2)
5775 coor_attr_keep_exist =
true;
5778 if(product_type == OSMAPL2S)
5779 coor_attr_keep_exist =
true;
5781 if (
false == coor_attr_keep_exist) {
5782 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
5783 ira !=(*irv)->attrs.end();) {
5784 if ((*ira)->newname == co_attrname) {
5786 ira = (*irv)->attrs.erase(ira);
5794 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
5795 ird != (*irv)->dims.end(); ++ ird) {
5796 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5797 ircv != this->cvars.end(); ++ircv) {
5798 if ((*ird)->name == (*ircv)->cfdimname)
5799 co_attrvalue = (co_attrvalue.empty())
5800 ?(*ircv)->newname:co_attrvalue +
" "+(*ircv)->newname;
5804 if (
false == co_attrvalue.empty()) {
5806 Add_Str_Attr(attr,co_attrname,co_attrvalue);
5807 (*irv)->attrs.push_back(attr);
5810 co_attrvalue.clear();
5822 BESDEBUG(
"h5",
"GMFile::Coming to Handle_Coor_Attr()"<<endl);
5823 string co_attrname =
"coordinates";
5824 string co_attrvalue=
"";
5825 string unit_attrname =
"units";
5826 string nonll_unit_attrvalue =
"level";
5827 string lat_unit_attrvalue =
"degrees_north";
5828 string lon_unit_attrvalue =
"degrees_east";
5832 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5833 ircv != this->cvars.end(); ++ircv) {
5835 if ((*ircv)->cvartype == CV_NONLATLON_MISS) {
5837 Add_Str_Attr(attr,unit_attrname,nonll_unit_attrvalue);
5838 (*ircv)->attrs.push_back(attr);
5840 else if ((*ircv)->cvartype == CV_LAT_MISS) {
5842 Add_Str_Attr(attr,unit_attrname,lat_unit_attrvalue);
5843 (*ircv)->attrs.push_back(attr);
5845 else if ((*ircv)->cvartype == CV_LON_MISS) {
5847 Add_Str_Attr(attr,unit_attrname,lon_unit_attrvalue);
5848 (*ircv)->attrs.push_back(attr);
5853 if(product_type == Mea_SeaWiFS_L2)
5857 else if(product_type == GPM_L1) {
5858 Handle_GPM_l1_Coor_Attr();
5863 else if(product_type == General_Product && gproduct_pattern == GENERAL_LATLON_COOR_ATTR){
5864 Handle_LatLon_With_CoordinateAttr_Coor_Attr();
5868 else if (
true == iscoard) {
5872 if(grp_cv_paths.size() >0) {
5873 for (vector<Var *>::iterator irv = this->
vars.begin();
5874 irv != this->vars.end(); ++irv) {
5875 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) != grp_cv_paths.end()){
5878 Flatten_VarPath_In_Coordinates_Attr(*irv);
5886 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5887 ircv != this->cvars.end(); ++ircv) {
5889 if((*ircv)->rank == 2 && (*ircv)->cvartype == CV_EXIST) {
5895 if(gp_latname == (*ircv)->name) {
5897 if(
false == Is_geolatlon(gp_latname,
true))
5898 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5900 else if(gp_lonname ==(*ircv)->name) {
5902 if(
false == Is_geolatlon(gp_lonname,
false))
5903 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5909 else if(
true == Is_geolatlon((*ircv)->name,
true))
5910 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5912 else if(
true == Is_geolatlon((*ircv)->name,
false))
5913 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5919 if(grp_cv_paths.size() >0) {
5920 for (vector<Var *>::iterator irv = this->
vars.begin();
5921 irv != this->vars.end(); ++irv) {
5922 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) != grp_cv_paths.end()){
5925 Flatten_VarPath_In_Coordinates_Attr(*irv);
5931 bool has_ll2d_coords =
false;
5934 if(General_Product == this->product_type && GENERAL_DIMSCALE == this->gproduct_pattern)
5935 has_ll2d_coords =
true;
5937 string ll2d_dimname0;
5938 string ll2d_dimname1;
5939 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5940 ircv != this->cvars.end(); ++ircv) {
5941 if((*ircv)->rank == 2) {
5943 ll2d_dimname0 = (*ircv)->getDimensions()[0]->name;
5944 ll2d_dimname1 = (*ircv)->getDimensions()[1]->name;
5945 if(ll2d_dimname0 !=
"" && ll2d_dimname1 !=
"")
5946 has_ll2d_coords =
true;
5953 if(
true == has_ll2d_coords) {
5961 bool force_flatten_coor_attr = HDF5RequestHandler::get_force_flatten_coor_attr();
5965 bool has_coor_attr_ge_2d_vars =
false;
5966 for (vector<Var *>::iterator irv = this->
vars.begin();
5967 irv != this->vars.end(); ++irv) {
5968 if((*irv)->rank >=2){
5969 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
5971 if((*ira)->name == co_attrname) {
5972 has_coor_attr_ge_2d_vars =
true;
5976 if(has_coor_attr_ge_2d_vars ==
true)
5983 bool is_hybrid_eos5=
false;
5984 if(force_flatten_coor_attr ==
true && has_coor_attr_ge_2d_vars ==
true)
5985 is_hybrid_eos5 = Is_Hybrid_EOS5();
5987 for (vector<Var *>::iterator irv = this->
vars.begin();
5988 irv != this->vars.end(); ++irv) {
5990 bool has_coor =
false;
5991 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
5993 if((*ira)->name == co_attrname) {
6000 if(
true == force_flatten_coor_attr &&
true == has_coor) {
6002 if(is_hybrid_eos5 ==
true) {
6003 Flatten_VarPath_In_Coordinates_Attr_EOS5((*irv));
6007 Flatten_VarPath_In_Coordinates_Attr((*irv));
6010 else if(((*irv)->rank >=2) && (has_coor_attr_ge_2d_vars ==
false ||
false == force_flatten_coor_attr)) {
6012 bool coor_attr_keep_exist =
false;
6015 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) == grp_cv_paths.end())
6018 coor_attr_keep_exist = Check_Var_2D_CVars(*irv);
6020 coor_attr_keep_exist =
true;
6024 if(product_type == OSMAPL2S)
6025 coor_attr_keep_exist =
true;
6028 if (
false == coor_attr_keep_exist) {
6029 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
6030 ira !=(*irv)->attrs.end();) {
6031 if ((*ira)->newname == co_attrname) {
6033 ira = (*irv)->attrs.erase(ira);
6041 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6042 ird != (*irv)->dims.end(); ++ ird) {
6043 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
6044 ircv != this->cvars.end(); ++ircv) {
6045 if ((*ird)->name == (*ircv)->cfdimname)
6046 co_attrvalue = (co_attrvalue.empty())
6047 ?(*ircv)->newname:co_attrvalue +
" "+(*ircv)->newname;
6051 if (
false == co_attrvalue.empty()) {
6053 Add_Str_Attr(attr,co_attrname,co_attrvalue);
6054 (*irv)->attrs.push_back(attr);
6057 co_attrvalue.clear();
6065 void GMFile:: Handle_GPM_l1_Coor_Attr() {
6067 BESDEBUG(
"h5",
"Coming to Handle_GPM_l1_Coor_Attr()"<<endl);
6081 string co_attrname =
"coordinates";
6082 string co_attrvalue=
"";
6085 set<string> cvar_2d_dimset;
6087 pair<map<string,string>::iterator,
bool>mapret;
6090 map<string,string>cfdimname_to_cvar2dname;
6093 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
6094 irv != this->cvars.end(); ++irv) {
6097 if((*irv)->rank == 2) {
6103 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6104 ird != (*irv)->dims.end(); ++ird) {
6105 cvar_2d_dimset.insert((*ird)->name);
6109 mapret = cfdimname_to_cvar2dname.insert(pair<string,string>((*irv)->cfdimname,(*irv)->newname));
6110 if (
false == mapret.second)
6111 throw4(
"The cf dimension name ",(*irv)->cfdimname,
" should map to 2-D coordinate variable",
6117 for (vector<Var *>::iterator irv = this->
vars.begin();
6118 irv != this->vars.end(); ++irv) {
6121 if((*irv)->rank >=2) {
6125 short have_2d_dimnames_flag = 0;
6126 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6127 ird !=(*irv)->dims.end();++ird) {
6128 if (cvar_2d_dimset.find((*ird)->name)!=cvar_2d_dimset.end())
6129 have_2d_dimnames_flag++;
6133 if(have_2d_dimnames_flag >=2) {
6137 if((*irv)->fullpath.size() > (*irv)->name.size())
6138 var_path=(*irv)->fullpath.substr(0,(*irv)->fullpath.size()-(*irv)->name.size());
6140 throw4(
"The variable full path ",(*irv)->fullpath,
" doesn't contain the variable name ",
6144 short cv_2d_flag = 0;
6147 vector<string> cv_2d_names;
6150 set<string> cv_2d_dimnames;
6153 for(map<string,string>::const_iterator itm = cfdimname_to_cvar2dname.begin();
6154 itm != cfdimname_to_cvar2dname.end();++itm) {
6157 string reduced_dimname = HDF5CFUtil::obtain_string_after_lastslash(itm->first);
6159 if(itm->first.size() <= reduced_dimname.size())
6160 throw2(
"The cf dim. name of this dimension is not right.",itm->first);
6162 cfdim_path= itm->first.substr(0,itm->first.size() - reduced_dimname.size());
6171 if(var_path == cfdim_path) {
6172 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6173 ird!=(*irv)->dims.end();++ird) {
6174 if(reduced_dimname == (*ird)->name) {
6176 cv_2d_names.push_back(itm->second);
6177 cv_2d_dimnames.insert((*ird)->name);
6189 if(cv_2d_flag != 2) {
6192 for(map<string,string>::const_iterator itm = cfdimname_to_cvar2dname.begin();
6193 itm != cfdimname_to_cvar2dname.end();++itm) {
6195 string reduced_dimname = HDF5CFUtil::obtain_string_after_lastslash(itm->first);
6197 if(itm->first.size() <= reduced_dimname.size())
6198 throw2(
"The cf dim. name of this dimension is not right.",itm->first);
6200 cfdim_path= itm->first.substr(0,itm->first.size() - reduced_dimname.size());
6209 if(var_path.find(cfdim_path)!=string::npos) {
6210 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6211 ird!=(*irv)->dims.end();++ird) {
6212 if(reduced_dimname == (*ird)->name) {
6214 cv_2d_names.push_back(itm->second);
6215 cv_2d_dimnames.insert((*ird)->name);
6224 if(2 == cv_2d_flag) {
6227 co_attrvalue = cv_2d_names[0] +
" " + cv_2d_names[1];
6228 if((*irv)->rank >2) {
6229 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6230 ird !=(*irv)->dims.end();++ird) {
6233 if(cv_2d_dimnames.find((*ird)->name) == cv_2d_dimnames.end())
6234 co_attrvalue = co_attrvalue +
" " +(*ird)->newname;
6238 Add_Str_Attr(attr,co_attrname,co_attrvalue);
6239 (*irv)->attrs.push_back(attr);
6247 void GMFile::Handle_LatLon_With_CoordinateAttr_Coor_Attr() {
6249 BESDEBUG(
"h5",
"Coming to Handle_LatLon_With_CoordinateAttr_Coor_Attr()"<<endl);
6250 string co_attrname =
"coordinates";
6253 for (vector<Var *>::iterator irv = this->
vars.begin();
6254 irv != this->vars.end(); ++irv) {
6255 if((*irv)->rank >= 2) {
6256 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end(); ++ira) {
6257 if((*ira)->name == co_attrname) {
6260 string coor_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
6261 if(Coord_Match_LatLon_NameSize(coor_value) ==
true)
6262 Flatten_VarPath_In_Coordinates_Attr(*irv);
6266 else if(Coord_Match_LatLon_NameSize_Same_Group(coor_value,HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) ==
true)
6267 Add_VarPath_In_Coordinates_Attr(*irv,coor_value);
6279 bool GMFile::Coord_Match_LatLon_NameSize(
const string & coord_values) {
6281 BESDEBUG(
"h5",
"Coming to Coord_Match_LatLon_NameSize()"<<endl);
6282 bool ret_value =
false;
6283 vector<string> coord_values_vec;
6285 int match_lat_name_pair_index = -1;
6286 int match_lon_name_pair_index = -2;
6287 int num_match_lat = 0;
6288 int num_match_lon = 0;
6292 HDF5CFUtil::Split_helper(coord_values_vec,coord_values,sep);
6295 if((coord_values_vec[0])[0] !=
'/') {
6296 for(vector<string>::iterator irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6297 if(((*irs).find_first_of(
'/'))!=string::npos) {
6298 *irs =
'/' + (*irs);
6304 for(vector<string>::iterator irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6308 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
6309 if((*irs) == (*ivs).name1){
6310 match_lat_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6313 else if ((*irs) == (*ivs).name2) {
6314 match_lon_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6320 if((match_lat_name_pair_index == match_lon_name_pair_index) && (num_match_lat ==1) && (num_match_lon ==1))
6329 bool GMFile::Coord_Match_LatLon_NameSize_Same_Group(
const string &coord_values,
const string &var_path) {
6331 BESDEBUG(
"h5",
"Coming to Coord_Match_LatLon_NameSize_Same_Group()"<<endl);
6332 bool ret_value =
false;
6333 vector<string> coord_values_vec;
6335 int match_lat_name_pair_index = -1;
6336 int match_lon_name_pair_index = -2;
6337 int num_match_lat = 0;
6338 int num_match_lon = 0;
6340 HDF5CFUtil::Split_helper(coord_values_vec,coord_values,sep);
6343 for(vector<string>::iterator irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6345 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
6346 string lat_name = HDF5CFUtil::obtain_string_after_lastslash((*ivs).name1);
6347 string lat_path = HDF5CFUtil::obtain_string_before_lastslash((*ivs).name1);
6348 string lon_name = HDF5CFUtil::obtain_string_after_lastslash((*ivs).name2);
6349 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*ivs).name2);
6350 if((*irs) == lat_name && lat_path == var_path){
6351 match_lat_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6354 else if ((*irs) == lon_name && lon_path == var_path) {
6355 match_lon_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6361 if((match_lat_name_pair_index == match_lon_name_pair_index) && (num_match_lat ==1) && (num_match_lon ==1))
6368 void GMFile::Add_VarPath_In_Coordinates_Attr(
Var *var,
const string &coor_value) {
6370 BESDEBUG(
"h5",
"Coming to Add_VarPath_In_Coordinates_Attr()"<<endl);
6371 string new_coor_value;
6373 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var->fullpath) ;
6374 string var_flatten_path = get_CF_string(var_path);
6377 size_t ele_start_pos = 0;
6378 size_t cur_pos = coor_value.find_first_of(sep);
6379 while(cur_pos !=string::npos) {
6380 string tempstr = coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
6381 tempstr = var_flatten_path + tempstr;
6382 new_coor_value += tempstr + sep;
6383 ele_start_pos = cur_pos+1;
6384 cur_pos = coor_value.find_first_of(sep,cur_pos+1);
6387 if(ele_start_pos == 0)
6388 new_coor_value = var_flatten_path + coor_value;
6390 new_coor_value += var_flatten_path + coor_value.substr(ele_start_pos);
6392 string coor_attr_name =
"coordinates";
6393 Replace_Var_Str_Attr(var,coor_attr_name,new_coor_value);
6398 void GMFile:: Create_Missing_CV(
GMCVar *GMcvar,
const string& dimname) {
6400 BESDEBUG(
"h5",
"GMFile::Coming to Create_Missing_CV()"<<endl);
6402 GMcvar->name = dimname;
6403 GMcvar->newname = GMcvar->name;
6404 GMcvar->fullpath = GMcvar->name;
6406 GMcvar->dtype = H5INT32;
6407 hsize_t gmcvar_dimsize = dimname_to_dimsize[dimname];
6408 bool unlimited_flag = dimname_to_unlimited[dimname];
6410 gmcvar_dim->unlimited_dim = unlimited_flag;
6411 gmcvar_dim->name = dimname;
6412 gmcvar_dim->newname = dimname;
6413 GMcvar->dims.push_back(gmcvar_dim);
6414 GMcvar->cfdimname = dimname;
6415 GMcvar->cvartype = CV_NONLATLON_MISS;
6416 GMcvar->product_type = product_type;
6421 bool GMFile::Is_netCDF_Dimension(
Var *var) {
6423 string netcdf_dim_mark =
"This is a netCDF dimension but not a netCDF variable";
6425 bool is_only_dimension =
false;
6427 for(vector<Attribute *>::iterator ira = var->attrs.begin();
6428 ira != var->attrs.end();ira++) {
6430 if (
"NAME" == (*ira)->name) {
6432 Retrieve_H5_Attr_Value(*ira,var->fullpath);
6434 name_value.resize((*ira)->value.size());
6435 copy((*ira)->value.begin(),(*ira)->value.end(),name_value.begin());
6438 if (0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark))
6439 is_only_dimension =
true;
6445 return is_only_dimension;
6455 GMFile::Is_Hybrid_EOS5() {
6457 bool has_group_hdfeos =
false;
6458 bool has_group_hdfeos_info =
false;
6464 for (vector<Group *>::iterator irg = this->
groups.begin();
6465 irg != this->groups.end(); ++ irg) {
6466 if (
"/HDFEOS" == (*irg)->path)
6467 has_group_hdfeos =
true;
6468 else if(
"/HDFEOS INFORMATION" == (*irg)->path) {
6469 for(vector<Attribute *>::iterator ira = (*irg)->attrs.begin();
6470 ira != (*irg)->attrs.end();ira++) {
6471 if(
"HDFEOSVersion" == (*ira)->name)
6472 has_group_hdfeos_info =
true;
6475 if(
true == has_group_hdfeos &&
true == has_group_hdfeos_info)
6480 if(
true == has_group_hdfeos &&
true == has_group_hdfeos_info)
6486 void GMFile::Handle_Hybrid_EOS5() {
6488 string eos_str=
"HDFEOS_";
6489 string eos_info_str=
"HDFEOS_INFORMATION_";
6490 string grid_str=
"GRIDS_";
6491 string swath_str=
"SWATHS_";
6492 string zas_str=
"ZAS_";
6493 string df_str=
"Data_Fields_";
6494 string gf_str=
"Geolocation_Fields_";
6495 for (vector<Var *>::iterator irv = this->
vars.begin();
6496 irv != this->vars.end(); irv++) {
6497 string temp_var_name = (*irv)->newname;
6499 bool remove_eos = Remove_EOS5_Strings(temp_var_name);
6501 if(
true == remove_eos)
6502 (*irv)->newname = get_CF_string(temp_var_name);
6504 string::size_type eos_info_pos = temp_var_name.find(eos_info_str);
6505 if(eos_info_pos !=string::npos)
6506 (*irv)->newname = temp_var_name.erase(eos_info_pos,eos_info_str.size());
6508 if(Remove_EOS5_Strings_NonEOS_Fields(temp_var_name)==
true)
6509 (*irv)->newname = get_CF_string(temp_var_name);
6515 for (vector<Var *>::iterator irv = this->
vars.begin();
6516 irv != this->vars.end(); irv++) {
6517 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6518 ird!=(*irv)->dims.end(); ++ird) {
6519 string temp_dim_name = (*ird)->newname;
6520 bool remove_eos = Remove_EOS5_Strings(temp_dim_name);
6522 if(
true == remove_eos)
6523 (*ird)->newname = get_CF_string(temp_dim_name);
6525 string::size_type eos_info_pos = temp_dim_name.find(eos_info_str);
6526 if(eos_info_pos !=string::npos)
6527 (*ird)->newname = temp_dim_name.erase(eos_info_pos,eos_info_str.size());
6529 if(Remove_EOS5_Strings_NonEOS_Fields(temp_dim_name)==
true)
6530 (*ird)->newname = get_CF_string(temp_dim_name);
6537 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
6538 irv != this->cvars.end(); ++irv) {
6539 string temp_var_name = (*irv)->newname;
6541 bool remove_eos = Remove_EOS5_Strings(temp_var_name);
6543 if(
true == remove_eos)
6544 (*irv)->newname = get_CF_string(temp_var_name);
6546 string::size_type eos_info_pos = temp_var_name.find(eos_info_str);
6547 if(eos_info_pos !=string::npos)
6548 (*irv)->newname = temp_var_name.erase(eos_info_pos,eos_info_str.size());
6550 if(Remove_EOS5_Strings_NonEOS_Fields(temp_var_name)==
true)
6551 (*irv)->newname = get_CF_string(temp_var_name);
6556 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
6557 irv != this->cvars.end(); irv++) {
6558 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6559 ird!=(*irv)->dims.end(); ++ird) {
6560 string temp_dim_name = (*ird)->newname;
6561 bool remove_eos = Remove_EOS5_Strings(temp_dim_name);
6563 if(
true == remove_eos)
6564 (*ird)->newname = get_CF_string(temp_dim_name);
6566 string::size_type eos_info_pos = temp_dim_name.find(eos_info_str);
6567 if(eos_info_pos !=string::npos)
6568 (*ird)->newname = temp_dim_name.erase(eos_info_pos,eos_info_str.size());
6570 if(Remove_EOS5_Strings_NonEOS_Fields(temp_dim_name)==
true)
6571 (*ird)->newname = get_CF_string(temp_dim_name);
6580 for (vector<Var *>::iterator irv = this->
vars.begin();
6581 irv != this->vars.end(); irv++) {
6582 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
6583 ira != (*irv)->attrs.end();ira++) {
6586 if((*ira)->name ==
"coordinates") {
6587 string cor_values((*ira)->value.begin(),(*ira)->value.end()) ;
6588 bool change_cor_values =
false;
6590 if(cor_values.find(eos_str)==0) {
6591 if(cor_values.find(grid_str)!=string::npos) {
6592 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6593 cor_values = HDF5CFUtil::remove_substrings(cor_values,grid_str);
6594 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6595 if(new_cor_values.size() < cor_values.size()){
6596 change_cor_values =
true;
6597 cor_values = new_cor_values;
6600 else if(cor_values.find(zas_str)!=string::npos) {
6601 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6602 cor_values = HDF5CFUtil::remove_substrings(cor_values,zas_str);
6603 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6604 if(new_cor_values.size() < cor_values.size()){
6605 change_cor_values =
true;
6606 cor_values = new_cor_values;
6609 else if(cor_values.find(swath_str)!=string::npos) {
6610 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6611 cor_values = HDF5CFUtil::remove_substrings(cor_values,swath_str);
6612 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6613 if(new_cor_values.size() < cor_values.size()){
6614 change_cor_values =
true;
6615 cor_values = new_cor_values;
6618 new_cor_values = HDF5CFUtil::remove_substrings(cor_values,gf_str);
6619 if(new_cor_values.size() < cor_values.size()){
6620 change_cor_values =
true;
6621 cor_values = new_cor_values;
6626 if(
true == change_cor_values) {
6627 (*ira)->value.resize(cor_values.size());
6628 (*ira)->fstrsize=cor_values.size();
6629 (*ira)->strsize[0] = cor_values.size();
6630 copy(cor_values.begin(), cor_values.end(), (*ira)->value.begin());
6641 bool GMFile:: Remove_EOS5_Strings(
string &var_name) {
6643 string eos_str=
"HDFEOS_";
6644 string grid_str=
"GRIDS_";
6645 string swath_str=
"SWATHS_";
6646 string zas_str=
"ZAS_";
6647 string df_str=
"Data_Fields_";
6648 string gf_str=
"Geolocation_Fields_";
6649 string temp_var_name = var_name;
6651 bool remove_eos =
false;
6653 string::size_type eos_pos = temp_var_name.find(eos_str);
6654 if(eos_pos!=string::npos) {
6655 temp_var_name.erase(eos_pos,eos_str.size());
6657 string::size_type grid_pos=temp_var_name.find(grid_str);
6658 string::size_type grid_df_pos=string::npos;
6659 if(grid_pos!=string::npos)
6660 grid_df_pos = temp_var_name.find(df_str,grid_pos);
6661 string::size_type zas_pos = string::npos;
6662 string::size_type zas_df_pos=string::npos;
6663 if(grid_pos==string::npos || grid_df_pos ==string::npos)
6664 zas_pos=temp_var_name.find(zas_str);
6665 if(zas_pos!=string::npos)
6666 zas_df_pos=temp_var_name.find(df_str,zas_pos);
6668 if(grid_pos !=string::npos && grid_df_pos!=string::npos) {
6669 temp_var_name.erase(grid_pos,grid_str.size());
6670 grid_df_pos = temp_var_name.find(df_str);
6671 temp_var_name.erase(grid_df_pos,df_str.size());
6674 else if(zas_pos!=string::npos && zas_df_pos!=string::npos){
6675 temp_var_name.erase(zas_pos,zas_str.size());
6676 zas_df_pos = temp_var_name.find(df_str);
6677 temp_var_name.erase(zas_df_pos,df_str.size());
6682 string::size_type swath_pos=temp_var_name.find(swath_str);
6683 string::size_type swath_df_pos=string::npos;
6684 if(swath_pos!=string::npos)
6685 swath_df_pos=temp_var_name.find(df_str,swath_pos);
6687 string::size_type swath_gf_pos=string::npos;
6688 if(swath_pos!=string::npos && swath_df_pos == string::npos)
6689 swath_gf_pos=temp_var_name.find(gf_str,swath_pos);
6691 if(swath_pos !=string::npos) {
6693 if(swath_df_pos!=string::npos) {
6694 temp_var_name.erase(swath_pos,swath_str.size());
6695 swath_df_pos = temp_var_name.find(df_str);
6696 temp_var_name.erase(swath_df_pos,df_str.size());
6699 else if(swath_gf_pos!=string::npos) {
6700 temp_var_name.erase(swath_pos,swath_str.size());
6701 swath_gf_pos = temp_var_name.find(gf_str);
6702 temp_var_name.erase(swath_gf_pos,gf_str.size());
6708 if(
true == remove_eos)
6709 var_name = temp_var_name;
6714 bool GMFile:: Remove_EOS5_Strings_NonEOS_Fields(
string &var_name) {
6716 string eos_str=
"HDFEOS_";
6717 string grid_str=
"GRIDS_";
6718 string swath_str=
"SWATHS_";
6719 string zas_str=
"ZAS_";
6720 string temp_var_name = var_name;
6722 bool remove_eos =
false;
6724 string::size_type eos_pos = temp_var_name.find(eos_str);
6725 if(eos_pos!=string::npos) {
6726 temp_var_name.erase(eos_pos,eos_str.size());
6730 if(temp_var_name.find(grid_str)==0)
6731 temp_var_name.erase(0,grid_str.size());
6732 else if(temp_var_name.find(swath_str)==0)
6733 temp_var_name.erase(0,swath_str.size());
6734 else if(temp_var_name.find(zas_str)==0)
6735 temp_var_name.erase(0,zas_str.size());
6737 if(
true == remove_eos)
6738 var_name = temp_var_name;
6759 if(this->unsupported_var_dtype ==
true) {
6762 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
6763 ircv != this->cvars.end();) {
6764 if((*ircv)->newname.find(
"FakeDim")==0) {
6765 bool var_has_fakedim =
false;
6766 for (vector<Var*>::iterator irv2 = this->
vars.begin();
6767 irv2 != this->vars.end(); irv2++) {
6768 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
6769 ird !=(*irv2)->dims.end(); ird++) {
6770 if((*ird)->newname == (*ircv)->newname){
6771 var_has_fakedim =
true;
6775 if(var_has_fakedim ==
true)
6778 if(var_has_fakedim ==
false) {
6781 ircv = this->cvars.erase(ircv);
6803 if(
true == this->have_nc4_non_coord) {
6804 string nc4_non_coord=
"_nc4_non_coord_";
6805 size_t nc4_non_coord_size= nc4_non_coord.size();
6806 for (vector<Var*>::iterator irv = this->
vars.begin();
6807 irv != this->vars.end(); irv++) {
6808 if((*irv)->name.find(nc4_non_coord)==0)
6809 (*irv)->newname = (*irv)->newname.substr(nc4_non_coord_size,(*irv)->newname.size()-nc4_non_coord_size);
6812 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
6813 ircv != this->cvars.end();++ircv) {
6814 if((*ircv)->name.find(nc4_non_coord)==0)
6815 (*ircv)->newname = (*ircv)->newname.substr(nc4_non_coord_size,(*ircv)->newname.size()-nc4_non_coord_size);
6823 GMFile::release_standalone_GMCVar_vector(vector<GMCVar*>&tempgc_vars){
6825 for (vector<GMCVar *>::iterator i = tempgc_vars.begin();
6826 i != tempgc_vars.end(); ) {
6828 i = tempgc_vars.erase(i);
6835 GMFile::add_ignored_info_attrs(
bool is_grp,
bool is_first){
6839 GMFile::add_ignored_info_objs(
bool is_dim_related,
bool is_first) {
6846 GMFile::ignored_dimscale_ref_list(
Var *var) {
6848 bool ignored_dimscale =
true;
6849 if(General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern) {
6851 bool has_dimscale =
false;
6852 bool has_reference_list =
false;
6853 for(vector<Attribute *>::iterator ira = var->attrs.begin();
6854 ira != var->attrs.end();ira++) {
6855 if((*ira)->name ==
"REFERENCE_LIST" &&
6856 false == HDF5CFUtil::cf_strict_support_type((*ira)->getType()))
6857 has_reference_list =
true;
6858 if((*ira)->name ==
"CLASS") {
6859 Retrieve_H5_Attr_Value(*ira,var->fullpath);
6861 class_value.resize((*ira)->value.size());
6862 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
6866 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
6867 has_dimscale =
true;
6871 if(
true == has_dimscale &&
true == has_reference_list) {
6872 ignored_dimscale=
false;
6878 return ignored_dimscale;
This class specifies the core engineering of mapping HDF5 to DAP by following CF.
#define throw1(a1)
The followings are convenient functions to throw exceptions with different.
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 Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for general HDF5 products.
void Adjust_Obj_Name()
Adjust object names based on different general NASA HDF5 products.
void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
void Adjust_Dim_Name()
Adjust dimension name for general NASA HDF5 products.
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.
void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr)
Retrieve DDS information from the HDF5 file; real implementation for general HDF5 products.
void Handle_SpVar()
Handle special variables for general NASA HDF5 products.
void Adjust_H5_Attr_Value(Attribute *attr)
Adjust attribute values for general HDF5 products.
void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for general HDF5 products.
void Handle_SpVar_Attr()
Handle special variable attributes for general NASA HDF5 products.
void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for general HDF5 products.
void Remove_Unneeded_Objects()
Remove unneeded objects.
void Add_Dim_Name()
Add dimension name.
void Flatten_Obj_Name(bool include_attr)
Flatten the object name for general NASA HDF5 products.
void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
void Handle_DimNameClashing()
void Handle_Coor_Attr()
Handle "coordinates" attributes for general HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
void Handle_CVar()
Handle coordinate variables for 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)