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") {
727 string name_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
728 if( 0 == name_value.compare(0,(*irv)->name.size(),(*irv)->name)) {
730 ira =(*irv)->attrs.erase(ira);
733 string netcdf_dim_mark=
"This is a netCDF dimension but not a netCDF variable";
734 if( 0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark)) {
736 ira =(*irv)->attrs.erase(ira);
743 else if((*ira)->name ==
"_Netcdf4Dimid") {
745 ira =(*irv)->attrs.erase(ira);
748 else if((*ira)->name ==
"_nc3_strict") {
750 ira =(*irv)->attrs.erase(ira);
763 if(
true == this->check_ignored &&
true == include_attr) {
764 if(
true == HDF5RequestHandler::get_drop_long_string()){
765 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
766 irv != this->cvars.end(); ++irv) {
767 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
768 ira != (*irv)->attrs.end();++ira) {
769 if(
true == Check_DropLongStr((*irv),(*ira))) {
770 this->add_ignored_droplongstr_hdr();
771 this->add_ignored_var_longstr_info((*irv),(*ira));
776 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
777 irv != this->spvars.end(); ++irv) {
778 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
779 ira != (*irv)->attrs.end();++ira) {
780 if(
true == Check_DropLongStr((*irv),(*ira))) {
781 this->add_ignored_droplongstr_hdr();
782 this->add_ignored_var_longstr_info((*irv),(*ira));
791 if(
false == this->have_ignored)
792 this->add_no_ignored_info();
799 BESDEBUG(
"h5",
"Coming to GMFile:Add_Dim_Name()"<<endl);
800 switch(product_type) {
803 Add_Dim_Name_Mea_SeaWiFS();
806 Add_Dim_Name_Aqu_L3();
809 Add_Dim_Name_OSMAPL2S();
811 case ACOS_L2S_OR_OCO2_L1B:
812 Add_Dim_Name_ACOS_L2S_OCO2_L1B();
815 Add_Dim_Name_Mea_Ozonel3z();
823 Add_Dim_Name_OBPG_L3();
825 case General_Product:
826 Add_Dim_Name_General_Product();
829 throw1(
"Cannot generate dim. names for unsupported datatype");
834 for (vector<Var*>::iterator irv2 = this->
vars.begin();
835 irv2 != this->
vars.end(); irv2++) {
836 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
837 ird !=(*irv2)->dims.end(); ird++) {
838 cerr<<
"Dimension name afet Add_Dim_Name "<<(*ird)->newname <<endl;
846 void GMFile::Add_Dim_Name_OBPG_L3() {
848 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_OBPG_L3()"<<endl);
851 Check_General_Product_Pattern();
852 Add_Dim_Name_General_Product();
856 void GMFile::Add_Dim_Name_Mea_SeaWiFS() {
858 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Mea_SeaWiFS()"<<endl);
859 pair<set<string>::iterator,
bool> setret;
860 if (Mea_SeaWiFS_L3 == product_type)
862 for (vector<Var *>::iterator irv = this->
vars.begin();
863 irv != this->
vars.end(); ++irv) {
864 Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
865 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
866 ird !=(*irv)->dims.end();++ird) {
867 setret = dimnamelist.insert((*ird)->name);
868 if (
true == setret.second)
869 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
873 if (
true == dimnamelist.empty())
874 throw1(
"This product should have the dimension names, but no dimension names are found");
878 void GMFile::Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(
Var* var)
881 BESDEBUG(
"h5",
"Coming to Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
883 bool has_dimlist =
false;
884 bool has_class =
false;
885 bool has_reflist =
false;
887 for(vector<Attribute *>::iterator ira = var->attrs.begin();
888 ira != var->attrs.end();ira++) {
889 if (
"DIMENSION_LIST" == (*ira)->name) {
893 if (
"CLASS" == (*ira)->name)
895 if (
"REFERENCE_LIST" == (*ira)->name)
898 if (
true == has_dimlist)
900 if (
true == has_class &&
true == has_reflist)
904 if (
true == has_dimlist)
905 Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(var,dimlistattr);
908 else if(
true == has_class &&
true == has_reflist) {
909 if (var->dims.size() !=1)
910 throw2(
"dimension scale dataset must be 1 dimension, this is not true for variable ",
915 (var->dims)[0]->name = var->fullpath;
916 (var->dims)[0]->newname = var->fullpath;
917 pair<set<string>::iterator,
bool> setret;
918 setret = dimnamelist.insert((var->dims)[0]->name);
919 if (
true == setret.second)
920 Insert_One_NameSizeMap_Element((var->dims)[0]->name,(var->dims)[0]->size,(var->dims)[0]->unlimited_dim);
928 set<hsize_t> fakedimsize;
929 pair<set<hsize_t>::iterator,
bool> setsizeret;
930 for (vector<Dimension *>::iterator ird= var->dims.begin();
931 ird != var->dims.end(); ++ird) {
932 Add_One_FakeDim_Name(*ird);
933 setsizeret = fakedimsize.insert((*ird)->size);
934 if (
false == setsizeret.second)
935 Adjust_Duplicate_FakeDim_Name(*ird);
939 for (
int i = 0; i < var->dims.size(); ++i) {
940 Add_One_FakeDim_Name((var->dims)[i]);
941 bool gotoMainLoop =
false;
942 for (
int j =i-1; j>=0 && !gotoMainLoop; --j) {
943 if (((var->dims)[i])->size == ((var->dims)[j])->size){
944 Adjust_Duplicate_FakeDim_Name((var->dims)[i]);
955 void GMFile::Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone(
Var *var,
Attribute*dimlistattr)
958 BESDEBUG(
"h5",
"Coming to Add_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone()"<<endl);
959 ssize_t objnamelen = -1;
966 hid_t amemtype_id = -1;
967 hid_t aspace_id = -1;
971 if(NULL == dimlistattr)
972 throw2(
"Cannot obtain the dimension list attribute for variable ",var->name);
975 throw2(
"The number of dimension should NOT be 0 for the variable ",var->name);
979 vlbuf.resize(var->rank);
981 dset_id = H5Dopen(this->fileid,(var->fullpath).c_str(),H5P_DEFAULT);
983 throw2(
"Cannot open the dataset ",var->fullpath);
985 attr_id = H5Aopen(dset_id,(dimlistattr->name).c_str(),H5P_DEFAULT);
987 throw4(
"Cannot open the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
989 atype_id = H5Aget_type(attr_id);
991 throw4(
"Cannot obtain the datatype of the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
993 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
996 throw2(
"Cannot obtain the memory datatype for the attribute ",dimlistattr->name);
999 if (H5Aread(attr_id,amemtype_id,&vlbuf[0]) <0)
1000 throw2(
"Cannot obtain the referenced object for the variable ",var->name);
1003 vector<char> objname;
1004 int vlbuf_index = 0;
1007 for (vector<Dimension *>::iterator ird = var->dims.begin();
1008 ird != var->dims.end(); ++ird) {
1010 if(vlbuf[vlbuf_index].p== NULL)
1011 throw4(
"The dimension doesn't exist. Var name is ",var->name,
"; the dimension index is ",vlbuf_index);
1012 rbuf =((hobj_ref_t*)vlbuf[vlbuf_index].p)[0];
1013 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0)
1014 throw2(
"Cannot dereference from the DIMENSION_LIST attribute for the variable ",var->name);
1016 if ((objnamelen= H5Iget_name(ref_dset,NULL,0))<=0)
1017 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
1018 objname.resize(objnamelen+1);
1019 if ((objnamelen= H5Iget_name(ref_dset,&objname[0],objnamelen+1))<=0)
1020 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
1022 string objname_str = string(objname.begin(),objname.end());
1023 string trim_objname = objname_str.substr(0,objnamelen);
1024 (*ird)->name = string(trim_objname.begin(),trim_objname.end());
1026 pair<set<string>::iterator,
bool> setret;
1027 setret = dimnamelist.insert((*ird)->name);
1028 if (
true == setret.second)
1029 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1030 (*ird)->newname = (*ird)->name;
1037 if(vlbuf.size()!= 0) {
1039 if ((aspace_id = H5Aget_space(attr_id)) < 0)
1040 throw2(
"Cannot get hdf5 dataspace id for the attribute ",dimlistattr->name);
1042 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)&vlbuf[0])<0)
1043 throw2(
"Cannot successfully clean up the variable length memory for the variable ",var->name);
1045 H5Sclose(aspace_id);
1050 H5Tclose(amemtype_id);
1061 if(amemtype_id != -1)
1062 H5Tclose(amemtype_id);
1065 H5Sclose(aspace_id);
1079 void GMFile::Add_Dim_Name_Mea_Ozonel3z() {
1081 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Mea_Ozonel3z()"<<endl);
1083 bool use_dimscale =
false;
1085 for (vector<Group *>::iterator irg = this->
groups.begin();
1086 irg != this->
groups.end(); ++ irg) {
1087 if (
"/Dimensions" == (*irg)->path) {
1088 use_dimscale =
true;
1093 if (
false == use_dimscale) {
1095 bool has_dimlist =
false;
1096 bool has_class =
false;
1097 bool has_reflist =
false;
1099 for (vector<Var *>::iterator irv = this->
vars.begin();
1100 irv != this->
vars.end(); irv++) {
1102 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1103 ira != (*irv)->attrs.end();ira++) {
1104 if (
"DIMENSION_LIST" == (*ira)->name)
1107 if (
true == has_dimlist)
1111 if (
true == has_dimlist) {
1112 for (vector<Var *>::iterator irv = this->
vars.begin();
1113 irv != this->
vars.end(); irv++) {
1115 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1116 ira != (*irv)->attrs.end();ira++) {
1117 if (
"CLASS" == (*ira)->name)
1119 if (
"REFERENCE_LIST" == (*ira)->name)
1121 if (
true == has_class &&
true == has_reflist)
1125 if (
true == has_class &&
1126 true == has_reflist)
1130 if (
true == has_class &&
true == has_reflist)
1131 use_dimscale =
true;
1135 if (
true == use_dimscale) {
1137 pair<set<string>::iterator,
bool> setret;
1138 for (vector<Var *>::iterator irv = this->
vars.begin();
1139 irv != this->
vars.end(); ++irv) {
1140 Handle_UseDimscale_Var_Dim_Names_Mea_SeaWiFS_Ozone((*irv));
1141 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
1142 ird !=(*irv)->dims.end();++ird) {
1143 setret = dimnamelist.insert((*ird)->name);
1144 if(
true == setret.second)
1145 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1149 if (
true == dimnamelist.empty())
1150 throw1(
"This product should have the dimension names, but no dimension names are found");
1156 multimap<hsize_t,string> ozonedimsize_to_dimname;
1157 pair<multimap<hsize_t,string>::iterator,multimap<hsize_t,string>::iterator> mm_er_ret;
1158 multimap<hsize_t,string>::iterator irmm;
1160 for (vector<Var *>::iterator irv = this->
vars.begin();
1161 irv != this->
vars.end(); ++irv) {
1162 bool is_cv = check_cv((*irv)->name);
1163 if (
true == is_cv) {
1164 if ((*irv)->dims.size() != 1)
1165 throw3(
"The coordinate variable", (*irv)->name,
" must be one dimension for the zonal average product");
1166 ozonedimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[0]->size,(*irv)->fullpath));
1170 set<hsize_t> fakedimsize;
1171 pair<set<hsize_t>::iterator,
bool> setsizeret;
1172 pair<set<string>::iterator,
bool> setret;
1173 pair<set<string>::iterator,
bool> tempsetret;
1174 set<string> tempdimnamelist;
1175 bool fakedimflag =
false;
1177 for (vector<Var *>::iterator irv = this->
vars.begin();
1178 irv != this->
vars.end(); ++irv) {
1180 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
1181 ird != (*irv)->dims.end(); ++ird) {
1184 mm_er_ret = ozonedimsize_to_dimname.equal_range((*ird)->size);
1185 for (irmm = mm_er_ret.first; irmm!=mm_er_ret.second;irmm++) {
1186 setret = tempdimnamelist.insert(irmm->second);
1187 if (
true == setret.second) {
1188 (*ird)->name = irmm->second;
1189 (*ird)->newname = (*ird)->name;
1190 setret = dimnamelist.insert((*ird)->name);
1191 if(setret.second) Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1192 fakedimflag =
false;
1197 if (
true == fakedimflag) {
1198 Add_One_FakeDim_Name(*ird);
1199 setsizeret = fakedimsize.insert((*ird)->size);
1200 if (
false == setsizeret.second)
1201 Adjust_Duplicate_FakeDim_Name(*ird);
1205 tempdimnamelist.clear();
1206 fakedimsize.clear();
1212 bool GMFile::check_cv(
string & varname) {
1214 BESDEBUG(
"h5",
"Coming to check_cv()"<<endl);
1215 const string lat_name =
"Latitude";
1216 const string time_name =
"Time";
1217 const string ratio_pressure_name =
"MixingRatioPressureLevels";
1218 const string profile_pressure_name =
"ProfilePressureLevels";
1219 const string wave_length_name =
"Wavelength";
1221 if (lat_name == varname)
1223 else if (time_name == varname)
1225 else if (ratio_pressure_name == varname)
1227 else if (profile_pressure_name == varname)
1229 else if (wave_length_name == varname)
1236 void GMFile::Add_Dim_Name_GPM()
1239 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_GPM()"<<endl);
1241 pair<set<string>::iterator,
bool> setret;
1253 for (vector<Var *>::iterator irv = this->
vars.begin();
1254 irv != this->
vars.end(); irv++) {
1256 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1257 ira != (*irv)->attrs.end(); ++ira) {
1259 if(
"DimensionNames" == (*ira)->name) {
1261 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1262 string dimname_value((*ira)->value.begin(),(*ira)->value.end());
1264 vector<string> ind_elems;
1268 if(ind_elems.size() != (size_t)((*irv)->getRank())) {
1269 throw2(
"The number of dims obtained from the <DimensionNames> attribute is not equal to the rank ",
1273 for(
unsigned int i = 0; i<ind_elems.size(); ++i) {
1275 ((*irv)->dims)[i]->name = ind_elems[i];
1279 if(((*irv)->dims)[i]->name==
""){
1280 Add_One_FakeDim_Name(((*irv)->dims)[i]);
1283 string fakedim =
"FakeDim";
1284 stringstream sdim_count;
1285 sdim_count << dim_count;
1286 fakedim = fakedim + sdim_count.str();
1288 ((*irv)->dims)[i]->name = fakedim;
1289 ((*irv)->dims)[i]->newname = fakedim;
1290 ind_elems[i] = fakedim;
1295 ((*irv)->dims)[i]->newname = ind_elems[i];
1296 setret = dimnamelist.insert(((*irv)->dims)[i]->name);
1298 if (
true == setret.second) {
1299 Insert_One_NameSizeMap_Element(((*irv)->dims)[i]->name,
1300 ((*irv)->dims)[i]->size,
1301 ((*irv)->dims)[i]->unlimited_dim);
1304 if(dimname_to_dimsize[((*irv)->dims)[i]->name] !=((*irv)->dims)[i]->size)
1305 throw5(
"Dimension ",((*irv)->dims)[i]->name,
"has two sizes",
1306 ((*irv)->dims)[i]->size,dimname_to_dimsize[((*irv)->dims)[i]->name]);
1318 if(
false == has_dim_name_attr) {
1320 throw4(
"The variable ", (*irv)->name,
" doesn't have the DimensionNames attribute.",
1321 "We currently don't support this case. Please report to the NASA data center.");
1330 void GMFile::Add_Dim_Name_Aqu_L3()
1332 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Aqu_L3()"<<endl);
1333 for (vector<Var *>::iterator irv = this->
vars.begin();
1334 irv != this->
vars.end(); irv++) {
1335 if (
"l3m_data" == (*irv)->name) {
1336 ((*irv)->dims)[0]->name =
"lat";
1337 ((*irv)->dims)[0]->newname =
"lat";
1338 ((*irv)->dims)[1]->name =
"lon";
1339 ((*irv)->dims)[1]->newname =
"lon";
1346 if (
"palette" == (*irv)->name) {
1348 ((*irv)->dims)[0]->name =
"paldim0";
1349 ((*irv)->dims)[0]->newname =
"paldim0";
1350 ((*irv)->dims)[1]->name =
"paldim1";
1351 ((*irv)->dims)[1]->newname =
"paldim1";
1359 void GMFile::Add_Dim_Name_OSMAPL2S(){
1361 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_OSMAPL2S()"<<endl);
1362 string tempvarname =
"";
1363 string key =
"_lat";
1364 string osmapl2sdim0 =
"YDim";
1365 string osmapl2sdim1 =
"XDim";
1368 multimap<hsize_t,string> osmapl2sdimsize_to_dimname;
1369 pair<multimap<hsize_t,string>::iterator,multimap<hsize_t,string>::iterator> mm_er_ret;
1370 multimap<hsize_t,string>::iterator irmm;
1373 for (vector<Var *>::iterator irv = this->
vars.begin();
1374 irv != this->
vars.end(); ++irv) {
1375 tempvarname = (*irv)->name;
1376 if ((tempvarname.size() > key.size())&&
1377 (key == tempvarname.substr(tempvarname.size()-key.size(),key.size()))){
1378 if ((*irv)->dims.size() !=2)
1379 throw1(
"Currently only 2D lat/lon is supported for OSMAPL2S");
1380 osmapl2sdimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[0]->size,osmapl2sdim0));
1381 osmapl2sdimsize_to_dimname.insert(pair<hsize_t,string>(((*irv)->dims)[1]->size,osmapl2sdim1));
1386 set<hsize_t> fakedimsize;
1387 pair<set<hsize_t>::iterator,
bool> setsizeret;
1388 pair<set<string>::iterator,
bool> setret;
1389 pair<set<string>::iterator,
bool> tempsetret;
1390 set<string> tempdimnamelist;
1391 bool fakedimflag =
false;
1394 for (vector<Var *>::iterator irv = this->
vars.begin();
1395 irv != this->
vars.end(); ++irv) {
1397 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
1398 ird != (*irv)->dims.end(); ++ird) {
1401 mm_er_ret = osmapl2sdimsize_to_dimname.equal_range((*ird)->size);
1402 for (irmm = mm_er_ret.first; irmm!=mm_er_ret.second;irmm++) {
1403 setret = tempdimnamelist.insert(irmm->second);
1404 if (setret.second) {
1405 (*ird)->name = irmm->second;
1406 (*ird)->newname = (*ird)->name;
1407 setret = dimnamelist.insert((*ird)->name);
1408 if(setret.second) Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
1409 fakedimflag =
false;
1414 if (
true == fakedimflag) {
1415 Add_One_FakeDim_Name(*ird);
1416 setsizeret = fakedimsize.insert((*ird)->size);
1417 if (!setsizeret.second)
1418 Adjust_Duplicate_FakeDim_Name(*ird);
1421 tempdimnamelist.clear();
1422 fakedimsize.clear();
1427 void GMFile::Add_Dim_Name_ACOS_L2S_OCO2_L1B(){
1429 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_ACOS_L2S_OCO2_L1B()"<<endl);
1430 for (vector<Var *>::iterator irv = this->
vars.begin();
1431 irv != this->
vars.end(); ++irv) {
1433 set<hsize_t> fakedimsize;
1434 pair<set<hsize_t>::iterator,
bool> setsizeret;
1435 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1436 ird != (*irv)->dims.end(); ++ird) {
1437 Add_One_FakeDim_Name(*ird);
1438 setsizeret = fakedimsize.insert((*ird)->size);
1439 if (
false == setsizeret.second)
1440 Adjust_Duplicate_FakeDim_Name(*ird);
1446 void GMFile::Add_Dim_Name_General_Product(){
1448 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_General_Product()"<<endl);
1451 if (GENERAL_DIMSCALE == this->gproduct_pattern){
1452 Add_Dim_Name_Dimscale_General_Product();
1455 else if (GENERAL_LATLON2D == this->gproduct_pattern)
1456 Add_Dim_Name_LatLon2D_General_Product();
1458 else if (GENERAL_LATLON1D == this->gproduct_pattern || GENERAL_LATLON_COOR_ATTR == this->gproduct_pattern)
1459 Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product();
1472 void GMFile::Check_General_Product_Pattern() {
1474 BESDEBUG(
"h5",
"Coming to Check_General_Product_Pattern()"<<endl);
1475 if(
false == Check_Dimscale_General_Product_Pattern()) {
1476 if(
false == Check_LatLon2D_General_Product_Pattern())
1477 if(
false == Check_LatLon1D_General_Product_Pattern())
1478 Check_LatLon_With_Coordinate_Attr_General_Product_Pattern();
1485 bool GMFile::Check_Dimscale_General_Product_Pattern() {
1487 BESDEBUG(
"h5",
"Coming to Check_Dimscale_General_Product_Pattern()"<<endl);
1488 bool ret_value =
false;
1489 bool has_dimlist =
false;
1490 bool has_dimscalelist =
false;
1493 for (vector<Var *>::iterator irv = this->
vars.begin();
1494 irv != this->
vars.end(); ++irv) {
1495 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1496 ira != (*irv)->attrs.end();ira++) {
1497 if (
"DIMENSION_LIST" == (*ira)->name) {
1502 if (
true == has_dimlist)
1511 for (vector<Var *>::iterator irv = this->
vars.begin();
1512 irv != this->
vars.end(); ++irv) {
1515 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
1516 ira != (*irv)->attrs.end();ira++) {
1517 if (
"CLASS" == (*ira)->name) {
1519 Retrieve_H5_Attr_Value(*ira,(*irv)->fullpath);
1521 class_value.resize((*ira)->value.size());
1522 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
1526 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
1527 has_dimscalelist =
true;
1533 if (
true == has_dimscalelist)
1538 if (
true == has_dimlist &&
true == has_dimscalelist) {
1539 this->gproduct_pattern = GENERAL_DIMSCALE;
1549 bool GMFile::Check_LatLon2D_General_Product_Pattern() {
1551 BESDEBUG(
"h5",
"Coming to Check_LatLon2D_General_Product_Pattern()"<<endl);
1552 bool ret_value =
false;
1554 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"latitude",
"longitude");
1555 if(
false == ret_value) {
1556 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"Latitude",
"Longitude");
1557 if(
false == ret_value) {
1558 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"lat",
"lon");
1559 if(
false == ret_value)
1560 ret_value = Check_LatLon2D_General_Product_Pattern_Name_Size(
"cell_lat",
"cell_lon");
1565 if(
true == ret_value)
1566 this->gproduct_pattern = GENERAL_LATLON2D;
1573 bool GMFile::Check_LatLon2D_General_Product_Pattern_Name_Size(
const string & latname,
const string & lonname) {
1575 BESDEBUG(
"h5",
"Coming to Check_LatLon2D_General_Product_Pattern_Name_Size()"<<endl);
1576 bool ret_value =
false;
1577 bool ll_flag =
false;
1579 vector<size_t>lat_size(2,0);
1580 vector<size_t>lon_size(2,0);
1582 const string designed_group1 =
"/";
1583 const string designed_group2 =
"/Geolocation/";
1585 bool lat_flag_g1 =
false;
1586 bool lon_flag_g1 =
false;
1587 bool lat_flag_g2 =
false;
1588 bool lon_flag_g2 =
false;
1594 lat_flag_g1 = is_var_under_group(latname,designed_group1,2,lat_size);
1595 lon_flag_g1 = is_var_under_group(lonname,designed_group1,2,lon_size);
1596 if(lat_flag_g1 ==
true && lon_flag_g1 ==
true) {
1599 lat_flag_g2 = is_var_under_group(latname,designed_group2,2,lat_size);
1600 if(lat_flag_g2 ==
false) {
1601 lon_flag_g2 = is_var_under_group(lonname,designed_group2,2,lon_size);
1602 if(lon_flag_g2 ==
false)
1606 else if(lat_flag_g1 ==
false && lon_flag_g1 ==
false) {
1607 lat_flag_g2 = is_var_under_group(latname,designed_group2,2,lat_size);
1608 if(lat_flag_g2 ==
true) {
1609 lon_flag_g2 = is_var_under_group(lonname,designed_group2,2,lon_size);
1610 if(lon_flag_g2 ==
true)
1618 for (vector<Var *>::iterator irv = this->
vars.begin();
1619 irv != this->
vars.end(); ++irv) {
1621 if((*irv)->rank == 2) {
1622 if((*irv)->name == latname) {
1625 string lat_path =HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1631 bool has_right_lat =
false;
1632 if(
"/" == lat_path ||
"/Geolocation/" == lat_path)
1633 if(
"/" == lat_path ||
"/Geolocation/" == lat_path) {
1635 lat_size[0] = (*irv)->getDimensions()[0]->size;
1636 lat_size[1] = (*irv)->getDimensions()[1]->size;
1640 else if((*irv)->name == lonname) {
1641 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1642 if(
"/" == lon_path ||
"/Geolocation/" == lon_path) {
1644 lon_size[0] = (*irv)->getDimensions()[0]->size;
1645 lon_size[1] = (*irv)->getDimensions()[1]->size;
1658 if(
true == ll_flag) {
1660 bool latlon_size_match =
true;
1661 for (
unsigned int size_index = 0; size_index <lat_size.size();size_index++) {
1662 if(lat_size[size_index] != lon_size[size_index]){
1663 latlon_size_match =
false;
1667 if (
true == latlon_size_match) {
1669 gp_latname = latname;
1670 gp_lonname = lonname;
1683 bool GMFile::Check_LatLon1D_General_Product_Pattern() {
1685 BESDEBUG(
"h5",
"Coming to Check_LatLon1D_General_Product_Pattern()"<<endl);
1686 bool ret_value =
false;
1688 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"latitude",
"longitude");
1689 if(
false == ret_value) {
1690 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"Latitude",
"Longitude");
1691 if(
false == ret_value) {
1692 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"lat",
"lon");
1693 if(
false == ret_value)
1694 ret_value = Check_LatLon1D_General_Product_Pattern_Name_Size(
"cell_lat",
"cell_lon");
1698 if(
true == ret_value)
1699 this->gproduct_pattern = GENERAL_LATLON1D;
1706 bool GMFile::Check_LatLon1D_General_Product_Pattern_Name_Size(
const string & latname,
const string & lonname) {
1708 BESDEBUG(
"h5",
"Coming to Check_LatLon1D_General_Product_Pattern_Name_Size()"<<endl);
1709 bool ret_value =
false;
1711 size_t lat_size = 0;
1712 size_t lon_size = 0;
1714 for (vector<Var *>::iterator irv = this->
vars.begin();
1715 irv != this->
vars.end(); ++irv) {
1717 if((*irv)->rank == 1) {
1718 if((*irv)->name == latname) {
1720 string lat_path =HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1724 if(
"/" == lat_path ||
"/Geolocation/" == lat_path) {
1726 lat_size = (*irv)->getDimensions()[0]->size;
1729 else if((*irv)->name == lonname) {
1730 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath);
1731 if(
"/" == lon_path ||
"/Geolocation/" == lon_path) {
1733 lon_size = (*irv)->getDimensions()[0]->size;
1743 bool latlon_size_match_grid =
true;
1749 if(lat_size == lon_size) {
1752 latlon_size_match_grid =
false;
1756 for (vector<Var *>::iterator irv = this->
vars.begin();
1757 irv != this->
vars.end(); ++irv) {
1758 if((*irv)->rank >=2) {
1759 short ll_size_flag = 0;
1760 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
1761 ird != (*irv)->dims.end(); ++ird) {
1762 if(lat_size == (*ird)->size) {
1764 if(2 == ll_size_flag){
1769 if(2 == ll_size_flag) {
1770 latlon_size_match_grid =
true;
1779 if (
true == latlon_size_match_grid) {
1780 gp_latname = latname;
1781 gp_lonname = lonname;
1791 bool GMFile::Check_LatLon_With_Coordinate_Attr_General_Product_Pattern() {
1793 BESDEBUG(
"h5",
"Coming to Check_LatLon_With_Coordinate_Attr_General_Product_Pattern()"<<endl);
1794 bool ret_value =
false;
1795 string co_attrname =
"coordinates";
1796 string co_attrvalue=
"";
1797 string unit_attrname =
"units";
1798 string lat_unit_attrvalue =
"degrees_north";
1799 string lon_unit_attrvalue =
"degrees_east";
1801 bool coor_has_lat_flag =
false;
1802 bool coor_has_lon_flag =
false;
1804 vector<Var*> tempvar_lat;
1805 vector<Var*> tempvar_lon;
1808 for (vector<Var *>::iterator irv = this->
vars.begin();
1809 irv != this->
vars.end(); ++irv) {
1810 if((*irv)->rank >=2) {
1811 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
1812 ira !=(*irv)->attrs.end();++ira) {
1816 if((*ira)->name == co_attrname) {
1817 Retrieve_H5_Attr_Value((*ira),(*irv)->fullpath);
1818 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
1819 vector<string> coord_values;
1821 HDF5CFUtil::Split_helper(coord_values,orig_attr_value,sep);
1823 for(vector<string>::iterator irs=coord_values.begin();irs!=coord_values.end();++irs) {
1824 string coord_value_suffix1;
1825 string coord_value_suffix2;
1826 string coord_value_suffix3;
1828 if((*irs).size() >=3) {
1831 coord_value_suffix1 = (*irs).substr((*irs).size()-3,3);
1834 if((*irs).size() >=8){
1835 coord_value_suffix2 = (*irs).substr((*irs).size()-8,8);
1836 if((*irs).size() >=9)
1837 coord_value_suffix3 = (*irs).substr((*irs).size()-9,9);
1842 if(coord_value_suffix1==
"lat" || coord_value_suffix2 ==
"latitude" || coord_value_suffix2 ==
"Latitude")
1843 coor_has_lat_flag =
true;
1844 else if(coord_value_suffix1==
"lon" || coord_value_suffix3 ==
"longitude" || coord_value_suffix3 ==
"Longitude")
1845 coor_has_lon_flag =
true;
1848 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag)
1852 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag)
1855 coor_has_lat_flag =
false;
1856 coor_has_lon_flag =
false;
1862 if(
true == coor_has_lat_flag &&
true == coor_has_lon_flag) {
1864 for (vector<Var *>::iterator irv = this->
vars.begin();
1865 irv != this->
vars.end(); ++irv) {
1866 bool var_is_lat =
false;
1867 bool var_is_lon =
false;
1869 string varname = (*irv)->name;
1873 if(varname.size() >=3) {
1874 ll_ssuffix = varname.substr(varname.size()-3,3);
1875 if(varname.size() >=8) {
1876 ll_lsuffix1 = varname.substr(varname.size()-8,8);
1877 if(varname.size() >=9)
1878 ll_lsuffix2 = varname.substr(varname.size()-9,9);
1881 if(ll_ssuffix==
"lat" || ll_lsuffix1 ==
"latitude" || ll_lsuffix1 ==
"Latitude")
1883 else if(ll_ssuffix==
"lon" || ll_lsuffix2 ==
"longitude" || ll_lsuffix2 ==
"Longitude")
1887 if(
true == var_is_lat) {
1888 if((*irv)->rank > 0) {
1889 Var * lat =
new Var(*irv);
1890 tempvar_lat.push_back(lat);
1893 else if(
true == var_is_lon) {
1894 if((*irv)->rank >0) {
1895 Var * lon =
new Var(*irv);
1896 tempvar_lon.push_back(lon);
1906 for(vector<Var*>:: iterator irlat = tempvar_lat.begin(); irlat!=tempvar_lat.end();++irlat) {
1909 if((*irlat)->rank == 1)
1910 Build_lat1D_latlon_candidate(*irlat,tempvar_lon);
1913 else if((*irlat)->rank >1)
1914 Build_latg1D_latlon_candidate(*irlat,tempvar_lon);
1918 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
1919 cerr<<
"struct lat lon names are " <<(*ivs).name1 <<
" and " << (*ivs).name2 <<endl;
1926 Build_unique_latlon_candidate();
1940 if(latloncv_candidate_pairs.size() >0) {
1941 int num_1d_rank = 0;
1942 int num_2d_rank = 0;
1943 int num_g2d_rank = 0;
1944 vector<struct Name_Size_2Pairs> temp_1d_latlon_pairs;
1945 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin();
1946 ivs!=latloncv_candidate_pairs.end();++ivs) {
1947 if(1 == (*ivs).rank) {
1949 temp_1d_latlon_pairs.push_back(*ivs);
1951 else if(2 == (*ivs).rank)
1953 else if((*ivs).rank >2)
1958 if (num_2d_rank !=0)
1960 else if(num_1d_rank!=0) {
1964 for(vector<struct Name_Size_2Pairs>::iterator ivs=temp_1d_latlon_pairs.begin();
1965 ivs!=temp_1d_latlon_pairs.end();++ivs) {
1966 if((*ivs).size1 != (*ivs).size2) {
1977 for (vector<Var *>::iterator irv = this->
vars.begin();
1978 irv != this->
vars.end(); ++irv) {
1979 if((*irv)->rank >=2) {
1980 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
1981 ira !=(*irv)->attrs.end();++ira) {
1983 if((*ira)->name == co_attrname) {
1984 Retrieve_H5_Attr_Value((*ira),(*irv)->fullpath);
1985 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
1986 vector<string> coord_values;
1988 HDF5CFUtil::Split_helper(coord_values,orig_attr_value,sep);
1989 bool has_lat_flag =
false;
1990 bool has_lon_flag =
false;
1991 for (vector<string>::iterator itcv=coord_values.begin();itcv!=coord_values.end();++itcv) {
1992 if((*ivs).name1 == (*itcv))
1993 has_lat_flag =
true;
1994 else if((*ivs).name2 == (*itcv))
1995 has_lon_flag =
true;
1998 if(
true == has_lat_flag &&
true == has_lon_flag) {
1999 short has_same_ll_size = 0;
2000 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();ird!=(*irv)->dims.end();++ird){
2001 if((*ird)->size == (*ivs).size1)
2004 if(has_same_ll_size!=2){
2011 if(
false == ret_value)
2016 if(
true == ret_value)
2023 release_standalone_var_vector(tempvar_lat);
2024 release_standalone_var_vector(tempvar_lon);
2028 if(
true == ret_value)
2029 cerr<<
"This product is the coordinate type "<<endl;
2032 if(
true == ret_value)
2033 this->gproduct_pattern = GENERAL_LATLON_COOR_ATTR;
2039 void GMFile::Build_lat1D_latlon_candidate(
Var *lat,
const vector<Var*> &lon_vec) {
2041 BESDEBUG(
"h5",
"Coming to Build_lat1D_latlon_candidate()"<<endl);
2042 set<string> lon_candidate_path;
2043 vector< pair<string,hsize_t> > lon_path_size_vec;
2046 for(vector<Var *>::const_iterator irlon = lon_vec.begin(); irlon!=lon_vec.end();++irlon) {
2048 if (lat->rank == (*irlon)->rank) {
2049 pair<string,hsize_t>lon_path_size;
2050 lon_path_size.first = (*irlon)->fullpath;
2051 lon_path_size.second = (*irlon)->getDimensions()[0]->size;
2052 lon_path_size_vec.push_back(lon_path_size);
2057 if(lon_path_size_vec.size() == 1) {
2060 latlon_pair.name1 = lat->fullpath;
2061 latlon_pair.name2 = lon_path_size_vec[0].first;
2063 latlon_pair.size2 = lon_path_size_vec[0].second;
2064 latlon_pair.rank = lat->rank;
2065 latloncv_candidate_pairs.push_back(latlon_pair);
2068 else if(lon_path_size_vec.size() >1) {
2072 string lat_path = HDF5CFUtil::obtain_string_before_lastslash(lat->fullpath);
2073 pair<string,hsize_t> lon_final_path_size;
2074 short num_lon_match = 0;
2075 for(vector <pair<string,hsize_t> >::iterator islon =lon_path_size_vec.begin();islon!=lon_path_size_vec.end();++islon) {
2077 if(HDF5CFUtil::obtain_string_before_lastslash((*islon).first)==lat_path) {
2079 if(1 == num_lon_match)
2080 lon_final_path_size = *islon;
2081 else if(num_lon_match > 1)
2085 if(num_lon_match ==1) {
2087 latlon_pair.name1 = lat->fullpath;
2088 latlon_pair.name2 = lon_final_path_size.first;
2090 latlon_pair.size2 = lon_final_path_size.second;
2091 latlon_pair.rank = lat->rank;
2092 latloncv_candidate_pairs.push_back(latlon_pair);
2099 void GMFile::Build_latg1D_latlon_candidate(
Var *lat,
const vector<Var*> & lon_vec) {
2101 BESDEBUG(
"h5",
"Coming to Build_latg1D_latlon_candidate()"<<endl);
2102 set<string> lon_candidate_path;
2105 for(vector<Var*>:: const_iterator irlon = lon_vec.begin(); irlon!=lon_vec.end();++irlon) {
2107 if (lat->rank == (*irlon)->rank) {
2110 bool same_dim =
true;
2111 for(
int dim_index = 0; dim_index <lat->rank; dim_index++) {
2113 (*irlon)->getDimensions()[dim_index]->size){
2118 if(
true == same_dim)
2119 lon_candidate_path.insert((*irlon)->fullpath);
2124 if(lon_candidate_path.size() > 1) {
2126 string lat_path = HDF5CFUtil::obtain_string_before_lastslash(lat->fullpath);
2127 vector <string> lon_final_candidate_path_vec;
2128 for(set<string>::iterator islon_path =lon_candidate_path.begin();islon_path!=lon_candidate_path.end();++islon_path) {
2131 if(HDF5CFUtil::obtain_string_before_lastslash(*islon_path)==lat_path)
2132 lon_final_candidate_path_vec.push_back(*islon_path);
2135 if(lon_final_candidate_path_vec.size() == 1) {
2139 latlon_pair.name1 = lat->fullpath;
2140 latlon_pair.name2 = lon_final_candidate_path_vec[0];
2143 latlon_pair.rank = lat->rank;
2144 latloncv_candidate_pairs.push_back(latlon_pair);
2146 else if(lon_final_candidate_path_vec.size() >1) {
2153 string lat_name = HDF5CFUtil::obtain_string_after_lastslash(lat->fullpath);
2154 string lat_name_prefix1;
2155 string lat_name_prefix2;
2158 if(lat_name.size() >3) {
2159 lat_name_prefix1 = lat_name.substr(0,lat_name.size()-3);
2160 if(lat_name.size() >8)
2161 lat_name_prefix2 = lat_name.substr(0,lat_name.size()-8);
2163 string lon_name_prefix1;
2164 string lon_name_prefix2;
2166 for(vector<string>::iterator ilon = lon_final_candidate_path_vec.begin(); ilon!=lon_final_candidate_path_vec.end();++ilon) {
2167 string lon_name = HDF5CFUtil::obtain_string_after_lastslash(*ilon);
2168 if(lon_name.size() >3) {
2169 lon_name_prefix1 = lon_name.substr(0,lon_name.size()-3);
2170 if(lon_name.size() >9)
2171 lon_name_prefix2 = lon_name.substr(0,lon_name.size()-9);
2173 if((lat_name_prefix1 !=
"" && lat_name_prefix1 == lon_name_prefix1) ||
2174 (lat_name_prefix2 !=
"" && lat_name_prefix2 == lon_name_prefix2)) {
2177 latlon_pair.name1 = lat->fullpath;
2178 latlon_pair.name2 = *ilon;
2181 latlon_pair.rank = lat->rank;
2182 latloncv_candidate_pairs.push_back(latlon_pair);
2189 else if(lon_candidate_path.size() == 1) {
2193 latlon_pair.name1 = lat->fullpath;
2194 latlon_pair.name2 = *(lon_candidate_path.begin());
2197 latlon_pair.rank = lat->rank;
2198 latloncv_candidate_pairs.push_back(latlon_pair);
2206 void GMFile::Build_unique_latlon_candidate() {
2208 BESDEBUG(
"h5",
"Coming to Build_unique_latlon_candidate()"<<endl);
2209 set<int> duplicate_index;
2210 for(
unsigned int i= 0; i<latloncv_candidate_pairs.size();i++) {
2211 for(
unsigned int j=i+1;j<latloncv_candidate_pairs.size();j++) {
2212 if(latloncv_candidate_pairs[i].name2 == latloncv_candidate_pairs[j].name2) {
2213 duplicate_index.insert(i);
2214 duplicate_index.insert(j);
2220 for(set<int>::reverse_iterator its= duplicate_index.rbegin();its!=duplicate_index.rend();++its) {
2221 latloncv_candidate_pairs[*its] = latloncv_candidate_pairs.back();
2222 latloncv_candidate_pairs.pop_back();
2229 bool GMFile::Check_LatLonName_General_Product(
int ll_rank) {
2231 if(ll_rank <1 || ll_rank >2)
2232 throw2(
"Only support rank = 1 or 2 lat/lon case for the general product. The current rank is ",ll_rank);
2233 bool ret_value =
false;
2234 size_t lat2D_dimsize0 = 0;
2235 size_t lat2D_dimsize1 = 0;
2236 size_t lon2D_dimsize0 = 0;
2237 size_t lon2D_dimsize1 = 0;
2240 vector<short>ll_flag(3,0);
2242 vector<size_t>lat_size;
2243 vector<size_t>lon_size;
2248 lat_size.assign(6,0);
2249 lon_size.assign(6,0);
2252 for (vector<Var *>::iterator irv = this->
vars.begin();
2253 irv != this->
vars.end(); ++irv) {
2255 if((*irv)->rank == ll_rank) {
2256 if((*irv)->name ==
"lat") {
2259 lat_size[0] = (*irv)->getDimensions()[0]->size;
2260 lat_size[1] = (*irv)->getDimensions()[1]->size;
2265 else if((*irv)->name ==
"lon") {
2268 lon_size[0] = (*irv)->getDimensions()[0]->size;
2269 lon_size[1] = (*irv)->getDimensions()[1]->size;
2274 else if((*irv)->name ==
"latitude"){
2277 lat_size[2] = (*irv)->getDimensions()[0]->size;
2278 lat_size[3] = (*irv)->getDimensions()[1]->size;
2282 else if((*irv)->name ==
"longitude"){
2285 lon_size[2] = (*irv)->getDimensions()[0]->size;
2286 lon_size[3] = (*irv)->getDimensions()[1]->size;
2291 else if((*irv)->name ==
"Latitude"){
2294 lat_size[4] = (*irv)->getDimensions()[0]->size;
2295 lat_size[5] = (*irv)->getDimensions()[1]->size;
2300 else if((*irv)->name ==
"Longitude"){
2303 lon_size[4] = (*irv)->getDimensions()[0]->size;
2304 lon_size[5] = (*irv)->getDimensions()[1]->size;
2310 int total_llflag = 0;
2311 for (
int i = 0; i < ll_flag.size();i++)
2316 if(1 == total_llflag) {
2317 bool latlon_size_match =
true;
2319 for (
int size_index = 0; size_index <lat_size.size();size_index++) {
2320 if(lat_size[size_index] != lon_size[size_index]){
2321 latlon_size_match =
false;
2327 if(
true == latlon_size_match) {
2329 if(2 == ll_flag[0]) {
2333 else if ( 2 == ll_flag[1]) {
2334 gp_latname =
"latitude";
2335 gp_lonname =
"longitude";
2338 else if (2 == ll_flag[2]){
2339 gp_latname =
"Latitude";
2340 gp_lonname =
"Longitude";
2350 void GMFile::Add_Dim_Name_LatLon2D_General_Product() {
2352 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_LatLon2D_General_Product()"<<endl);
2355 size_t latdimsize0 = 0;
2356 size_t latdimsize1 = 0;
2359 for (vector<Var *>::iterator irv = this->
vars.begin();
2360 irv != this->
vars.end(); ++irv) {
2362 set<hsize_t> fakedimsize;
2363 pair<set<hsize_t>::iterator,
bool> setsizeret;
2364 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2365 ird != (*irv)->dims.end(); ++ird) {
2366 Add_One_FakeDim_Name(*ird);
2367 setsizeret = fakedimsize.insert((*ird)->size);
2370 if (
false == setsizeret.second)
2371 Adjust_Duplicate_FakeDim_Name(*ird);
2376 if((*irv)->name == gp_latname) {
2377 if((*irv)->rank != 2) {
2378 throw4(
"coordinate variables ",gp_latname,
2379 " must have rank 2 for the 2-D latlon case , the current rank is ",
2382 latdimname0 = (*irv)->getDimensions()[0]->name;
2383 latdimsize0 = (*irv)->getDimensions()[0]->size;
2385 latdimname1 = (*irv)->getDimensions()[1]->name;
2386 latdimsize1 = (*irv)->getDimensions()[1]->size;
2393 for (vector<Var *>::iterator irv = this->
vars.begin();
2394 irv != this->
vars.end(); ++irv) {
2395 int lat_dim0_index = 0;
2396 int lat_dim1_index = 0;
2397 bool has_lat_dims_size =
false;
2399 for (
unsigned int dim_index = 0; dim_index <(*irv)->dims.size(); dim_index++) {
2402 if(((*irv)->dims[dim_index])->size == latdimsize0) {
2405 lat_dim0_index = dim_index;
2406 for(
unsigned int dim_index2 = dim_index+1;dim_index2 < (*irv)->dims.size();dim_index2++) {
2407 if(((*irv)->dims[dim_index2])->size == latdimsize1) {
2408 lat_dim1_index = dim_index2;
2409 has_lat_dims_size =
true;
2414 if(
true == has_lat_dims_size)
2418 if(
true == has_lat_dims_size) {
2419 ((*irv)->dims[lat_dim0_index])->name = latdimname0;
2422 ((*irv)->dims[lat_dim1_index])->name = latdimname1;
2433 set<string>tempdimnamelist;
2435 for (vector<Var *>::iterator irv = this->
vars.begin();
2436 irv != this->
vars.end(); ++irv) {
2437 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2438 ird != (*irv)->dims.end(); ++ird)
2439 tempdimnamelist.insert((*ird)->name);
2444 set<string>finaldimnamelist;
2445 string finaldimname_base =
"FakeDim";
2447 for(
unsigned int i = 0; i<tempdimnamelist.size();i++) {
2448 stringstream sfakedimindex;
2450 string finaldimname = finaldimname_base + sfakedimindex.str();
2451 finaldimnamelist.insert(finaldimname);
2456 if(finaldimnamelist != tempdimnamelist) {
2457 map<string,string> tempdimname_to_finaldimname;
2458 set<string>:: iterator tempit = tempdimnamelist.begin();
2459 set<string>:: iterator finalit = finaldimnamelist.begin();
2460 while(tempit != tempdimnamelist.end()) {
2461 tempdimname_to_finaldimname[*tempit] = *finalit;
2467 for (vector<Var *>::iterator irv = this->
vars.begin();
2468 irv != this->
vars.end(); ++irv) {
2469 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2470 ird != (*irv)->dims.end(); ++ird) {
2471 if(tempdimname_to_finaldimname.find((*ird)->name) !=tempdimname_to_finaldimname.end()){
2472 (*ird)->name = tempdimname_to_finaldimname[(*ird)->name];
2475 throw3(
"The dimension names ",(*ird)->name,
"cannot be found in the dim. name list.");
2481 dimnamelist.clear();
2482 dimnamelist = finaldimnamelist;
2485 dimname_to_dimsize.clear();
2486 for (vector<Var *>::iterator irv = this->
vars.begin();
2487 irv != this->
vars.end(); ++irv) {
2488 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2489 ird != (*irv)->dims.end(); ++ird) {
2490 if(finaldimnamelist.find((*ird)->name)!=finaldimnamelist.end()) {
2491 dimname_to_dimsize[(*ird)->name] = (*ird)->size;
2492 dimname_to_unlimited[(*ird)->name] = (*ird)->unlimited_dim;
2493 finaldimnamelist.erase((*ird)->name);
2497 if(
true == finaldimnamelist.empty())
2502 for (vector<Var *>::iterator irv = this->
vars.begin();
2503 irv != this->
vars.end(); ++irv) {
2504 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2505 ird != (*irv)->dims.end(); ++ird) {
2506 (*ird)->newname = (*ird)->name;
2514 void GMFile::Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product() {
2516 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_LatLon1D_Or_CoordAttr_General_Product()"<<endl);
2518 for (vector<Var *>::iterator irv = this->
vars.begin();
2519 irv != this->
vars.end(); ++irv) {
2521 set<hsize_t> fakedimsize;
2522 pair<set<hsize_t>::iterator,
bool> setsizeret;
2523 for (vector<Dimension *>::iterator ird= (*irv)->dims.begin();
2524 ird != (*irv)->dims.end(); ++ird) {
2525 Add_One_FakeDim_Name(*ird);
2526 setsizeret = fakedimsize.insert((*ird)->size);
2528 if (
false == setsizeret.second)
2529 Adjust_Duplicate_FakeDim_Name(*ird);
2535 void GMFile::Add_Dim_Name_Dimscale_General_Product() {
2537 BESDEBUG(
"h5",
"Coming to Add_Dim_Name_Dimscale_General_Product()"<<endl);
2539 pair<set<string>::iterator,
bool> setret;
2540 this->iscoard =
true;
2542 for (vector<Var *>::iterator irv = this->
vars.begin();
2543 irv != this->
vars.end(); ++irv) {
2546 Handle_UseDimscale_Var_Dim_Names_General_Product((*irv));
2549 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
2550 ird !=(*irv)->dims.end();++ird) {
2551 setret = dimnamelist.insert((*ird)->name);
2552 if (
true == setret.second)
2553 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
2557 if (
true == dimnamelist.empty())
2558 throw1(
"This product should have the dimension names, but no dimension names are found");
2563 void GMFile::Handle_UseDimscale_Var_Dim_Names_General_Product(
Var *var) {
2565 BESDEBUG(
"h5",
"Coming to Handle_UseDimscale_Var_Dim_Names_General_Product()"<<endl);
2567 bool has_dimlist =
false;
2568 bool has_dimclass =
false;
2570 for(vector<Attribute *>::iterator ira = var->attrs.begin();
2571 ira != var->attrs.end();ira++) {
2572 if (
"DIMENSION_LIST" == (*ira)->name) {
2576 if (
"CLASS" == (*ira)->name) {
2578 Retrieve_H5_Attr_Value(*ira,var->fullpath);
2580 class_value.resize((*ira)->value.size());
2581 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
2585 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
2586 has_dimclass =
true;
2594 if (
true == has_dimlist)
2595 Add_UseDimscale_Var_Dim_Names_General_Product(var,dimlistattr);
2598 else if(
true == has_dimclass) {
2599 if (var->dims.size() !=1)
2600 throw2(
"Currently dimension scale dataset must be 1 dimension, this is not true for the dataset ",
2605 (var->dims)[0]->name = var->fullpath;
2606 (var->dims)[0]->newname = var->fullpath;
2607 pair<set<string>::iterator,
bool> setret;
2608 setret = dimnamelist.insert((var->dims)[0]->name);
2609 if (
true == setret.second)
2610 Insert_One_NameSizeMap_Element((var->dims)[0]->name,(var->dims)[0]->size,(var->dims)[0]->unlimited_dim);
2616 set<hsize_t> fakedimsize;
2617 pair<set<hsize_t>::iterator,
bool> setsizeret;
2618 for (vector<Dimension *>::iterator ird= var->dims.begin();
2619 ird != var->dims.end(); ++ird) {
2620 Add_One_FakeDim_Name(*ird);
2621 setsizeret = fakedimsize.insert((*ird)->size);
2623 if (
false == setsizeret.second)
2624 Adjust_Duplicate_FakeDim_Name(*ird);
2631 void GMFile::Add_UseDimscale_Var_Dim_Names_General_Product(
Var *var,
Attribute*dimlistattr)
2634 BESDEBUG(
"h5",
"Coming to Add_UseDimscale_Var_Dim_Names_General_Product()"<<endl);
2635 ssize_t objnamelen = -1;
2638 vector<hvl_t> vlbuf;
2642 hid_t atype_id = -1;
2643 hid_t amemtype_id = -1;
2644 hid_t aspace_id = -1;
2645 hid_t ref_dset = -1;
2647 if(NULL == dimlistattr)
2648 throw2(
"Cannot obtain the dimension list attribute for variable ",var->name);
2650 else if (0==var->rank)
2651 throw2(
"The number of dimension should NOT be 0 for the variable ",var->name);
2656 vlbuf.resize(var->rank);
2658 dset_id = H5Dopen(this->fileid,(var->fullpath).c_str(),H5P_DEFAULT);
2660 throw2(
"Cannot open the dataset ",var->fullpath);
2662 attr_id = H5Aopen(dset_id,(dimlistattr->name).c_str(),H5P_DEFAULT);
2664 throw4(
"Cannot open the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
2666 atype_id = H5Aget_type(attr_id);
2668 throw4(
"Cannot obtain the datatype of the attribute ",dimlistattr->name,
" of HDF5 dataset ",var->fullpath);
2670 amemtype_id = H5Tget_native_type(atype_id, H5T_DIR_ASCEND);
2672 if (amemtype_id < 0)
2673 throw2(
"Cannot obtain the memory datatype for the attribute ",dimlistattr->name);
2676 if (H5Aread(attr_id,amemtype_id,&vlbuf[0]) <0)
2677 throw2(
"Cannot obtain the referenced object for the variable ",var->name);
2680 vector<char> objname;
2681 int vlbuf_index = 0;
2684 for (vector<Dimension *>::iterator ird = var->dims.begin();
2685 ird != var->dims.end(); ++ird) {
2687 if(vlbuf[vlbuf_index].p== NULL)
2688 throw4(
"The dimension doesn't exist. Var name is ",var->name,
"; the dimension index is ",vlbuf_index);
2689 rbuf =((hobj_ref_t*)vlbuf[vlbuf_index].p)[0];
2690 if ((ref_dset = H5RDEREFERENCE(attr_id, H5R_OBJECT, &rbuf)) < 0)
2691 throw2(
"Cannot dereference from the DIMENSION_LIST attribute for the variable ",var->name);
2693 if ((objnamelen= H5Iget_name(ref_dset,NULL,0))<=0)
2694 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
2695 objname.resize(objnamelen+1);
2696 if ((objnamelen= H5Iget_name(ref_dset,&objname[0],objnamelen+1))<=0)
2697 throw2(
"Cannot obtain the dataset name dereferenced from the DIMENSION_LIST attribute for the variable ",var->name);
2699 string objname_str = string(objname.begin(),objname.end());
2705 string trim_objname = objname_str.substr(0,objnamelen);
2706 (*ird)->name = string(trim_objname.begin(),trim_objname.end());
2708 pair<set<string>::iterator,
bool> setret;
2709 setret = dimnamelist.insert((*ird)->name);
2710 if (
true == setret.second)
2711 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size,(*ird)->unlimited_dim);
2712 (*ird)->newname = (*ird)->name;
2720 if(vlbuf.size()!= 0) {
2722 if ((aspace_id = H5Aget_space(attr_id)) < 0)
2723 throw2(
"Cannot get hdf5 dataspace id for the attribute ",dimlistattr->name);
2725 if (H5Dvlen_reclaim(amemtype_id,aspace_id,H5P_DEFAULT,(
void*)&vlbuf[0])<0)
2726 throw2(
"Cannot successfully clean up the variable length memory for the variable ",var->name);
2728 H5Sclose(aspace_id);
2733 H5Tclose(amemtype_id);
2743 if(amemtype_id != -1)
2744 H5Tclose(amemtype_id);
2747 H5Sclose(aspace_id);
2764 BESDEBUG(
"h5",
"GMFile:: Coming to Handle_CVar()"<<endl);
2770 if (General_Product == this->product_type ||
2771 ACOS_L2S_OR_OCO2_L1B == this->product_type) {
2772 if (GENERAL_DIMSCALE == this->gproduct_pattern)
2773 Handle_CVar_Dimscale_General_Product();
2774 else if (GENERAL_LATLON1D == this->gproduct_pattern)
2775 Handle_CVar_LatLon1D_General_Product();
2776 else if (GENERAL_LATLON2D == this->gproduct_pattern)
2777 Handle_CVar_LatLon2D_General_Product();
2781 else if (Mea_SeaWiFS_L2 == this->product_type ||
2782 Mea_SeaWiFS_L3 == this->product_type)
2783 Handle_CVar_Mea_SeaWiFS();
2784 else if (Aqu_L3 == this->product_type)
2785 Handle_CVar_Aqu_L3();
2786 else if (OBPG_L3 == this->product_type)
2787 Handle_CVar_OBPG_L3();
2788 else if (OSMAPL2S == this->product_type)
2789 Handle_CVar_OSMAPL2S();
2790 else if (Mea_Ozone == this->product_type)
2791 Handle_CVar_Mea_Ozone();
2792 else if (GPMS_L3 == this->product_type || GPMM_L3 == this->product_type)
2793 Handle_CVar_GPM_L3();
2794 else if (GPM_L1 == this->product_type)
2795 Handle_CVar_GPM_L1();
2799 void GMFile::Handle_CVar_GPM_L1() {
2801 BESDEBUG(
"h5",
"Coming to Handle_CVar_GPM_L1()"<<endl);
2804 for (vector<Var *>::iterator irv = this->
vars.begin();
2805 irv != this->
vars.end(); ++irv) {
2806 if((*irv)->name==
"AlgorithmRuntimeInfo") {
2808 this->
vars.erase(irv);
2821 set<string> ll_dim_set;
2822 for (vector<Var *>::iterator irv = this->
vars.begin();
2823 irv != this->
vars.end(); ) {
2824 if((*irv)->rank == 2 && (*irv)->name ==
"Latitude") {
2826 size_t lat_pos = (*irv)->fullpath.rfind(
"Latitude");
2827 string lat_path = (*irv)->fullpath.substr(0,lat_pos);
2828 GMcvar->cfdimname = lat_path + ((*irv)->dims)[0]->name;
2829 ll_dim_set.insert(((*irv)->dims)[0]->name);
2830 GMcvar->cvartype = CV_EXIST;
2831 GMcvar->product_type = product_type;
2832 this->cvars.push_back(GMcvar);
2834 irv = this->
vars.erase(irv);
2837 if((*irv)->rank == 2 && (*irv)->name ==
"Longitude") {
2839 size_t lon_pos = (*irv)->fullpath.rfind(
"Longitude");
2840 string lon_path = (*irv)->fullpath.substr(0,lon_pos);
2841 GMcvar->cfdimname = lon_path + ((*irv)->dims)[1]->name;
2842 ll_dim_set.insert(((*irv)->dims)[1]->name);
2843 GMcvar->cvartype = CV_EXIST;
2844 GMcvar->product_type = product_type;
2845 this->cvars.push_back(GMcvar);
2847 irv = this->
vars.erase(irv);
2856 set<string> cvdimset;
2857 pair<set<string>::iterator,
bool> setret;
2858 for (vector<Var *>::iterator irv = this->
vars.begin();
2859 irv != this->
vars.end(); ++irv) {
2860 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();
2861 ird != (*irv)->dims.end(); ++ird) {
2862 setret = cvdimset.insert((*ird)->name);
2863 cerr<<
"var name is "<<(*irv)->fullpath <<endl;
2864 if (
true == setret.second) {
2865 cerr<<
"dim name is "<<(*ird)->name <<endl;
2866 Insert_One_NameSizeMap_Element((*ird)->name,(*ird)->size);
2875 for (map<string,hsize_t>::const_iterator itd = dimname_to_dimsize.begin();
2876 itd!=dimname_to_dimsize.end();++itd) {
2879 if((ll_dim_set.find(itd->first)) == ll_dim_set.end()) {
2881 Create_Missing_CV(GMcvar,itd->first);
2882 this->cvars.push_back(GMcvar);
2889 void GMFile::Handle_CVar_GPM_L3() {
2891 BESDEBUG(
"h5",
"Coming to Handle_CVar_GPM_L3()"<<endl);
2896 for (map<string,hsize_t>::const_iterator itd = dimname_to_dimsize.begin();
2897 itd!=dimname_to_dimsize.end();++itd) {
2900 if(
"nlon" == itd->first ||
"nlat" == itd->first
2901 ||
"lnH" == itd->first ||
"ltH" == itd->first
2902 ||
"lnL" == itd->first ||
"ltL" == itd->first) {
2903 GMcvar->name = itd->first;
2904 GMcvar->newname = GMcvar->name;
2905 GMcvar->fullpath = GMcvar->name;
2907 GMcvar->dtype = H5FLOAT32;
2909 gmcvar_dim->name = GMcvar->name;
2910 gmcvar_dim->newname = gmcvar_dim->name;
2911 GMcvar->dims.push_back(gmcvar_dim);
2912 GMcvar->cfdimname = gmcvar_dim->name;
2913 if (
"nlat" ==GMcvar->name ||
"ltH" == GMcvar->name
2914 ||
"ltL" == GMcvar->name)
2915 GMcvar->cvartype = CV_LAT_MISS;
2916 else if (
"nlon" == GMcvar->name ||
"lnH" == GMcvar->name
2917 ||
"lnL" == GMcvar->name)
2918 GMcvar->cvartype = CV_LON_MISS;
2919 GMcvar->product_type = product_type;
2921 else if ((
"nlayer" == itd->first && (28 == itd->second || 19 == itd->second)) ||
2922 (
"hgt" == itd->first && 5 == itd->second) ||
2923 (
"nalt" == itd->first && 5 == itd->second)){
2924 GMcvar->name = itd->first;
2925 GMcvar->newname = GMcvar->name;
2926 GMcvar->fullpath = GMcvar->name;
2928 GMcvar->dtype = H5FLOAT32;
2930 gmcvar_dim->name = GMcvar->name;
2931 gmcvar_dim->newname = gmcvar_dim->name;
2932 GMcvar->dims.push_back(gmcvar_dim);
2933 GMcvar->cfdimname = gmcvar_dim->name;
2934 GMcvar->cvartype = CV_SPECIAL;
2935 GMcvar->product_type = product_type;
2938 Create_Missing_CV(GMcvar,itd->first);
2939 this->cvars.push_back(GMcvar);
2944 void GMFile::Handle_CVar_Mea_SeaWiFS() {
2946 BESDEBUG(
"h5",
"Coming to Handle_CVar_Mea_SeaWiFS()"<<endl);
2947 pair<set<string>::iterator,
bool> setret;
2948 set<string>tempdimnamelist = dimnamelist;
2950 for (set<string>::iterator irs = dimnamelist.begin();
2951 irs != dimnamelist.end();++irs) {
2952 for (vector<Var *>::iterator irv = this->
vars.begin();
2953 irv != this->
vars.end(); ) {
2954 if ((*irs)== (*irv)->fullpath) {
2956 if (!iscoard && ((
"/natrack" == (*irs))
2957 ||
"/nxtrack" == (*irs))) {
2962 if((*irv)->dims.size()!=1)
2963 throw3(
"Coard coordinate variable ",(*irv)->name,
"is not 1D");
2966 tempdimnamelist.erase(*irs);
2968 GMcvar->cfdimname = *irs;
2969 GMcvar->cvartype = CV_EXIST;
2970 GMcvar->product_type = product_type;
2971 this->cvars.push_back(GMcvar);
2973 irv = this->
vars.erase(irv);
2976 else if(
false == iscoard) {
2979 if ((((*irs) ==
"/natrack") && ((*irv)->fullpath ==
"/latitude"))
2980 ||(((*irs) ==
"/nxtrack") && ((*irv)->fullpath ==
"/longitude"))) {
2981 tempdimnamelist.erase(*irs);
2983 GMcvar->cfdimname = *irs;
2984 GMcvar->cvartype = CV_EXIST;
2985 GMcvar->product_type = product_type;
2986 this->cvars.push_back(GMcvar);
2988 irv = this->
vars.erase(irv);
3004 for (set<string>::iterator irs = tempdimnamelist.begin();
3005 irs != tempdimnamelist.end();++irs) {
3007 Create_Missing_CV(GMcvar,*irs);
3008 this->cvars.push_back(GMcvar);
3013 void GMFile::Handle_CVar_OSMAPL2S() {
3015 BESDEBUG(
"h5",
"Coming to Handle_CVar_OSMAPL2S()"<<endl);
3016 pair<set<string>::iterator,
bool> setret;
3017 set<string>tempdimnamelist = dimnamelist;
3019 string key0 =
"_lat";
3020 string key1 =
"_lon";
3021 string osmapl2sdim0 =
"YDim";
3022 string osmapl2sdim1 =
"XDim";
3024 bool foundkey0 =
false;
3025 bool foundkey1 =
false;
3029 for (vector<Var *>::iterator irv = this->
vars.begin();
3030 irv != this->
vars.end(); ) {
3032 tempvarname = (*irv)->name;
3034 if ((tempvarname.size() > key0.size())&&
3035 (key0 == tempvarname.substr(tempvarname.size()-key0.size(),key0.size()))){
3039 if (dimnamelist.find(osmapl2sdim0)== dimnamelist.end())
3040 throw5(
"variable ",tempvarname,
" must have dimension ",osmapl2sdim0,
" , but not found ");
3042 tempdimnamelist.erase(osmapl2sdim0);
3044 GMcvar->newname = GMcvar->name;
3045 GMcvar->cfdimname = osmapl2sdim0;
3046 GMcvar->cvartype = CV_EXIST;
3047 GMcvar->product_type = product_type;
3048 this->cvars.push_back(GMcvar);
3050 irv = this->
vars.erase(irv);
3053 else if ((tempvarname.size() > key1.size())&&
3054 (key1 == tempvarname.substr(tempvarname.size()-key1.size(),key1.size()))){
3058 if (dimnamelist.find(osmapl2sdim1)== dimnamelist.end())
3059 throw5(
"variable ",tempvarname,
" must have dimension ",osmapl2sdim1,
" , but not found ");
3061 tempdimnamelist.erase(osmapl2sdim1);
3064 GMcvar->newname = GMcvar->name;
3065 GMcvar->cfdimname = osmapl2sdim1;
3066 GMcvar->cvartype = CV_EXIST;
3067 GMcvar->product_type = product_type;
3068 this->cvars.push_back(GMcvar);
3070 irv = this->
vars.erase(irv);
3075 if (
true == foundkey0 &&
true == foundkey1)
3079 for (set<string>::iterator irs = tempdimnamelist.begin();
3080 irs != tempdimnamelist.end();++irs) {
3083 Create_Missing_CV(GMcvar,*irs);
3084 this->cvars.push_back(GMcvar);
3090 void GMFile::Handle_CVar_Aqu_L3() {
3092 BESDEBUG(
"h5",
"Coming to Handle_CVar_Aqu_L3()"<<endl);
3094 for (vector<Var *>::iterator irv = this->
vars.begin();
3095 irv != this->
vars.end(); ++irv) {
3097 if (
"l3m_data" == (*irv)->name) {
3098 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
3099 ird != (*irv)->dims.end(); ++ird) {
3101 GMcvar->name = (*ird)->name;
3102 GMcvar->newname = GMcvar->name;
3103 GMcvar->fullpath = GMcvar->name;
3105 GMcvar->dtype = H5FLOAT32;
3107 gmcvar_dim->name = GMcvar->name;
3108 gmcvar_dim->newname = gmcvar_dim->name;
3109 GMcvar->dims.push_back(gmcvar_dim);
3110 GMcvar->cfdimname = gmcvar_dim->name;
3111 if (
"lat" ==GMcvar->name ) GMcvar->cvartype = CV_LAT_MISS;
3112 if (
"lon" == GMcvar->name ) GMcvar->cvartype = CV_LON_MISS;
3113 GMcvar->product_type = product_type;
3114 this->cvars.push_back(GMcvar);
3122 void GMFile::Handle_CVar_Mea_Ozone() {
3124 BESDEBUG(
"h5",
"Coming to Handle_CVar_Mea_Ozone()"<<endl);
3125 pair<set<string>::iterator,
bool> setret;
3126 set<string>tempdimnamelist = dimnamelist;
3128 if(
false == iscoard)
3129 throw1(
"Measure Ozone level 3 zonal average product must follow COARDS conventions");
3131 for (set<string>::iterator irs = dimnamelist.begin();
3132 irs != dimnamelist.end();++irs) {
3133 for (vector<Var *>::iterator irv = this->
vars.begin();
3134 irv != this->
vars.end(); ) {
3135 if ((*irs)== (*irv)->fullpath) {
3137 if((*irv)->dims.size()!=1)
3138 throw3(
"Coard coordinate variable",(*irv)->name,
"is not 1D");
3141 tempdimnamelist.erase(*irs);
3143 GMcvar->cfdimname = *irs;
3144 GMcvar->cvartype = CV_EXIST;
3145 GMcvar->product_type = product_type;
3146 this->cvars.push_back(GMcvar);
3148 irv = this->
vars.erase(irv);
3156 for (set<string>::iterator irs = tempdimnamelist.begin();
3157 irs != tempdimnamelist.end();irs++) {
3160 Create_Missing_CV(GMcvar,*irs);
3161 this->cvars.push_back(GMcvar);
3166 void GMFile::Handle_CVar_Dimscale_General_Product() {
3168 BESDEBUG(
"h5",
"Coming to Handle_CVar_Dimscale_General_Product"<<endl);
3169 pair<set<string>::iterator,
bool> setret;
3170 set<string>tempdimnamelist = dimnamelist;
3172 for (set<string>::iterator irs = dimnamelist.begin();
3173 irs != dimnamelist.end();++irs) {
3174 for (vector<Var *>::iterator irv = this->
vars.begin();
3175 irv != this->
vars.end(); ) {
3178 if ((*irs)== (*irv)->fullpath) {
3180 if((*irv)->dims.size()!=1)
3181 throw3(
"COARDS coordinate variable",(*irv)->name,
"is not 1D");
3184 tempdimnamelist.erase(*irs);
3186 GMcvar->cfdimname = *irs;
3189 bool is_netcdf_dimension = Is_netCDF_Dimension(*irv);
3193 if (
true == is_netcdf_dimension)
3194 GMcvar->cvartype = CV_FILLINDEX;
3196 GMcvar->cvartype = CV_EXIST;
3197 GMcvar->product_type = product_type;
3198 this->cvars.push_back(GMcvar);
3200 irv = this->
vars.erase(irv);
3209 Update_M2DLatLon_Dimscale_CVs();
3212 for (set<string>::iterator irs = tempdimnamelist.begin();
3213 irs != tempdimnamelist.end();irs++) {
3215 Create_Missing_CV(GMcvar,*irs);
3216 this->cvars.push_back(GMcvar);
3222 for (set<string>::iterator irs = dimnamelist.begin();
3223 irs != dimnamelist.end();irs++) {
3224 cerr<<
"dimension name is "<<(*irs)<<endl;
3233 void GMFile::Update_M2DLatLon_Dimscale_CVs() {
3235 BESDEBUG(
"h5",
"Coming to Update_M2DLatLon_Dimscale_CVs()"<<endl);
3237 if(
false == Check_1DGeolocation_Dimscale()) {
3240 vector<GMCVar*> tempcvar_1dlat;
3241 vector<GMCVar*> tempcvar_1dlon;
3244 Obtain_1DLatLon_CVs(tempcvar_1dlat,tempcvar_1dlon);
3247 vector<Var*> tempcvar_2dlat;
3248 vector<Var*> tempcvar_2dlon;
3254 map<string,int> latlon2d_path_to_index;
3257 Obtain_2DLatLon_Vars(tempcvar_2dlat,tempcvar_2dlon,latlon2d_path_to_index);
3260 for(vector<GMCVar *>::iterator irv = tempcvar_1dlat.begin();irv != tempcvar_1dlat.end();++irv)
3261 cerr<<
"1-D lat variable full path is "<<(*irv)->fullpath <<endl;
3262 for(vector<GMCVar *>::iterator irv = tempcvar_1dlon.begin();irv != tempcvar_1dlon.end();++irv)
3263 cerr<<
"1-D lon variable full path is "<<(*irv)->fullpath <<endl;
3265 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3266 cerr<<
"2-D lat variable full path is "<<(*irv)->fullpath <<endl;
3267 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3268 cerr<<
"2-D lon variable full path is "<<(*irv)->fullpath <<endl;
3272 Obtain_2DLLVars_With_Dims_not_1DLLCVars(tempcvar_2dlat,tempcvar_2dlon,tempcvar_1dlat,tempcvar_1dlon,latlon2d_path_to_index);
3275 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3276 cerr<<
"2-D Left lat variable full path is "<<(*irv)->fullpath <<endl;
3277 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3278 cerr<<
"2-D Left lon variable full path is "<<(*irv)->fullpath <<endl;
3283 Obtain_2DLLCVar_Candidate(tempcvar_2dlat,tempcvar_2dlon,latlon2d_path_to_index);
3286 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv)
3287 cerr<<
"Final candidate 2-D Left lat variable full path is "<<(*irv)->fullpath <<endl;
3288 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv)
3289 cerr<<
"Final candidate 2-D Left lon variable full path is "<<(*irv)->fullpath <<endl;
3294 vector<int> var2d_index;
3295 for (map<string,int>::const_iterator it= latlon2d_path_to_index.begin();it!=latlon2d_path_to_index.end();++it)
3296 var2d_index.push_back(it->second);
3298 Remove_2DLLCVar_Final_Candidate_from_Vars(var2d_index);
3301 if(tempcvar_2dlat.size()>0)
3306 set<string>dim_names_2d_cvs;
3308 for(vector<Var *>::iterator irv = tempcvar_2dlat.begin();irv != tempcvar_2dlat.end();++irv){
3312 dim_names_2d_cvs.insert(lat->cfdimname);
3313 lat->cvartype = CV_EXIST;
3314 lat->product_type = product_type;
3315 this->cvars.push_back(lat);
3317 for(vector<Var *>::iterator irv = tempcvar_2dlon.begin();irv != tempcvar_2dlon.end();++irv){
3321 dim_names_2d_cvs.insert(lon->cfdimname);
3322 lon->cvartype = CV_EXIST;
3323 lon->product_type = product_type;
3324 this->cvars.push_back(lon);
3330 for(vector<GMCVar*>::iterator ircv= this->cvars.begin();ircv !=this->cvars.end();) {
3331 if(1 == (*ircv)->rank) {
3332 if(dim_names_2d_cvs.find((*ircv)->cfdimname)!=dim_names_2d_cvs.end()) {
3333 if(CV_FILLINDEX == (*ircv)->cvartype) {
3335 ircv = this->cvars.erase(ircv);
3337 else if(CV_EXIST == (*ircv)->cvartype) {
3340 Var *var =
new Var(*ircv);
3341 this->
vars.push_back(var);
3345 ircv = this->cvars.erase(ircv);
3349 if(CV_LAT_MISS == (*ircv)->cvartype)
3350 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_LAT_MISS");
3351 else if(CV_LON_MISS == (*ircv)->cvartype)
3352 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_LON_MISS");
3353 else if(CV_NONLATLON_MISS == (*ircv)->cvartype)
3354 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_NONLATLON_MISS");
3355 else if(CV_MODIFY == (*ircv)->cvartype)
3356 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_MODIFY");
3357 else if(CV_SPECIAL == (*ircv)->cvartype)
3358 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_SPECIAL");
3360 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",(*ircv)->cfdimname,
"is a coordinate variable of type CV_UNSUPPORTED");
3377 for(set<string>::iterator irs = grp_cv_paths.begin();irs != grp_cv_paths.end();++irs) {
3378 cerr<<
"group path is "<< (*irs)<<endl;
3385 cerr<<
"File name is "<< this->path <<endl;
3386 cerr<<
"CV names are the following "<<endl;
3387 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ++i)
3388 cerr<<(*i)->fullpath <<endl;
3393 release_standalone_GMCVar_vector(tempcvar_1dlat);
3394 release_standalone_GMCVar_vector(tempcvar_1dlon);
3395 release_standalone_var_vector(tempcvar_2dlat);
3396 release_standalone_var_vector(tempcvar_2dlon);
3403 bool GMFile::Check_1DGeolocation_Dimscale() {
3405 BESDEBUG(
"h5",
"Coming to Check_1DGeolocation_Dimscale()"<<endl);
3406 bool has_only_1d_geolocation_cv =
false;
3407 bool has_1d_lat_cv_flag =
false;
3408 bool has_1d_lon_cv_flag =
false;
3411 hsize_t lat_size = 0;
3414 hsize_t lon_size = 0;
3417 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
3418 ircv != this->cvars.end(); ++ircv) {
3420 if((*ircv)->cvartype == CV_EXIST) {
3421 string attr_name =
"units";
3422 string lat_unit_value =
"degrees_north";
3423 string lon_unit_value =
"degrees_east";
3425 for(vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
3426 ira != (*ircv)->attrs.end();ira++) {
3428 if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) {
3429 lat_size = (*ircv)->getDimensions()[0]->size;
3430 lat_dimname = (*ircv)->getDimensions()[0]->name;
3431 has_1d_lat_cv_flag =
true;
3434 else if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value)){
3435 lon_size = (*ircv)->getDimensions()[0]->size;
3436 lon_dimname = (*ircv)->getDimensions()[0]->name;
3437 has_1d_lon_cv_flag =
true;
3446 if(
true == has_1d_lat_cv_flag ) {
3448 if(
true == has_1d_lon_cv_flag) {
3451 if(0 == this->
groups.size()) {
3455 if(lat_size == lon_size) {
3456 bool var_has_latdim =
false;
3457 bool var_has_londim =
false;
3458 for (vector<Var *>::iterator irv = this->
vars.begin();
3459 irv != this->
vars.end(); ++irv) {
3460 if((*irv)->rank >= 2) {
3461 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
3462 ird !=(*irv)->dims.end();++ird) {
3463 if((*ird)->name == lat_dimname)
3464 var_has_latdim =
true;
3465 else if((*ird)->name == lon_dimname)
3466 var_has_londim =
true;
3468 if(
true == var_has_latdim &&
true == var_has_londim) {
3469 has_only_1d_geolocation_cv =
true;
3473 var_has_latdim =
false;
3474 var_has_londim =
false;
3480 has_only_1d_geolocation_cv =
true;
3484 bool has_2d_latname_flag =
false;
3485 bool has_2d_lonname_flag =
false;
3486 for (vector<Var *>::iterator irv = this->
vars.begin();
3487 irv != this->
vars.end(); ++irv) {
3488 if((*irv)->rank == 2) {
3491 if(
true == Is_geolatlon((*irv)->name,
true))
3492 has_2d_latname_flag =
true;
3495 else if(
true == Is_geolatlon((*irv)->name,
false))
3496 has_2d_lonname_flag =
true;
3498 if((
true == has_2d_latname_flag) && (
true == has_2d_lonname_flag))
3503 if(has_2d_latname_flag !=
true || has_2d_lonname_flag !=
true) {
3506 has_2d_latname_flag =
false;
3507 has_2d_lonname_flag =
false;
3509 for (vector<Var *>::iterator irv = this->
vars.begin();
3510 irv != this->
vars.end(); ++irv) {
3511 if((*irv)->rank == 2) {
3512 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
3513 ira != (*irv)->attrs.end(); ++ira) {
3515 if (
false == has_2d_latname_flag) {
3518 has_2d_latname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
true);
3519 if(
true == has_2d_latname_flag)
3521 else if(
false == has_2d_lonname_flag) {
3524 has_2d_lonname_flag = has_latlon_cf_units((*ira),(*irv)->fullpath,
false);
3525 if(
true == has_2d_lonname_flag)
3529 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 if(
true == has_2d_latname_flag &&
true == has_2d_lonname_flag)
3545 if(has_2d_latname_flag !=
true || has_2d_lonname_flag !=
true)
3546 has_only_1d_geolocation_cv =
true;
3551 has_only_1d_geolocation_cv =
true;
3557 if(has_only_1d_geolocation_cv ==
true)
3558 cerr <<
"has only 1D lat/lon CVs. "<<endl;
3560 cerr<<
"Possibly has 2D lat/lon CVs. "<<endl;
3563 return has_only_1d_geolocation_cv;
3569 void GMFile::Obtain_1DLatLon_CVs(vector<GMCVar*> &cvar_1dlat,vector<GMCVar*> &cvar_1dlon) {
3571 BESDEBUG(
"h5",
"Coming to Obtain_1DLatLon_CVs()"<<endl);
3572 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
3573 ircv != this->cvars.end(); ++ircv) {
3575 if((*ircv)->cvartype == CV_EXIST) {
3577 string attr_name =
"units";
3578 string lat_unit_value =
"degrees_north";
3579 string lon_unit_value =
"degrees_east";
3581 for(vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
3582 ira != (*ircv)->attrs.end();ira++) {
3585 if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) {
3588 lat->cvartype = (*ircv)->cvartype;
3589 lat->product_type = (*ircv)->product_type;
3590 cvar_1dlat.push_back(lat);
3593 else if(
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value)){
3596 lon->cvartype = (*ircv)->cvartype;
3597 lon->product_type = (*ircv)->product_type;
3598 cvar_1dlon.push_back(lon);
3609 void GMFile::Obtain_2DLatLon_Vars(vector<Var*> &var_2dlat,vector<Var*> &var_2dlon,map<string,int> & latlon2d_path_to_index) {
3611 BESDEBUG(
"h5",
"Coming to Obtain_2DLatLon_Vars()"<<endl);
3612 for (vector<Var *>::iterator irv = this->
vars.begin();
3613 irv != this->
vars.end(); ++irv) {
3614 if((*irv)->rank == 2) {
3617 if(
true == Is_geolatlon((*irv)->name,
true)) {
3618 Var *lat =
new Var(*irv);
3619 var_2dlat.push_back(lat);
3620 latlon2d_path_to_index[(*irv)->fullpath]= distance(this->
vars.begin(),irv);
3625 bool has_2dlat =
false;
3626 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
3627 ira != (*irv)->attrs.end(); ++ira) {
3630 if(
true == has_latlon_cf_units((*ira),(*irv)->fullpath,
true)) {
3631 Var *lat =
new Var(*irv);
3632 var_2dlat.push_back(lat);
3633 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3639 if(
true == has_2dlat)
3644 if(
true == Is_geolatlon((*irv)->name,
false)) {
3645 Var *lon =
new Var(*irv);
3646 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3647 var_2dlon.push_back(lon);
3650 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
3651 ira != (*irv)->attrs.end(); ++ira) {
3654 if(
true == has_latlon_cf_units((*ira),(*irv)->fullpath,
false)) {
3655 Var *lon =
new Var(*irv);
3656 latlon2d_path_to_index[(*irv)->fullpath] = distance(this->
vars.begin(),irv);
3657 var_2dlon.push_back(lon);
3668 void GMFile::Obtain_2DLLVars_With_Dims_not_1DLLCVars(vector<Var*> &var_2dlat,
3669 vector<Var*> &var_2dlon,
3670 vector<GMCVar*> &cvar_1dlat,
3671 vector<GMCVar*> &cvar_1dlon,
3672 map<string,int> &latlon2d_path_to_index) {
3674 BESDEBUG(
"h5",
"Coming to Obtain_2DLLVars_With_Dims_not_1DLLCVars()"<<endl);
3676 for(vector<Var *>::iterator irv = var_2dlat.begin();irv != var_2dlat.end();) {
3677 bool remove_2dlat =
false;
3678 for(vector<GMCVar *>::iterator ircv = cvar_1dlat.begin();ircv != cvar_1dlat.end();++ircv) {
3679 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
3680 ird!=(*irv)->dims.end(); ++ird) {
3681 if((*ird)->name == (*ircv)->getDimensions()[0]->name &&
3682 (*ird)->size == (*ircv)->getDimensions()[0]->size) {
3683 latlon2d_path_to_index.erase((*irv)->fullpath);
3685 irv = var_2dlat.erase(irv);
3686 remove_2dlat =
true;
3690 if(
true == remove_2dlat)
3694 if(
false == remove_2dlat)
3699 for(vector<Var *>::iterator irv = var_2dlon.begin();irv != var_2dlon.end();) {
3700 bool remove_2dlon =
false;
3701 for(vector<GMCVar *>::iterator ircv = cvar_1dlon.begin();ircv != cvar_1dlon.end();++ircv) {
3702 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
3703 ird!=(*irv)->dims.end(); ++ird) {
3704 if((*ird)->name == (*ircv)->getDimensions()[0]->name &&
3705 (*ird)->size == (*ircv)->getDimensions()[0]->size) {
3706 latlon2d_path_to_index.erase((*irv)->fullpath);
3708 irv = var_2dlon.erase(irv);
3709 remove_2dlon =
true;
3713 if(
true == remove_2dlon)
3717 if(
false == remove_2dlon)
3724 void GMFile::Obtain_2DLLCVar_Candidate(vector<Var*> &var_2dlat,
3725 vector<Var*> &var_2dlon,
3726 map<string,int>& latlon2d_path_to_index) {
3727 BESDEBUG(
"h5",
"Coming to Obtain_2DLLCVar_Candidate()"<<endl);
3730 vector<string> lon2d_group_paths;
3732 for(vector<Var *>::iterator irv_2dlat = var_2dlat.begin();irv_2dlat !=var_2dlat.end();) {
3733 for(vector<Var *>::iterator irv_2dlon = var_2dlon.begin();irv_2dlon != var_2dlon.end();++irv_2dlon) {
3734 if(((*irv_2dlat)->getDimensions()[0]->name == (*irv_2dlon)->getDimensions()[0]->name) &&
3735 ((*irv_2dlat)->getDimensions()[0]->size == (*irv_2dlon)->getDimensions()[0]->size) &&
3736 ((*irv_2dlat)->getDimensions()[1]->name == (*irv_2dlon)->getDimensions()[1]->name) &&
3737 ((*irv_2dlat)->getDimensions()[1]->size == (*irv_2dlon)->getDimensions()[1]->size))
3738 lon2d_group_paths.push_back(HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlon)->fullpath));
3742 if(0 == lon2d_group_paths.size()) {
3743 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3745 irv_2dlat = var_2dlat.erase(irv_2dlat);
3749 string lat2d_group_path = HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlat)->fullpath);
3752 short lon2d_has_lat2d_group_path_flag = 0;
3753 for(vector<string>::iterator ivs = lon2d_group_paths.begin();ivs!=lon2d_group_paths.end();++ivs) {
3754 if((*ivs)==lat2d_group_path)
3755 lon2d_has_lat2d_group_path_flag++;
3759 if(0 == lon2d_has_lat2d_group_path_flag) {
3760 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3762 irv_2dlat = var_2dlat.erase(irv_2dlat);
3765 else if (1== lon2d_has_lat2d_group_path_flag) {
3772 grp_cv_paths.insert(lat2d_group_path);
3773 latlon2d_path_to_index.erase((*irv_2dlat)->fullpath);
3775 irv_2dlat = var_2dlat.erase(irv_2dlat);
3780 lon2d_group_paths.clear();
3784 for(vector<Var *>::iterator irv_2dlat = var_2dlat.begin();irv_2dlat !=var_2dlat.end();++irv_2dlat)
3785 cerr<<
"2 left 2-D lat variable full path is: "<<(*irv_2dlat)->fullpath <<endl;
3791 vector<string> lat2d_group_paths;
3794 for(vector<Var *>::iterator irv_2dlon = var_2dlon.begin();irv_2dlon !=var_2dlon.end();) {
3795 for(vector<Var *>::iterator irv_2dlat = var_2dlat.begin();irv_2dlat != var_2dlat.end();++irv_2dlat) {
3796 if(((*irv_2dlat)->getDimensions()[0]->name == (*irv_2dlon)->getDimensions()[0]->name) &&
3797 ((*irv_2dlat)->getDimensions()[0]->size == (*irv_2dlon)->getDimensions()[0]->size) &&
3798 ((*irv_2dlat)->getDimensions()[1]->name == (*irv_2dlon)->getDimensions()[1]->name) &&
3799 ((*irv_2dlat)->getDimensions()[1]->size == (*irv_2dlon)->getDimensions()[1]->size))
3800 lat2d_group_paths.push_back(HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlat)->fullpath));
3804 if(0 == lat2d_group_paths.size()) {
3805 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3807 irv_2dlon = var_2dlon.erase(irv_2dlon);
3810 string lon2d_group_path = HDF5CFUtil::obtain_string_before_lastslash((*irv_2dlon)->fullpath);
3813 short lat2d_has_lon2d_group_path_flag = 0;
3814 for(vector<string>::iterator ivs = lat2d_group_paths.begin();ivs!=lat2d_group_paths.end();++ivs) {
3815 if((*ivs)==lon2d_group_path)
3816 lat2d_has_lon2d_group_path_flag++;
3820 if(0 == lat2d_has_lon2d_group_path_flag) {
3821 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3823 irv_2dlon = var_2dlon.erase(irv_2dlon);
3826 else if (1== lat2d_has_lon2d_group_path_flag) {
3833 grp_cv_paths.insert(lon2d_group_path);
3834 latlon2d_path_to_index.erase((*irv_2dlon)->fullpath);
3836 irv_2dlon = var_2dlon.erase(irv_2dlon);
3840 lat2d_group_paths.clear();
3843 for(vector<Var*>::iterator itv = var_2dlat.begin(); itv!= var_2dlat.end();++itv) {
3844 cerr<<
"Before unique, 2-D CV latitude name is "<<(*itv)->fullpath <<endl;
3846 for(vector<Var*>::iterator itv = var_2dlon.begin(); itv!= var_2dlon.end();++itv) {
3847 cerr<<
"Before unique, 2-D CV longitude name is "<<(*itv)->fullpath <<endl;
3852 Obtain_unique_2dCV(var_2dlat,latlon2d_path_to_index);
3853 Obtain_unique_2dCV(var_2dlon,latlon2d_path_to_index);
3855 for(vector<Var*>::iterator itv = var_2dlat.begin(); itv!= var_2dlat.end();++itv) {
3856 cerr<<
"2-D CV latitude name is "<<(*itv)->fullpath <<endl;
3858 for(vector<Var*>::iterator itv = var_2dlon.begin(); itv!= var_2dlon.end();++itv) {
3859 cerr<<
"2-D CV longitude name is "<<(*itv)->fullpath <<endl;
3864 if(var_2dlat.size() != var_2dlon.size()) {
3865 throw1(
"Error in generating 2-D lat/lon CVs. The size of 2d-lat should be the same as that of 2d-lon.");
3871 void GMFile::Obtain_unique_2dCV(vector<Var*> &var_ll,map<string,int>&latlon2d_path_to_index){
3873 BESDEBUG(
"h5",
"Coming to Obtain_unique_2dCV()"<<endl);
3874 vector<bool> var_share_dims(var_ll.size(),
false);
3876 for(
unsigned int i = 0; i <var_ll.size();i++) {
3879 string var_ll_i_path = HDF5CFUtil::obtain_string_before_lastslash(var_ll[i]->fullpath);
3882 for(
unsigned int j = i+1; j<var_ll.size();j++) {
3883 if((var_ll[i]->getDimensions()[0]->name == var_ll[j]->getDimensions()[0]->name)
3884 ||(var_ll[i]->getDimensions()[0]->name == var_ll[j]->getDimensions()[1]->name)
3885 ||(var_ll[i]->getDimensions()[1]->name == var_ll[j]->getDimensions()[0]->name)
3886 ||(var_ll[i]->getDimensions()[1]->name == var_ll[j]->getDimensions()[1]->name)){
3887 string var_ll_j_path = HDF5CFUtil::obtain_string_before_lastslash(var_ll[j]->fullpath);
3894 if(var_ll_i_path.size() > var_ll_j_path.size()) {
3898 if(var_ll_i_path.compare(0,var_ll_j_path.size(),var_ll_j_path)==0) {
3899 var_share_dims[i] =
true;
3900 grp_cv_paths.insert(var_ll_i_path);
3903 var_share_dims[i] =
true;
3904 var_share_dims[j] =
true;
3906 grp_cv_paths.insert(var_ll_i_path);
3907 grp_cv_paths.insert(var_ll_j_path);
3910 else if (var_ll_i_path.size() == var_ll_j_path.size()) {
3911 var_share_dims[i] =
true;
3912 var_share_dims[j] =
true;
3913 if(var_ll_i_path == var_ll_j_path)
3914 grp_cv_paths.insert(var_ll_i_path);
3916 grp_cv_paths.insert(var_ll_i_path);
3917 grp_cv_paths.insert(var_ll_j_path);
3923 if(var_ll_j_path.compare(0,var_ll_i_path.size(),var_ll_i_path)==0) {
3924 var_share_dims[j] =
true;
3925 grp_cv_paths.insert(var_ll_j_path);
3928 var_share_dims[i] =
true;
3929 var_share_dims[j] =
true;
3931 grp_cv_paths.insert(var_ll_i_path);
3932 grp_cv_paths.insert(var_ll_j_path);
3942 for(vector<Var*>::iterator itv = var_ll.begin(); itv!= var_ll.end();) {
3943 if(
true == var_share_dims[var_index]) {
3944 latlon2d_path_to_index.erase((*itv)->fullpath);
3946 itv = var_ll.erase(itv);
3957 void GMFile::Remove_2DLLCVar_Final_Candidate_from_Vars(vector<int> &var2d_index) {
3959 BESDEBUG(
"h5",
"Coming to Remove_2DLLCVar_Final_Candidate_from_Vars()"<<endl);
3961 sort(var2d_index.begin(),var2d_index.end());
3962 vector<Var *>::iterator it = this->
vars.begin();
3968 for (
unsigned int i = 0; i <var2d_index.size();i++) {
3970 advance(it,var2d_index[i]);
3972 advance(it,var2d_index[i]-var2d_index[i-1]-1);
3974 if(it == this->
vars.end())
3975 throw1(
"Out of range to obtain 2D lat/lon variables");
3978 it = this->
vars.erase(it);
3986 bool GMFile::Check_Var_2D_CVars(
Var *var) {
3988 BESDEBUG(
"h5",
"Coming to Check_Var_2D_CVars()"<<endl);
3989 bool ret_value =
true;
3990 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
3991 ircv != this->cvars.end(); ++ircv) {
3992 if((*ircv)->rank==2) {
3993 short first_dim_index = 0;
3994 short first_dim_times = 0;
3995 short second_dim_index = 0;
3996 short second_dim_times = 0;
3997 for (vector<Dimension *>::iterator ird = var->dims.begin();
3998 ird != var->dims.end(); ++ird) {
3999 if((*ird)->name == ((*ircv)->getDimensions()[0])->name) {
4000 first_dim_index = distance(var->dims.begin(),ird);
4003 else if((*ird)->name == ((*ircv)->getDimensions()[1])->name) {
4004 second_dim_index = distance(var->dims.begin(),ird);
4010 if(first_dim_times == 1 && second_dim_times == 1) {
4011 if(first_dim_index < second_dim_index) {
4024 bool GMFile::Flatten_VarPath_In_Coordinates_Attr(
Var *var) {
4026 BESDEBUG(
"h5",
"Coming to Flatten_VarPath_In_Coordinates_Attr()"<<endl);
4027 string co_attrname =
"coordinates";
4028 bool has_coor_attr =
false;
4029 string orig_coor_value;
4030 string flatten_coor_value;
4034 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end();) {
4038 if((*ira)->name == co_attrname) {
4039 Retrieve_H5_Attr_Value((*ira),var->fullpath);
4040 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
4041 orig_coor_value = orig_attr_value;
4042 has_coor_attr =
true;
4044 ira = var->attrs.erase(ira);
4051 if(
true == has_coor_attr) {
4054 size_t ele_start_pos = 0;
4055 size_t cur_pos = orig_coor_value.find_first_of(sc);
4056 while(cur_pos !=string::npos) {
4057 string tempstr = orig_coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
4058 tempstr = get_CF_string(tempstr);
4059 flatten_coor_value += tempstr + sc;
4060 ele_start_pos = cur_pos+1;
4061 cur_pos = orig_coor_value.find_first_of(sc,cur_pos+1);
4064 if(ele_start_pos == 0)
4065 flatten_coor_value = get_CF_string(orig_coor_value);
4067 flatten_coor_value += get_CF_string(orig_coor_value.substr(ele_start_pos));
4071 Add_Str_Attr(attr,co_attrname,flatten_coor_value);
4072 var->attrs.push_back(attr);
4082 bool GMFile::Flatten_VarPath_In_Coordinates_Attr_EOS5(
Var *var) {
4084 BESDEBUG(
"h5",
"Coming to Flatten_VarPath_In_Coordinates_Attr_EOS5()"<<endl);
4085 string co_attrname =
"coordinates";
4086 bool has_coor_attr =
false;
4087 string orig_coor_value;
4088 string flatten_coor_value;
4092 for (vector<Attribute *>:: iterator ira =var->attrs.begin(); ira !=var->attrs.end();) {
4096 if((*ira)->name == co_attrname) {
4097 Retrieve_H5_Attr_Value((*ira),var->fullpath);
4099 string orig_attr_value((*ira)->value.begin(),(*ira)->value.end());
4100 orig_coor_value = orig_attr_value;
4101 has_coor_attr =
true;
4103 ira = var->attrs.erase(ira);
4110 if(
true == has_coor_attr) {
4114 size_t ele_start_pos = 0;
4116 size_t cur_pos = orig_coor_value.find_first_of(sc);
4117 while(cur_pos !=string::npos) {
4118 string tempstr = orig_coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
4121 tempstr = get_CF_string(tempstr);
4122 flatten_coor_value += tempstr + sc;
4123 ele_start_pos = cur_pos+1;
4124 cur_pos = orig_coor_value.find_first_of(sc,cur_pos+1);
4127 if(ele_start_pos == 0) {
4130 flatten_coor_value = get_CF_string(tempstr);
4133 flatten_coor_value += get_CF_string(orig_coor_value.substr(ele_start_pos));
4137 Add_Str_Attr(attr,co_attrname,flatten_coor_value);
4138 var->attrs.push_back(attr);
4150 bool GMFile::Check_2DLatLon_Dimscale(
string & latname,
string &lonname) {
4168 bool latlon_2d_cv_check1 =
false;
4171 latlon_2d_cv_check1 =
true;
4174 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4175 ircv != this->cvars.end(); ++ircv) {
4176 if((*ircv)->cvartype == CV_FILLINDEX){
4177 latlon_2d_cv_check1 =
true;
4183 bool latlon_2d_cv_check2 =
true;
4186 if(
true == latlon_2d_cv_check1) {
4187 BESDEBUG(
"h5",
"Coming to check if having 2d latlon coordinates for a netCDF-4 like product. "<<endl);
4190 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4191 ircv != this->cvars.end(); ++ircv) {
4192 if((*ircv)->cvartype == CV_EXIST) {
4193 for(vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
4194 ira != (*ircv)->attrs.end();ira++) {
4195 string attr_name =
"units";
4196 string lat_unit_value =
"degrees_north";
4197 string lon_unit_value =
"degrees_east";
4200 if((
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lat_unit_value)) ||
4201 (
true == Is_Str_Attr(*ira,(*ircv)->fullpath,attr_name,lon_unit_value))) {
4202 latlon_2d_cv_check2=
false;
4208 if(
false == latlon_2d_cv_check2)
4213 bool latlon_2d_cv_check3 =
true;
4216 if(
true == latlon_2d_cv_check1 &&
true == latlon_2d_cv_check2) {
4218 short latlon_flag = 0;
4219 short LatLon_flag = 0;
4220 short latilong_flag = 0;
4222 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4223 ircv != this->cvars.end(); ++ircv) {
4224 if((*ircv)->cvartype == CV_EXIST) {
4225 if((*ircv)->name ==
"lat")
4227 else if((*ircv)->name ==
"lon")
4229 else if((*ircv)->name ==
"latitude")
4231 else if((*ircv)->name ==
"longitude")
4233 else if((*ircv)->name ==
"Latitude")
4235 else if((*ircv)->name ==
"Longitude")
4240 if((2== latlon_flag) || (2 == latilong_flag) || (2 == LatLon_flag ))
4241 latlon_2d_cv_check3 =
false;
4244 bool latlon_2d =
false;
4245 short latlon_flag = 0;
4246 string latdim1,latdim2,londim1,londim2;
4248 short LatLon_flag = 0;
4249 string Latdim1,Latdim2,Londim1,Londim2;
4251 short latilong_flag = 0;
4252 string latidim1,latidim2,longdim1,longdim2;
4259 if(
true == latlon_2d_cv_check1 &&
true == latlon_2d_cv_check2 &&
true == latlon_2d_cv_check3) {
4261 for (vector<Var *>::iterator irv = this->
vars.begin();
4262 irv != this->
vars.end(); ++irv) {
4265 if((*irv)->rank == 2) {
4266 if((*irv)->name ==
"lat") {
4268 latdim1 = (*irv)->getDimensions()[0]->name;
4269 latdim2 = (*irv)->getDimensions()[1]->name;
4272 else if((*irv)->name ==
"lon") {
4274 londim1 = (*irv)->getDimensions()[0]->name;
4275 londim2 = (*irv)->getDimensions()[1]->name;
4277 else if((*irv)->name ==
"latitude"){
4279 latidim1 = (*irv)->getDimensions()[0]->name;
4280 latidim2 = (*irv)->getDimensions()[1]->name;
4282 else if((*irv)->name ==
"longitude"){
4284 longdim1 = (*irv)->getDimensions()[0]->name;
4285 longdim2 = (*irv)->getDimensions()[1]->name;
4288 else if((*irv)->name ==
"Latitude"){
4290 Latdim1 = (*irv)->getDimensions()[0]->name;
4291 Latdim2 = (*irv)->getDimensions()[1]->name;
4294 else if((*irv)->name ==
"Longitude"){
4296 Londim1 = (*irv)->getDimensions()[0]->name;
4297 Londim2 = (*irv)->getDimensions()[1]->name;
4307 if(2 == latlon_flag) {
4308 if((2 == latilong_flag) || ( 2 == LatLon_flag))
4310 else if((latdim1 == londim1) && (latdim2 == londim2)) {
4316 else if ( 2 == latilong_flag) {
4317 if( 2 == LatLon_flag)
4319 else if ((latidim1 == longdim1) ||(latidim2 == longdim2)) {
4320 latname =
"latitude";
4321 lonname =
"longitude";
4325 else if (2 == LatLon_flag){
4326 if ((Latdim1 == Londim1) ||(Latdim2 == Londim2)) {
4327 latname =
"Latitude";
4328 lonname =
"Longitude";
4339 void GMFile::Update_2DLatLon_Dimscale_CV(
const string &latname,
const string &lonname) {
4344 for (vector<Var *>::iterator irv = this->
vars.begin();
4345 irv != this->
vars.end(); ++irv) {
4347 if((*irv)->rank == 2) {
4350 if((*irv)->name == latname) {
4353 string latdim0 = (*irv)->getDimensions()[0]->name;
4357 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ) {
4358 if((*i)->cfdimname == latdim0) {
4359 if(CV_FILLINDEX == (*i)->cvartype) {
4361 i = this->cvars.erase(i);
4363 else if(CV_EXIST == (*i)->cvartype) {
4366 this->
vars.push_back(var);
4369 i = this->cvars.erase(i);
4373 if(CV_LAT_MISS == (*i)->cvartype)
4374 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_LAT_MISS");
4375 else if(CV_LON_MISS == (*i)->cvartype)
4376 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_LON_MISS");
4377 else if(CV_NONLATLON_MISS == (*i)->cvartype)
4378 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_NONLATLON_MISS");
4379 else if(CV_MODIFY == (*i)->cvartype)
4380 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_MODIFY");
4381 else if(CV_SPECIAL == (*i)->cvartype)
4382 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_SPECIAL");
4384 throw3(
"For the 2-D lat/lon case, the latitude dimension name ",latdim0,
"is a coordinate variable of type CV_UNSUPPORTED");
4393 GMcvar->cfdimname = latdim0;
4394 GMcvar->cvartype = CV_EXIST;
4395 GMcvar->product_type = product_type;
4396 this->cvars.push_back(GMcvar);
4398 this->
vars.erase(irv);
4405 for (vector<Var *>::iterator irv = this->
vars.begin();
4406 irv != this->
vars.end(); ++irv) {
4408 if((*irv)->rank == 2) {
4411 if((*irv)->name == lonname) {
4414 string londim0 = (*irv)->getDimensions()[1]->name;
4417 for (vector<GMCVar *>:: iterator i= this->cvars.begin(); i!=this->cvars.end(); ) {
4419 if((*i)->cfdimname == londim0) {
4420 if(CV_FILLINDEX == (*i)->cvartype) {
4422 i= this->cvars.erase(i);
4424 else if(CV_EXIST == (*i)->cvartype) {
4427 this->
vars.push_back(var);
4430 i = this->cvars.erase(i);
4433 if(CV_LAT_MISS == (*i)->cvartype)
4434 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_LAT_MISS");
4435 else if(CV_LON_MISS == (*i)->cvartype)
4436 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_LON_MISS");
4437 else if(CV_NONLATLON_MISS == (*i)->cvartype)
4438 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_NONLATLON_MISS");
4439 else if(CV_MODIFY == (*i)->cvartype)
4440 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_MODIFY");
4441 else if(CV_SPECIAL == (*i)->cvartype)
4442 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_SPECIAL");
4444 throw3(
"For the 2-D lat/lon case, the longitude dimension name ",londim0,
"is a coordinate variable of type CV_UNSUPPORTED");
4453 GMcvar->cfdimname = londim0;
4454 GMcvar->cvartype = CV_EXIST;
4455 GMcvar->product_type = product_type;
4456 this->cvars.push_back(GMcvar);
4458 this->
vars.erase(irv);
4467 void GMFile::Handle_CVar_LatLon1D_General_Product() {
4469 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon1D_General_Product()"<<endl);
4470 this->iscoard =
true;
4471 Handle_CVar_LatLon_General_Product();
4476 void GMFile::Handle_CVar_LatLon2D_General_Product() {
4478 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon2D_General_Product()"<<endl);
4479 Handle_CVar_LatLon_General_Product();
4485 void GMFile::Handle_CVar_LatLon_General_Product() {
4487 BESDEBUG(
"h5",
"Coming to Handle_CVar_LatLon_General_Product()"<<endl);
4488 if((GENERAL_LATLON2D != this->gproduct_pattern)
4489 && GENERAL_LATLON1D != this->gproduct_pattern)
4490 throw1(
"This function only supports latlon 1D or latlon 2D general products");
4492 pair<set<string>::iterator,
bool> setret;
4493 set<string>tempdimnamelist = dimnamelist;
4495 for (vector<Var *>::iterator irv = this->
vars.begin();
4496 irv != this->
vars.end(); ++irv) {
4499 if (gp_latname== (*irv)->name) {
4503 tempdimnamelist.erase(((*irv)->dims[0])->name);
4505 GMcvar->cfdimname = ((*irv)->dims[0])->name;
4506 GMcvar->cvartype = CV_EXIST;
4507 GMcvar->product_type = product_type;
4508 this->cvars.push_back(GMcvar);
4510 this->
vars.erase(irv);
4515 for (vector<Var *>::iterator irv = this->
vars.begin();
4516 irv != this->
vars.end(); ++irv) {
4519 if (gp_lonname== (*irv)->name) {
4525 if(GENERAL_LATLON2D == this->gproduct_pattern)
4526 londimname = ((*irv)->dims[1])->name;
4528 londimname = ((*irv)->dims[0])->name;
4530 tempdimnamelist.erase(londimname);
4532 GMcvar->cfdimname = londimname;
4533 GMcvar->cvartype = CV_EXIST;
4534 GMcvar->product_type = product_type;
4535 this->cvars.push_back(GMcvar);
4537 this->
vars.erase(irv);
4544 for (set<string>::iterator irs = tempdimnamelist.begin();
4545 irs != tempdimnamelist.end();irs++) {
4547 Create_Missing_CV(GMcvar,*irs);
4548 this->cvars.push_back(GMcvar);
4554 void GMFile::Handle_CVar_OBPG_L3() {
4556 BESDEBUG(
"h5",
"Coming to Handle_CVar_OBPG_L3()"<<endl);
4557 if (GENERAL_DIMSCALE == this->gproduct_pattern)
4558 Handle_CVar_Dimscale_General_Product();
4561 for (vector<Var *>::iterator irv = this->
vars.begin();
4562 irv != this->
vars.end(); ++irv) {
4569 if((*irv)->rank == 2) {
4571 if(((*irv)->fullpath.find(
"/geophsical_data") == 0) || ((*irv)->dtype == H5FLOAT32)) {
4573 size_t lat_size = (*irv)->getDimensions()[0]->size;
4574 string lat_name = (*irv)->getDimensions()[0]->name;
4575 size_t lon_size = (*irv)->getDimensions()[1]->size;
4576 string lon_name = (*irv)->getDimensions()[1]->name;
4577 size_t temp_size = 0;
4579 H5DataType ll_dtype = (*irv)->dtype;
4582 if(lat_size >lon_size) {
4583 temp_size = lon_size;
4584 temp_name = lon_name;
4585 lon_size = lat_size;
4586 lon_name = lat_name;
4587 lat_size = temp_size;
4588 lat_name = temp_name;
4590 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
4591 ircv != this->cvars.end(); ++ircv) {
4592 if((*ircv)->cvartype == CV_FILLINDEX) {
4593 if((*ircv)->getDimensions()[0]->size == lat_size &&
4594 (*ircv)->getDimensions()[0]->name == lat_name) {
4595 (*ircv)->cvartype = CV_LAT_MISS;
4596 (*ircv)->dtype = ll_dtype;
4597 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
4598 ira != (*ircv)->attrs.end(); ++ira) {
4599 if ((*ira)->name ==
"NAME") {
4601 (*ircv)->attrs.erase(ira);
4606 else if((*ircv)->getDimensions()[0]->size == lon_size &&
4607 (*ircv)->getDimensions()[0]->name == lon_name) {
4608 (*ircv)->cvartype = CV_LON_MISS;
4609 (*ircv)->dtype = ll_dtype;
4610 for (vector<Attribute *>::iterator ira = (*ircv)->attrs.begin();
4611 ira != (*ircv)->attrs.end(); ++ira) {
4612 if ((*ira)->name ==
"NAME") {
4614 (*ircv)->attrs.erase(ira);
4633 BESDEBUG(
"h5",
"Coming to Handle_SpVar()"<<endl);
4634 if (ACOS_L2S_OR_OCO2_L1B == product_type)
4635 Handle_SpVar_ACOS_OCO2();
4636 else if(GPM_L1 == product_type) {
4639 for (vector<Var *>::iterator irv = this->
vars.begin();
4640 irv != this->
vars.end(); ++irv) {
4641 if((*irv)->name==
"AlgorithmRuntimeInfo") {
4643 this->
vars.erase(irv);
4650 else if(GPMM_L3 == product_type || GPMS_L3 == product_type) {
4652 for (vector<Var *>::iterator irv = this->
vars.begin();
4653 irv != this->
vars.end(); ) {
4654 if((*irv)->name==
"InputFileNames") {
4656 irv = this->
vars.erase(irv);
4658 else if((*irv)->name==
"InputAlgorithmVersions") {
4660 irv = this->
vars.erase(irv);
4662 else if((*irv)->name==
"InputGenerationDateTimes") {
4664 irv = this->
vars.erase(irv);
4677 void GMFile::Handle_SpVar_ACOS_OCO2() {
4679 BESDEBUG(
"h5",
"Coming to Handle_SpVar_ACOS_OCO2()"<<endl);
4682 for (vector<Var *>::iterator irv = this->
vars.begin();
4683 irv != this->
vars.end(); ) {
4684 if (H5INT64 == (*irv)->getType()) {
4688 spvar->name = (*irv)->name +
"_Time";
4689 spvar->newname = (*irv)->newname+
"_Time";
4690 spvar->dtype = H5INT32;
4691 spvar->otype = (*irv)->getType();
4695 spvar->numofdbits = 6;
4696 this->spvars.push_back(spvar);
4700 spvar2->name = (*irv)->name +
"_Date";
4701 spvar2->newname = (*irv)->newname+
"_Date";
4702 spvar2->dtype = H5INT32;
4703 spvar2->otype = (*irv)->getType();
4707 spvar2->numofdbits = 8;
4708 this->spvars.push_back(spvar2);
4711 irv = this->
vars.erase(irv);
4723 BESDEBUG(
"h5",
"Coming to Adjust_Obj_Name()"<<endl);
4724 if(Mea_Ozone == product_type)
4725 Adjust_Mea_Ozone_Obj_Name();
4727 if(GPMS_L3 == product_type || GPMM_L3 == product_type)
4728 Adjust_GPM_L3_Obj_Name();
4732 for (vector<Var*>::iterator irv2 = this->
vars.begin();
4733 irv2 != this->
vars.end(); irv2++) {
4734 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
4735 ird !=(*irv2)->dims.end(); ird++) {
4736 cerr<<
"Dimension name afet Adjust_Obj_Name "<<(*ird)->newname <<endl;
4744 void GMFile:: Adjust_GPM_L3_Obj_Name() {
4746 BESDEBUG(
"h5",
"Coming to Adjust_GPM_L3_Obj_Name()"<<endl);
4749 if(this->
groups.size() <= 1) {
4750 for (vector<Var *>::iterator irv = this->
vars.begin();
4751 irv != this->
vars.end(); ++irv) {
4752 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4753 if (objnewname !=
"")
4754 (*irv)->newname = objnewname;
4758 for (vector<Var *>::iterator irv = this->
vars.begin();
4759 irv != this->
vars.end(); ++irv) {
4760 size_t grid_group_path_pos = ((*irv)->newname.substr(1)).find_first_of(
"/");
4761 objnewname = ((*irv)->newname).substr(grid_group_path_pos+2);
4762 (*irv)->newname = objnewname;
4768 void GMFile:: Adjust_Mea_Ozone_Obj_Name() {
4770 BESDEBUG(
"h5",
"Coming to Adjust_Mea_Ozone_Obj_Name()"<<endl);
4772 for (vector<Var *>::iterator irv = this->
vars.begin();
4773 irv != this->
vars.end(); ++irv) {
4774 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4775 if (objnewname !=
"")
4776 (*irv)->newname = objnewname;
4780 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4781 ird !=(*irv)->dims.end();++ird) {
4782 cerr<<
"Ozone dim. name "<<(*ird)->name <<endl;
4783 cerr<<
"Ozone dim. new name "<<(*ird)->newname <<endl;
4789 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4790 irv != this->cvars.end(); ++irv) {
4791 objnewname = HDF5CFUtil::obtain_string_after_lastslash((*irv)->newname);
4792 if (objnewname !=
"")
4793 (*irv)->newname = objnewname;
4796 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4797 ird !=(*irv)->dims.end();++ird) {
4798 cerr<<
"Ozone CV dim. name "<<(*ird)->name <<endl;
4799 cerr<<
"Ozone CV dim. new name "<<(*ird)->newname <<endl;
4808 BESDEBUG(
"h5",
"GMFile::Coming to Flatten_Obj_Name()"<<endl);
4813 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4814 irv != this->cvars.end(); ++irv) {
4815 (*irv)->newname = get_CF_string((*irv)->newname);
4817 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4818 ird != (*irv)->dims.end(); ++ird) {
4819 (*ird)->newname = get_CF_string((*ird)->newname);
4822 if (
true == include_attr) {
4823 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
4824 ira != (*irv)->attrs.end(); ++ira)
4825 (*ira)->newname = File::get_CF_string((*ira)->newname);
4832 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
4833 irv != this->spvars.end(); ++irv) {
4834 (*irv)->newname = get_CF_string((*irv)->newname);
4836 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
4837 ird != (*irv)->dims.end(); ++ird)
4838 (*ird)->newname = get_CF_string((*ird)->newname);
4840 if (
true == include_attr) {
4841 for (vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
4842 ira != (*irv)->attrs.end(); ++ira)
4843 (*ira)->newname = File::get_CF_string((*ira)->newname);
4850 for (vector<Var*>::iterator irv2 = this->
vars.begin();
4851 irv2 != this->
vars.end(); irv2++) {
4852 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
4853 ird !=(*irv2)->dims.end(); ird++) {
4854 cerr<<
"Dimension name afet Flatten_Obj_Name "<<(*ird)->newname <<endl;
4866 BESDEBUG(
"h5",
"GMFile::Coming to Handle_Obj_NameClashing()"<<endl);
4870 set<string>objnameset;
4871 Handle_GMCVar_NameClashing(objnameset);
4872 Handle_GMSPVar_NameClashing(objnameset);
4873 File::Handle_GeneralObj_NameClashing(include_attr,objnameset);
4874 if (
true == include_attr) {
4875 Handle_GMCVar_AttrNameClashing();
4876 Handle_GMSPVar_AttrNameClashing();
4883 void GMFile::Handle_GMCVar_NameClashing(set<string> &objnameset ) {
4885 GMHandle_General_NameClashing(objnameset,this->cvars);
4889 void GMFile::Handle_GMSPVar_NameClashing(set<string> &objnameset ) {
4891 GMHandle_General_NameClashing(objnameset,this->spvars);
4895 void GMFile::Handle_GMCVar_AttrNameClashing() {
4897 BESDEBUG(
"h5",
"Coming to Handle_GMCVar_AttrNameClashing()"<<endl);
4898 set<string> objnameset;
4900 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4901 irv != this->cvars.end(); ++irv) {
4902 Handle_General_NameClashing(objnameset,(*irv)->attrs);
4908 void GMFile::Handle_GMSPVar_AttrNameClashing() {
4910 BESDEBUG(
"h5",
"Coming to Handle_GMSPVar_AttrNameClashing()"<<endl);
4911 set<string> objnameset;
4913 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
4914 irv != this->spvars.end(); ++irv) {
4915 Handle_General_NameClashing(objnameset,(*irv)->attrs);
4923 template<
class T>
void 4924 GMFile::GMHandle_General_NameClashing(set <string>&objnameset, vector<T*>& objvec) {
4926 BESDEBUG(
"h5",
"Coming to GMHandle_General_NameClashing()"<<endl);
4927 pair<set<string>::iterator,
bool> setret;
4928 set<string>::iterator iss;
4930 vector<string> clashnamelist;
4931 vector<string>::iterator ivs;
4933 map<int,int> cl_to_ol;
4937 typename vector<T*>::iterator irv;
4939 for (irv = objvec.begin();
4940 irv != objvec.end(); ++irv) {
4942 setret = objnameset.insert((*irv)->newname);
4943 if (
false == setret.second ) {
4944 clashnamelist.insert(clashnamelist.end(),(*irv)->newname);
4945 cl_to_ol[cl_index] = ol_index;
4954 for (ivs=clashnamelist.begin(); ivs!=clashnamelist.end(); ++ivs) {
4955 int clash_index = 1;
4956 string temp_clashname = *ivs +
'_';
4957 HDF5CFUtil::gen_unique_name(temp_clashname,objnameset,clash_index);
4958 *ivs = temp_clashname;
4963 for (
unsigned int i =0; i <clashnamelist.size(); i++)
4964 objvec[cl_to_ol[i]]->newname = clashnamelist[i];
4972 BESDEBUG(
"h5",
"GMFile: Coming to Handle_DimNameClashing()"<<endl);
4974 if (ACOS_L2S_OR_OCO2_L1B == product_type)
4977 map<string,string>dimname_to_dimnewname;
4978 pair<map<string,string>::iterator,
bool>mapret;
4979 set<string> dimnameset;
4980 vector<Dimension*>vdims;
4981 set<string> dimnewnameset;
4982 pair<set<string>::iterator,
bool> setret;
4985 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
4986 irv !=this->cvars.end(); ++irv) {
4987 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
4988 ird !=(*irv)->dims.end();++ird) {
4989 setret = dimnameset.insert((*ird)->name);
4990 if (
true == setret.second)
4991 vdims.push_back(*ird);
4998 for(vector<Var *>::iterator irv= this->
vars.begin();
4999 irv != this->
vars.end();++irv) {
5000 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
5001 ird !=(*irv)->dims.end();++ird) {
5003 setret = dimnameset.insert((*ird)->name);
5004 if (setret.second) vdims.push_back(*ird);
5008 GMHandle_General_NameClashing(dimnewnameset,vdims);
5011 for (vector<Dimension*>::iterator ird = vdims.begin();ird!=vdims.end();++ird) {
5012 mapret = dimname_to_dimnewname.insert(pair<string,string>((*ird)->name,(*ird)->newname));
5013 if (
false == mapret.second)
5014 throw4(
"The dimension name ",(*ird)->name,
" should map to ",
5019 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5020 irv !=this->cvars.end(); ++irv)
5021 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
5022 ird!=(*irv)->dims.end();++ird)
5023 (*ird)->newname = dimname_to_dimnewname[(*ird)->name];
5025 for (vector<Var *>::iterator irv = this->
vars.begin();
5026 irv != this->
vars.end(); ++irv)
5027 for (vector <Dimension *>:: iterator ird = (*irv)->dims.begin();
5028 ird !=(*irv)->dims.end();++ird)
5029 (*ird)->newname = dimname_to_dimnewname[(*ird)->name];
5036 BESDEBUG(
"h5",
"GMFile:Coming to Adjust_Dim_Name()"<<endl);
5039 for (vector<Var*>::iterator irv2 = this->
vars.begin();
5040 irv2 != this->
vars.end(); irv2++) {
5041 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
5042 ird !=(*irv2)->dims.end(); ird++) {
5043 cerr<<
"Dimension new name "<<(*ird)->newname <<endl;
5049 if(
true == iscoard) {
5050 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5051 irv !=this->cvars.end(); ++irv) {
5053 cerr<<
"1D Cvariable name is "<<(*irv)->name <<endl;
5054 cerr<<
"1D Cvariable new name is "<<(*irv)->newname <<endl;
5055 cerr<<
"1D Cvariable dim name is "<<((*irv)->dims)[0]->name <<endl;
5056 cerr<<
"1D Cvariable dim new name is "<<((*irv)->dims)[0]->newname <<endl;
5058 if ((*irv)->dims.size()!=1)
5059 throw3(
"Coard coordinate variable ",(*irv)->name,
"is not 1D");
5060 if ((*irv)->newname != (((*irv)->dims)[0]->newname)) {
5061 ((*irv)->dims)[0]->newname = (*irv)->newname;
5064 for (vector<Var*>::iterator irv2 = this->
vars.begin();
5065 irv2 != this->
vars.end(); ++irv2) {
5066 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
5067 ird !=(*irv2)->dims.end(); ++ird) {
5072 if ((*ird)->name == ((*irv)->dims)[0]->name)
5073 (*ird)->newname = ((*irv)->dims)[0]->newname;
5082 for (vector<Var*>::iterator irv2 = this->
vars.begin();
5083 irv2 != this->
vars.end(); irv2++) {
5084 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
5085 ird !=(*irv2)->dims.end(); ird++) {
5086 cerr<<
"Dimension name afet Adjust_Dim_Name "<<(*ird)->newname <<endl;
5098 BESDEBUG(
"h5",
"GMFile::Coming to Add_Supplement_Attrs()"<<endl);
5099 if (General_Product == product_type ||
true == add_path) {
5103 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5104 irv != this->cvars.end(); ++irv) {
5105 if (((*irv)->cvartype == CV_EXIST) || ((*irv)->cvartype == CV_MODIFY)) {
5107 const string varname = (*irv)->name;
5108 const string attrname =
"origname";
5109 Add_Str_Attr(attr,attrname,varname);
5110 (*irv)->attrs.push_back(attr);
5114 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5115 irv != this->cvars.end(); ++irv) {
5116 if (((*irv)->cvartype == CV_EXIST) || ((*irv)->cvartype == CV_MODIFY)) {
5118 const string varname = (*irv)->fullpath;
5119 const string attrname =
"fullnamepath";
5120 Add_Str_Attr(attr,attrname,varname);
5121 (*irv)->attrs.push_back(attr);
5125 for (vector<GMSPVar *>::iterator irv = this->spvars.begin();
5126 irv != this->spvars.end(); ++irv) {
5128 const string varname = (*irv)->name;
5129 const string attrname =
"origname";
5130 Add_Str_Attr(attr,attrname,varname);
5131 (*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)->fullpath;
5138 const string attrname =
"fullnamepath";
5139 Add_Str_Attr(attr,attrname,varname);
5140 (*irv)->attrs.push_back(attr);
5144 if(GPM_L1 == product_type || GPMS_L3 == product_type || GPMM_L3 == product_type)
5146 else if (Aqu_L3 == product_type)
5148 else if (Mea_SeaWiFS_L2 == product_type || Mea_SeaWiFS_L3 == product_type)
5149 Add_SeaWiFS_Attrs();
5155 GMFile:: Add_GPM_Attrs() {
5157 BESDEBUG(
"h5",
"Coming to Add_GPM_Attrs()"<<endl);
5158 vector<HDF5CF::Var *>::const_iterator it_v;
5159 vector<HDF5CF::Attribute *>::const_iterator ira;
5160 const string attr_name_be_replaced =
"CodeMissingValue";
5161 const string attr_new_name =
"_FillValue";
5162 const string attr2_name_be_replaced =
"Units";
5163 const string attr2_new_name =
"units";
5168 for (it_v =
vars.begin(); it_v !=
vars.end(); ++it_v) {
5169 bool has_fvalue_attr =
false;
5170 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5171 if(attr_new_name == (*ira)->name) {
5172 has_fvalue_attr =
true;
5177 if(
false == has_fvalue_attr) {
5178 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5179 if(attr_name_be_replaced == (*ira)->name) {
5180 if((*ira)->dtype == H5FSTRING)
5181 Change_Attr_One_Str_to_Others((*ira),(*it_v));
5182 (*ira)->name = attr_new_name;
5183 (*ira)->newname = attr_new_name;
5191 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
5192 irv != this->cvars.end(); ++irv) {
5193 bool has_fvalue_attr =
false;
5195 for(ira = (*irv)->attrs.begin(); ira!= (*irv)->attrs.end();ira++) {
5197 if(attr_new_name == (*ira)->name) {
5198 has_fvalue_attr =
true;
5202 if(
false == has_fvalue_attr) {
5203 for(ira = (*irv)->attrs.begin(); ira!= (*irv)->attrs.end();ira++) {
5205 if(attr_name_be_replaced == (*ira)->name) {
5206 if((*ira)->dtype == H5FSTRING)
5207 Change_Attr_One_Str_to_Others((*ira),(*irv));
5208 (*ira)->name = attr_new_name;
5209 (*ira)->newname = attr_new_name;
5216 if(product_type == GPM_L1) {
5218 if ((*irv)->cvartype == CV_EXIST) {
5219 if((*irv)->name.find(
"Latitude") !=string::npos) {
5220 string unit_value =
"degrees_north";
5221 Correct_GPM_L1_LatLon_units(*irv,unit_value);
5224 else if((*irv)->name.find(
"Longitude") !=string::npos) {
5225 string unit_value =
"degrees_east";
5226 Correct_GPM_L1_LatLon_units(*irv,unit_value);
5231 else if ((*irv)->cvartype == CV_NONLATLON_MISS) {
5234 const string attrname =
"comment";
5238 if((*irv)->name ==
"nchannel1")
5239 comment =
"Number of Swath S1 channels (10V 10H 19V 19H 23V 37V 37H 89V 89H).";
5240 else if((*irv)->name ==
"nchannel2")
5241 comment =
"Number of Swath S2 channels (166V 166H 183+/-3V 183+/-8V).";
5242 else if((*irv)->name ==
"nchan1")
5243 comment =
"Number of channels in Swath 1.";
5244 else if((*irv)->name ==
"nchan2")
5245 comment =
"Number of channels in Swath 2.";
5246 else if((*irv)->name ==
"VH")
5247 comment =
"Number of polarizations.";
5248 else if((*irv)->name ==
"GMIxyz")
5249 comment =
"x, y, z components in GMI instrument coordinate system.";
5250 else if((*irv)->name ==
"LNL")
5251 comment =
"Linear and non-linear.";
5252 else if((*irv)->name ==
"nscan")
5253 comment =
"Number of scans in the granule.";
5254 else if((*irv)->name ==
"nscan1")
5255 comment =
"Typical number of Swath S1 scans in the granule.";
5256 else if((*irv)->name ==
"nscan2")
5257 comment =
"Typical number of Swath S2 scans in the granule.";
5258 else if((*irv)->name ==
"npixelev")
5259 comment =
"Number of earth view pixels in one scan.";
5260 else if((*irv)->name ==
"npixelht")
5261 comment =
"Number of hot load pixels in one scan.";
5262 else if((*irv)->name ==
"npixelcs")
5263 comment =
"Number of cold sky pixels in one scan.";
5264 else if((*irv)->name ==
"npixelfr")
5265 comment =
"Number of full rotation earth view pixels in one scan.";
5266 else if((*irv)->name ==
"nfreq1")
5267 comment =
"Number of frequencies in Swath 1.";
5268 else if((*irv)->name ==
"nfreq2")
5269 comment =
"Number of frequencies in Swath 2.";
5270 else if((*irv)->name ==
"npix1")
5271 comment =
"Number of pixels in Swath 1.";
5272 else if((*irv)->name ==
"npix2")
5273 comment =
"Number of pixels in Swath 2.";
5274 else if((*irv)->name ==
"npix3")
5275 comment =
"Number of pixels in Swath 3.";
5276 else if((*irv)->name ==
"npix4")
5277 comment =
"Number of pixels in Swath 4.";
5278 else if((*irv)->name ==
"ncolds1")
5279 comment =
"Maximum number of cold samples in Swath 1.";
5280 else if((*irv)->name ==
"ncolds2")
5281 comment =
"Maximum number of cold samples in Swath 2.";
5282 else if((*irv)->name ==
"nhots1")
5283 comment =
"Maximum number of hot samples in Swath 1.";
5284 else if((*irv)->name ==
"nhots2")
5285 comment =
"Maximum number of hot samples in Swath 2.";
5286 else if((*irv)->name ==
"ntherm")
5287 comment =
"Number of hot load thermisters.";
5288 else if((*irv)->name ==
"ntach")
5289 comment =
"Number of tachometer readings.";
5290 else if((*irv)->name ==
"nsamt"){
5291 comment =
"Number of sample types. ";
5292 comment = +
"The types are: total science GSDR, earthview,hot load, cold sky.";
5294 else if((*irv)->name ==
"nndiode")
5295 comment =
"Number of noise diodes.";
5296 else if((*irv)->name ==
"n7")
5297 comment =
"Number seven.";
5298 else if((*irv)->name ==
"nray")
5299 comment =
"Number of angle bins in each NS scan.";
5300 else if((*irv)->name ==
"nrayMS")
5301 comment =
"Number of angle bins in each MS scan.";
5302 else if((*irv)->name ==
"nrayHS")
5303 comment =
"Number of angle bins in each HS scan.";
5304 else if((*irv)->name ==
"nbin")
5305 comment =
"Number of range bins in each NS and MS ray. Bin interval is 125m.";
5306 else if((*irv)->name ==
"nbinHS")
5307 comment =
"Number of range bins in each HS ray. Bin interval is 250m.";
5308 else if((*irv)->name ==
"nbinSZP")
5309 comment =
"Number of range bins for sigmaZeroProfile.";
5310 else if((*irv)->name ==
"nbinSZPHS")
5311 comment =
"Number of range bins for sigmaZeroProfile in each HS scan.";
5312 else if((*irv)->name ==
"nNP")
5313 comment =
"Number of NP kinds.";
5314 else if((*irv)->name ==
"nearFar")
5315 comment =
"Near reference, Far reference.";
5316 else if((*irv)->name ==
"foreBack")
5317 comment =
"Forward, Backward.";
5318 else if((*irv)->name ==
"method")
5319 comment =
"Number of SRT methods.";
5320 else if((*irv)->name ==
"nNode")
5321 comment =
"Number of binNode.";
5322 else if((*irv)->name ==
"nDSD")
5323 comment =
"Number of DSD parameters. Parameters are N0 and D0";
5324 else if((*irv)->name ==
"LS")
5325 comment =
"Liquid, solid.";
5331 Add_Str_Attr(attr,attrname,comment);
5332 (*irv)->attrs.push_back(attr);
5338 if(product_type == GPMS_L3 || product_type == GPMM_L3) {
5339 if ((*irv)->cvartype == CV_NONLATLON_MISS) {
5342 const string attrname =
"comment";
5346 if((*irv)->name ==
"chn")
5347 comment =
"Number of channels:Ku,Ka,KaHS,DPR.";
5348 else if((*irv)->name ==
"inst")
5349 comment =
"Number of instruments:Ku,Ka,KaHS.";
5350 else if((*irv)->name ==
"tim")
5351 comment =
"Number of hours(local time).";
5352 else if((*irv)->name ==
"ang"){
5353 comment =
"Number of angles.The meaning of ang is different for each channel.";
5355 "For Ku channel all indices are used with the meaning 0,1,2,..6 =angle bins 24,";
5357 "(20,28),(16,32),(12,36),(8,40),(3,44),and (0,48).";
5359 "For Ka channel 4 indices are used with the meaning 0,1,2,3 = angle bins 12,(8,16),";
5361 "(4,20),and (0,24). For KaHS channel 4 indices are used with the meaning 0,1,2,3 =";
5362 comment +=
"angle bins(11,2),(7,16),(3,20),and (0.23).";
5365 else if((*irv)->name ==
"rt")
5366 comment =
"Number of rain types: stratiform, convective,all.";
5367 else if((*irv)->name ==
"st")
5368 comment =
"Number of surface types:ocean,land,all.";
5369 else if((*irv)->name ==
"bin"){
5370 comment =
"Number of bins in histogram. The thresholds are different for different";
5371 comment +=
" variables. see the file specification for this algorithm.";
5373 else if((*irv)->name ==
"nvar") {
5374 comment =
"Number of phase bins. Bins are counts of phase less than 100, ";
5375 comment +=
"counts of phase greater than or equal to 100 and less than 200, ";
5376 comment +=
"counts of phase greater than or equal to 200.";
5378 else if((*irv)->name ==
"AD")
5379 comment =
"Ascending or descending half of the orbit.";
5385 Add_Str_Attr(attr,attrname,comment);
5386 (*irv)->attrs.push_back(attr);
5393 if ((*irv)->cvartype == CV_SPECIAL) {
5394 if((*irv)->name ==
"nlayer" || (*irv)->name ==
"hgt" 5395 || (*irv)->name ==
"nalt") {
5397 string unit_value =
"km";
5398 Add_Str_Attr(attr,attr2_new_name,unit_value);
5399 (*irv)->attrs.push_back(attr);
5402 string attr1_axis=
"axis";
5403 string attr1_value =
"Z";
5404 Add_Str_Attr(attr1,attr1_axis,attr1_value);
5405 (*irv)->attrs.push_back(attr1);
5408 string attr2_positive=
"positive";
5409 string attr2_value =
"up";
5410 Add_Str_Attr(attr2,attr2_positive,attr2_value);
5411 (*irv)->attrs.push_back(attr2);
5414 if((*irv)->name ==
"hgt" || (*irv)->name ==
"nalt"){
5416 string comment =
"Number of heights above the earth ellipsoid";
5417 Add_Str_Attr(attr1,
"comment",comment);
5418 (*irv)->attrs.push_back(attr1);
5428 const string fill_value_attr_name =
"_FillValue";
5429 vector<HDF5CF::Var *>::const_iterator it_v;
5430 vector<HDF5CF::Attribute *>::const_iterator ira;
5432 for (it_v =
vars.begin();
5433 it_v !=
vars.end(); ++it_v) {
5435 bool has_fillvalue =
false;
5436 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5437 if (fill_value_attr_name == (*ira)->name){
5438 has_fillvalue =
true;
5445 if (has_fillvalue !=
true ) {
5447 if(H5FLOAT32 == (*it_v)->dtype) {
5449 float _FillValue = -9999.9;
5450 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5451 (*it_v)->attrs.push_back(attr);
5461 GMFile:: Correct_GPM_L1_LatLon_units(
Var *var,
const string unit_value) {
5463 BESDEBUG(
"h5",
"Coming to Correct_GPM_L1_LatLon_units()"<<endl);
5464 const string Unit_name =
"Units";
5465 const string unit_name =
"units";
5467 vector<HDF5CF::Attribute *>::iterator ira;
5470 for(ira = var->attrs.begin(); ira!= var->attrs.end();) {
5471 if(unit_name == (*ira)->name) {
5473 ira = var->attrs.erase(ira);
5475 else if(Unit_name == (*ira)->name) {
5477 ira = var->attrs.erase(ira);
5486 Add_Str_Attr(attr,unit_name,unit_value);
5487 var->attrs.push_back(attr);
5494 GMFile:: Add_Aqu_Attrs() {
5496 BESDEBUG(
"h5",
"Coming to Add_Aqu_Attrs()"<<endl);
5497 vector<HDF5CF::Var *>::const_iterator it_v;
5498 vector<HDF5CF::Attribute *>::const_iterator ira;
5500 const string orig_longname_attr_name =
"Parameter";
5501 const string longname_attr_name =
"long_name";
5502 string longname_value;
5505 const string orig_units_attr_name =
"Units";
5506 const string units_attr_name =
"units";
5509 const string orig_valid_min_attr_name =
"Data Minimum";
5510 const string valid_min_attr_name =
"valid_min";
5511 float valid_min_value = 0;
5513 const string orig_valid_max_attr_name =
"Data Maximum";
5514 const string valid_max_attr_name =
"valid_max";
5515 float valid_max_value = 0;
5520 const string fill_value_attr_name =
"_FillValue";
5521 float _FillValue = -32767.0;
5524 if (orig_longname_attr_name == (*ira)->name) {
5525 Retrieve_H5_Attr_Value(*ira,
"/");
5526 longname_value.resize((*ira)->value.size());
5527 copy((*ira)->value.begin(),(*ira)->value.end(),longname_value.begin());
5530 else if (orig_units_attr_name == (*ira)->name) {
5531 Retrieve_H5_Attr_Value(*ira,
"/");
5532 units_value.resize((*ira)->value.size());
5533 copy((*ira)->value.begin(),(*ira)->value.end(),units_value.begin());
5536 else if (orig_valid_min_attr_name == (*ira)->name) {
5537 Retrieve_H5_Attr_Value(*ira,
"/");
5538 memcpy(&valid_min_value,(
void*)(&((*ira)->value[0])),(*ira)->value.size());
5541 else if (orig_valid_max_attr_name == (*ira)->name) {
5542 Retrieve_H5_Attr_Value(*ira,
"/");
5543 memcpy(&valid_max_value,(
void*)(&((*ira)->value[0])),(*ira)->value.size());
5550 bool has_long_name =
false;
5551 bool has_units =
false;
5552 bool has_valid_min =
false;
5553 bool has_valid_max =
false;
5554 bool has_fillvalue =
false;
5556 for (it_v =
vars.begin();
5557 it_v !=
vars.end(); ++it_v) {
5558 if (
"l3m_data" == (*it_v)->name) {
5559 for (ira = (*it_v)->attrs.begin(); ira != (*it_v)->attrs.end(); ++ira) {
5560 if (longname_attr_name == (*ira)->name)
5561 has_long_name =
true;
5562 else if(units_attr_name == (*ira)->name)
5564 else if(valid_min_attr_name == (*ira)->name)
5565 has_valid_min =
true;
5566 else if(valid_max_attr_name == (*ira)->name)
5567 has_valid_max =
true;
5568 else if(fill_value_attr_name == (*ira)->name)
5569 has_fillvalue =
true;
5577 for (it_v =
vars.begin();
5578 it_v !=
vars.end(); ++it_v) {
5579 if (
"l3m_data" == (*it_v)->name) {
5583 if(
false == has_long_name) {
5585 Add_Str_Attr(attr,longname_attr_name,longname_value);
5586 (*it_v)->attrs.push_back(attr);
5590 if(
false == has_units) {
5592 Add_Str_Attr(attr,units_attr_name,units_value);
5593 (*it_v)->attrs.push_back(attr);
5597 if(
false == has_valid_min) {
5599 Add_One_Float_Attr(attr,valid_min_attr_name,valid_min_value);
5600 (*it_v)->attrs.push_back(attr);
5604 if(
false == has_valid_max) {
5606 Add_One_Float_Attr(attr,valid_max_attr_name,valid_max_value);
5607 (*it_v)->attrs.push_back(attr);
5611 if(
false == has_fillvalue) {
5613 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5614 (*it_v)->attrs.push_back(attr);
5624 GMFile:: Add_SeaWiFS_Attrs() {
5626 BESDEBUG(
"h5",
"Coming to Add_SeaWiFS_Attrs()"<<endl);
5629 const string fill_value_attr_name =
"_FillValue";
5630 float _FillValue = -999.0;
5631 const string valid_range_attr_name =
"valid_range";
5632 vector<HDF5CF::Var *>::const_iterator it_v;
5633 vector<HDF5CF::Attribute *>::const_iterator ira;
5636 for (it_v =
vars.begin();
5637 it_v !=
vars.end(); ++it_v) {
5638 if (H5FLOAT32 == (*it_v)->dtype) {
5639 bool has_fillvalue =
false;
5640 bool has_validrange =
false;
5641 for(ira = (*it_v)->attrs.begin(); ira!= (*it_v)->attrs.end();ira++) {
5642 if (fill_value_attr_name == (*ira)->name){
5643 has_fillvalue =
true;
5647 else if(valid_range_attr_name == (*ira)->name) {
5648 has_validrange =
true;
5654 if (has_fillvalue !=
true && has_validrange !=
true ) {
5656 Add_One_Float_Attr(attr,fill_value_attr_name,_FillValue);
5657 (*it_v)->attrs.push_back(attr);
5668 string co_attrname =
"coordinates";
5669 string co_attrvalue=
"";
5670 string unit_attrname =
"units";
5671 string nonll_unit_attrvalue =
"level";
5672 string lat_unit_attrvalue =
"degrees_north";
5673 string lon_unit_attrvalue =
"degrees_east";
5675 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5676 ircv != this->cvars.end(); ++ircv) {
5679 if ((*ircv)->cvartype == CV_NONLATLON_MISS) {
5681 Add_Str_Attr(attr,unit_attrname,nonll_unit_attrvalue);
5682 (*ircv)->attrs.push_back(attr);
5685 else if ((*ircv)->cvartype == CV_LAT_MISS) {
5690 Add_Str_Attr(attr,unit_attrname,lat_unit_attrvalue);
5691 (*ircv)->attrs.push_back(attr);
5695 else if ((*ircv)->cvartype == CV_LON_MISS) {
5697 Add_Str_Attr(attr,unit_attrname,lon_unit_attrvalue);
5698 (*ircv)->attrs.push_back(attr);
5703 if(product_type == Mea_SeaWiFS_L2)
5707 else if(product_type == GPM_L1) {
5708 Handle_GPM_l1_Coor_Attr();
5712 else if (
true == iscoard) {
5719 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5720 ircv != this->cvars.end(); ++ircv) {
5721 if((*ircv)->rank == 2) {
5724 if(gp_latname == (*ircv)->name)
5725 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5726 else if(gp_lonname ==(*ircv)->name)
5727 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5732 string ll2d_dimname0,ll2d_dimname1;
5733 bool has_ll2d_coords =
false;
5734 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5735 ircv != this->cvars.end(); ++ircv) {
5736 if((*ircv)->rank == 2) {
5738 ll2d_dimname0 = (*ircv)->getDimensions()[0]->name;
5739 ll2d_dimname1 = (*ircv)->getDimensions()[1]->name;
5740 if(ll2d_dimname0 !=
"" && ll2d_dimname1 !=
"")
5741 has_ll2d_coords =
true;
5746 if(
true == has_ll2d_coords) {
5748 for (vector<Var *>::iterator irv = this->
vars.begin();
5749 irv != this->
vars.end(); ++irv) {
5751 bool coor_attr_keep_exist =
false;
5754 if(((*irv)->rank >=2)) {
5756 short ll2dim_flag = 0;
5757 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
5758 ird != (*irv)->dims.end(); ++ ird) {
5759 if((*ird)->name == ll2d_dimname0)
5761 else if((*ird)->name == ll2d_dimname1)
5765 if(ll2dim_flag != 2)
5766 coor_attr_keep_exist =
true;
5769 if(product_type == OSMAPL2S)
5770 coor_attr_keep_exist =
true;
5772 if (
false == coor_attr_keep_exist) {
5773 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
5774 ira !=(*irv)->attrs.end();) {
5775 if ((*ira)->newname == co_attrname) {
5777 ira = (*irv)->attrs.erase(ira);
5785 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
5786 ird != (*irv)->dims.end(); ++ ird) {
5787 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5788 ircv != this->cvars.end(); ++ircv) {
5789 if ((*ird)->name == (*ircv)->cfdimname)
5790 co_attrvalue = (co_attrvalue.empty())
5791 ?(*ircv)->newname:co_attrvalue +
" "+(*ircv)->newname;
5795 if (
false == co_attrvalue.empty()) {
5797 Add_Str_Attr(attr,co_attrname,co_attrvalue);
5798 (*irv)->attrs.push_back(attr);
5801 co_attrvalue.clear();
5813 BESDEBUG(
"h5",
"GMFile::Coming to Handle_Coor_Attr()"<<endl);
5814 string co_attrname =
"coordinates";
5815 string co_attrvalue=
"";
5816 string unit_attrname =
"units";
5817 string nonll_unit_attrvalue =
"level";
5818 string lat_unit_attrvalue =
"degrees_north";
5819 string lon_unit_attrvalue =
"degrees_east";
5823 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5824 ircv != this->cvars.end(); ++ircv) {
5826 if ((*ircv)->cvartype == CV_NONLATLON_MISS) {
5828 Add_Str_Attr(attr,unit_attrname,nonll_unit_attrvalue);
5829 (*ircv)->attrs.push_back(attr);
5831 else if ((*ircv)->cvartype == CV_LAT_MISS) {
5833 Add_Str_Attr(attr,unit_attrname,lat_unit_attrvalue);
5834 (*ircv)->attrs.push_back(attr);
5836 else if ((*ircv)->cvartype == CV_LON_MISS) {
5838 Add_Str_Attr(attr,unit_attrname,lon_unit_attrvalue);
5839 (*ircv)->attrs.push_back(attr);
5844 if(product_type == Mea_SeaWiFS_L2)
5848 else if(product_type == GPM_L1) {
5849 Handle_GPM_l1_Coor_Attr();
5854 else if(product_type == General_Product && gproduct_pattern == GENERAL_LATLON_COOR_ATTR){
5855 Handle_LatLon_With_CoordinateAttr_Coor_Attr();
5859 else if (
true == iscoard) {
5863 if(grp_cv_paths.size() >0) {
5864 for (vector<Var *>::iterator irv = this->
vars.begin();
5865 irv != this->
vars.end(); ++irv) {
5866 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) != grp_cv_paths.end()){
5869 Flatten_VarPath_In_Coordinates_Attr(*irv);
5877 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5878 ircv != this->cvars.end(); ++ircv) {
5880 if((*ircv)->rank == 2 && (*ircv)->cvartype == CV_EXIST) {
5886 if(gp_latname == (*ircv)->name) {
5888 if(
false == Is_geolatlon(gp_latname,
true))
5889 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5891 else if(gp_lonname ==(*ircv)->name) {
5893 if(
false == Is_geolatlon(gp_lonname,
false))
5894 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5900 else if(
true == Is_geolatlon((*ircv)->name,
true))
5901 Replace_Var_Str_Attr((*ircv),unit_attrname,lat_unit_attrvalue);
5903 else if(
true == Is_geolatlon((*ircv)->name,
false))
5904 Replace_Var_Str_Attr((*ircv),unit_attrname,lon_unit_attrvalue);
5910 if(grp_cv_paths.size() >0) {
5911 for (vector<Var *>::iterator irv = this->
vars.begin();
5912 irv != this->
vars.end(); ++irv) {
5913 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) != grp_cv_paths.end()){
5916 Flatten_VarPath_In_Coordinates_Attr(*irv);
5922 bool has_ll2d_coords =
false;
5925 if(General_Product == this->product_type && GENERAL_DIMSCALE == this->gproduct_pattern)
5926 has_ll2d_coords =
true;
5928 string ll2d_dimname0;
5929 string ll2d_dimname1;
5930 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
5931 ircv != this->cvars.end(); ++ircv) {
5932 if((*ircv)->rank == 2) {
5934 ll2d_dimname0 = (*ircv)->getDimensions()[0]->name;
5935 ll2d_dimname1 = (*ircv)->getDimensions()[1]->name;
5936 if(ll2d_dimname0 !=
"" && ll2d_dimname1 !=
"")
5937 has_ll2d_coords =
true;
5944 if(
true == has_ll2d_coords) {
5952 bool force_flatten_coor_attr = HDF5RequestHandler::get_force_flatten_coor_attr();
5956 bool has_coor_attr_ge_2d_vars =
false;
5957 for (vector<Var *>::iterator irv = this->
vars.begin();
5958 irv != this->
vars.end(); ++irv) {
5959 if((*irv)->rank >=2){
5960 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
5962 if((*ira)->name == co_attrname) {
5963 has_coor_attr_ge_2d_vars =
true;
5967 if(has_coor_attr_ge_2d_vars ==
true)
5974 bool is_hybrid_eos5=
false;
5975 if(force_flatten_coor_attr ==
true && has_coor_attr_ge_2d_vars ==
true)
5976 is_hybrid_eos5 = Is_Hybrid_EOS5();
5978 for (vector<Var *>::iterator irv = this->
vars.begin();
5979 irv != this->
vars.end(); ++irv) {
5981 bool has_coor =
false;
5982 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end();++ira) {
5984 if((*ira)->name == co_attrname) {
5991 if(
true == force_flatten_coor_attr &&
true == has_coor) {
5993 if(is_hybrid_eos5 ==
true) {
5994 Flatten_VarPath_In_Coordinates_Attr_EOS5((*irv));
5998 Flatten_VarPath_In_Coordinates_Attr((*irv));
6001 else if(((*irv)->rank >=2) && (has_coor_attr_ge_2d_vars ==
false ||
false == force_flatten_coor_attr)) {
6003 bool coor_attr_keep_exist =
false;
6006 if(grp_cv_paths.find(HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) == grp_cv_paths.end())
6009 coor_attr_keep_exist = Check_Var_2D_CVars(*irv);
6011 coor_attr_keep_exist =
true;
6015 if(product_type == OSMAPL2S)
6016 coor_attr_keep_exist =
true;
6019 if (
false == coor_attr_keep_exist) {
6020 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin();
6021 ira !=(*irv)->attrs.end();) {
6022 if ((*ira)->newname == co_attrname) {
6024 ira = (*irv)->attrs.erase(ira);
6032 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6033 ird != (*irv)->dims.end(); ++ ird) {
6034 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
6035 ircv != this->cvars.end(); ++ircv) {
6036 if ((*ird)->name == (*ircv)->cfdimname)
6037 co_attrvalue = (co_attrvalue.empty())
6038 ?(*ircv)->newname:co_attrvalue +
" "+(*ircv)->newname;
6042 if (
false == co_attrvalue.empty()) {
6044 Add_Str_Attr(attr,co_attrname,co_attrvalue);
6045 (*irv)->attrs.push_back(attr);
6048 co_attrvalue.clear();
6056 void GMFile:: Handle_GPM_l1_Coor_Attr() {
6058 BESDEBUG(
"h5",
"Coming to Handle_GPM_l1_Coor_Attr()"<<endl);
6072 string co_attrname =
"coordinates";
6073 string co_attrvalue=
"";
6076 set<string> cvar_2d_dimset;
6078 pair<map<string,string>::iterator,
bool>mapret;
6081 map<string,string>cfdimname_to_cvar2dname;
6084 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
6085 irv != this->cvars.end(); ++irv) {
6088 if((*irv)->rank == 2) {
6094 for(vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6095 ird != (*irv)->dims.end(); ++ird) {
6096 cvar_2d_dimset.insert((*ird)->name);
6100 mapret = cfdimname_to_cvar2dname.insert(pair<string,string>((*irv)->cfdimname,(*irv)->newname));
6101 if (
false == mapret.second)
6102 throw4(
"The cf dimension name ",(*irv)->cfdimname,
" should map to 2-D coordinate variable",
6108 for (vector<Var *>::iterator irv = this->
vars.begin();
6109 irv != this->
vars.end(); ++irv) {
6112 if((*irv)->rank >=2) {
6116 short have_2d_dimnames_flag = 0;
6117 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6118 ird !=(*irv)->dims.end();++ird) {
6119 if (cvar_2d_dimset.find((*ird)->name)!=cvar_2d_dimset.end())
6120 have_2d_dimnames_flag++;
6124 if(have_2d_dimnames_flag >=2) {
6128 if((*irv)->fullpath.size() > (*irv)->name.size())
6129 var_path=(*irv)->fullpath.substr(0,(*irv)->fullpath.size()-(*irv)->name.size());
6131 throw4(
"The variable full path ",(*irv)->fullpath,
" doesn't contain the variable name ",
6135 short cv_2d_flag = 0;
6138 vector<string> cv_2d_names;
6141 set<string> cv_2d_dimnames;
6144 for(map<string,string>::const_iterator itm = cfdimname_to_cvar2dname.begin();
6145 itm != cfdimname_to_cvar2dname.end();++itm) {
6148 string reduced_dimname = HDF5CFUtil::obtain_string_after_lastslash(itm->first);
6150 if(itm->first.size() <= reduced_dimname.size())
6151 throw2(
"The cf dim. name of this dimension is not right.",itm->first);
6153 cfdim_path= itm->first.substr(0,itm->first.size() - reduced_dimname.size());
6162 if(var_path == cfdim_path) {
6163 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6164 ird!=(*irv)->dims.end();++ird) {
6165 if(reduced_dimname == (*ird)->name) {
6167 cv_2d_names.push_back(itm->second);
6168 cv_2d_dimnames.insert((*ird)->name);
6180 if(cv_2d_flag != 2) {
6183 for(map<string,string>::const_iterator itm = cfdimname_to_cvar2dname.begin();
6184 itm != cfdimname_to_cvar2dname.end();++itm) {
6186 string reduced_dimname = HDF5CFUtil::obtain_string_after_lastslash(itm->first);
6188 if(itm->first.size() <= reduced_dimname.size())
6189 throw2(
"The cf dim. name of this dimension is not right.",itm->first);
6191 cfdim_path= itm->first.substr(0,itm->first.size() - reduced_dimname.size());
6200 if(var_path.find(cfdim_path)!=string::npos) {
6201 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6202 ird!=(*irv)->dims.end();++ird) {
6203 if(reduced_dimname == (*ird)->name) {
6205 cv_2d_names.push_back(itm->second);
6206 cv_2d_dimnames.insert((*ird)->name);
6215 if(2 == cv_2d_flag) {
6218 co_attrvalue = cv_2d_names[0] +
" " + cv_2d_names[1];
6219 if((*irv)->rank >2) {
6220 for (vector<Dimension *>::iterator ird = (*irv)->dims.begin();
6221 ird !=(*irv)->dims.end();++ird) {
6224 if(cv_2d_dimnames.find((*ird)->name) == cv_2d_dimnames.end())
6225 co_attrvalue = co_attrvalue +
" " +(*ird)->newname;
6229 Add_Str_Attr(attr,co_attrname,co_attrvalue);
6230 (*irv)->attrs.push_back(attr);
6238 void GMFile::Handle_LatLon_With_CoordinateAttr_Coor_Attr() {
6240 BESDEBUG(
"h5",
"Coming to Handle_LatLon_With_CoordinateAttr_Coor_Attr()"<<endl);
6241 string co_attrname =
"coordinates";
6244 for (vector<Var *>::iterator irv = this->
vars.begin();
6245 irv != this->
vars.end(); ++irv) {
6246 if((*irv)->rank >= 2) {
6247 for (vector<Attribute *>:: iterator ira =(*irv)->attrs.begin(); ira !=(*irv)->attrs.end(); ++ira) {
6248 if((*ira)->name == co_attrname) {
6251 string coor_value = Retrieve_Str_Attr_Value(*ira,(*irv)->fullpath);
6252 if(Coord_Match_LatLon_NameSize(coor_value) ==
true)
6253 Flatten_VarPath_In_Coordinates_Attr(*irv);
6257 else if(Coord_Match_LatLon_NameSize_Same_Group(coor_value,HDF5CFUtil::obtain_string_before_lastslash((*irv)->fullpath)) ==
true)
6258 Add_VarPath_In_Coordinates_Attr(*irv,coor_value);
6270 bool GMFile::Coord_Match_LatLon_NameSize(
const string & coord_values) {
6272 BESDEBUG(
"h5",
"Coming to Coord_Match_LatLon_NameSize()"<<endl);
6273 bool ret_value =
false;
6274 vector<string> coord_values_vec;
6276 int match_lat_name_pair_index = -1;
6277 int match_lon_name_pair_index = -2;
6278 int num_match_lat = 0;
6279 int num_match_lon = 0;
6283 HDF5CFUtil::Split_helper(coord_values_vec,coord_values,sep);
6286 if((coord_values_vec[0])[0] !=
'/') {
6287 for(vector<string>::iterator irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6288 if(((*irs).find_first_of(
'/'))!=string::npos) {
6289 *irs =
'/' + (*irs);
6295 for(vector<string>::iterator irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6299 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
6300 if((*irs) == (*ivs).name1){
6301 match_lat_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6304 else if ((*irs) == (*ivs).name2) {
6305 match_lon_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6311 if((match_lat_name_pair_index == match_lon_name_pair_index) && (num_match_lat ==1) && (num_match_lon ==1))
6320 bool GMFile::Coord_Match_LatLon_NameSize_Same_Group(
const string &coord_values,
const string &var_path) {
6322 BESDEBUG(
"h5",
"Coming to Coord_Match_LatLon_NameSize_Same_Group()"<<endl);
6323 bool ret_value =
false;
6324 vector<string> coord_values_vec;
6326 int match_lat_name_pair_index = -1;
6327 int match_lon_name_pair_index = -2;
6328 int num_match_lat = 0;
6329 int num_match_lon = 0;
6331 HDF5CFUtil::Split_helper(coord_values_vec,coord_values,sep);
6334 for(vector<string>::iterator irs=coord_values_vec.begin();irs!=coord_values_vec.end();++irs){
6336 for(vector<struct Name_Size_2Pairs>::iterator ivs=latloncv_candidate_pairs.begin(); ivs!=latloncv_candidate_pairs.end();++ivs) {
6337 string lat_name = HDF5CFUtil::obtain_string_after_lastslash((*ivs).name1);
6338 string lat_path = HDF5CFUtil::obtain_string_before_lastslash((*ivs).name1);
6339 string lon_name = HDF5CFUtil::obtain_string_after_lastslash((*ivs).name2);
6340 string lon_path = HDF5CFUtil::obtain_string_before_lastslash((*ivs).name2);
6341 if((*irs) == lat_name && lat_path == var_path){
6342 match_lat_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6345 else if ((*irs) == lon_name && lon_path == var_path) {
6346 match_lon_name_pair_index = distance(latloncv_candidate_pairs.begin(),ivs);
6352 if((match_lat_name_pair_index == match_lon_name_pair_index) && (num_match_lat ==1) && (num_match_lon ==1))
6359 void GMFile::Add_VarPath_In_Coordinates_Attr(
Var *var,
const string &coor_value) {
6361 BESDEBUG(
"h5",
"Coming to Add_VarPath_In_Coordinates_Attr()"<<endl);
6362 string new_coor_value;
6364 string var_path = HDF5CFUtil::obtain_string_before_lastslash(var->fullpath) ;
6365 string var_flatten_path = get_CF_string(var_path);
6368 size_t ele_start_pos = 0;
6369 size_t cur_pos = coor_value.find_first_of(sep);
6370 while(cur_pos !=string::npos) {
6371 string tempstr = coor_value.substr(ele_start_pos,cur_pos-ele_start_pos);
6372 tempstr = var_flatten_path + tempstr;
6373 new_coor_value += tempstr + sep;
6374 ele_start_pos = cur_pos+1;
6375 cur_pos = coor_value.find_first_of(sep,cur_pos+1);
6378 if(ele_start_pos == 0)
6379 new_coor_value = var_flatten_path + coor_value;
6381 new_coor_value += var_flatten_path + coor_value.substr(ele_start_pos);
6383 string coor_attr_name =
"coordinates";
6384 Replace_Var_Str_Attr(var,coor_attr_name,new_coor_value);
6389 void GMFile:: Create_Missing_CV(
GMCVar *GMcvar,
const string& dimname) {
6391 BESDEBUG(
"h5",
"GMFile::Coming to Create_Missing_CV()"<<endl);
6393 GMcvar->name = dimname;
6394 GMcvar->newname = GMcvar->name;
6395 GMcvar->fullpath = GMcvar->name;
6397 GMcvar->dtype = H5INT32;
6398 hsize_t gmcvar_dimsize = dimname_to_dimsize[dimname];
6399 bool unlimited_flag = dimname_to_unlimited[dimname];
6401 gmcvar_dim->unlimited_dim = unlimited_flag;
6402 gmcvar_dim->name = dimname;
6403 gmcvar_dim->newname = dimname;
6404 GMcvar->dims.push_back(gmcvar_dim);
6405 GMcvar->cfdimname = dimname;
6406 GMcvar->cvartype = CV_NONLATLON_MISS;
6407 GMcvar->product_type = product_type;
6412 bool GMFile::Is_netCDF_Dimension(
Var *var) {
6414 string netcdf_dim_mark =
"This is a netCDF dimension but not a netCDF variable";
6416 bool is_only_dimension =
false;
6418 for(vector<Attribute *>::iterator ira = var->attrs.begin();
6419 ira != var->attrs.end();ira++) {
6421 if (
"NAME" == (*ira)->name) {
6423 Retrieve_H5_Attr_Value(*ira,var->fullpath);
6425 name_value.resize((*ira)->value.size());
6426 copy((*ira)->value.begin(),(*ira)->value.end(),name_value.begin());
6429 if (0 == name_value.compare(0,netcdf_dim_mark.size(),netcdf_dim_mark))
6430 is_only_dimension =
true;
6436 return is_only_dimension;
6446 GMFile::Is_Hybrid_EOS5() {
6448 bool has_group_hdfeos =
false;
6449 bool has_group_hdfeos_info =
false;
6455 for (vector<Group *>::iterator irg = this->
groups.begin();
6456 irg != this->
groups.end(); ++ irg) {
6457 if (
"/HDFEOS" == (*irg)->path)
6458 has_group_hdfeos =
true;
6459 else if(
"/HDFEOS INFORMATION" == (*irg)->path) {
6460 for(vector<Attribute *>::iterator ira = (*irg)->attrs.begin();
6461 ira != (*irg)->attrs.end();ira++) {
6462 if(
"HDFEOSVersion" == (*ira)->name)
6463 has_group_hdfeos_info =
true;
6466 if(
true == has_group_hdfeos &&
true == has_group_hdfeos_info)
6471 if(
true == has_group_hdfeos &&
true == has_group_hdfeos_info)
6477 void GMFile::Handle_Hybrid_EOS5() {
6479 string eos_str=
"HDFEOS_";
6480 string eos_info_str=
"HDFEOS_INFORMATION_";
6481 string grid_str=
"GRIDS_";
6482 string swath_str=
"SWATHS_";
6483 string zas_str=
"ZAS_";
6484 string df_str=
"Data_Fields_";
6485 string gf_str=
"Geolocation_Fields_";
6486 for (vector<Var *>::iterator irv = this->
vars.begin();
6487 irv != this->
vars.end(); irv++) {
6488 string temp_var_name = (*irv)->newname;
6490 bool remove_eos = Remove_EOS5_Strings(temp_var_name);
6492 if(
true == remove_eos)
6493 (*irv)->newname = get_CF_string(temp_var_name);
6495 string::size_type eos_info_pos = temp_var_name.find(eos_info_str);
6496 if(eos_info_pos !=string::npos)
6497 (*irv)->newname = temp_var_name.erase(eos_info_pos,eos_info_str.size());
6499 if(Remove_EOS5_Strings_NonEOS_Fields(temp_var_name)==
true)
6500 (*irv)->newname = get_CF_string(temp_var_name);
6506 for (vector<Var *>::iterator irv = this->
vars.begin();
6507 irv != this->
vars.end(); irv++) {
6508 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6509 ird!=(*irv)->dims.end(); ++ird) {
6510 string temp_dim_name = (*ird)->newname;
6511 bool remove_eos = Remove_EOS5_Strings(temp_dim_name);
6513 if(
true == remove_eos)
6514 (*ird)->newname = get_CF_string(temp_dim_name);
6516 string::size_type eos_info_pos = temp_dim_name.find(eos_info_str);
6517 if(eos_info_pos !=string::npos)
6518 (*ird)->newname = temp_dim_name.erase(eos_info_pos,eos_info_str.size());
6520 if(Remove_EOS5_Strings_NonEOS_Fields(temp_dim_name)==
true)
6521 (*ird)->newname = get_CF_string(temp_dim_name);
6528 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
6529 irv != this->cvars.end(); ++irv) {
6530 string temp_var_name = (*irv)->newname;
6532 bool remove_eos = Remove_EOS5_Strings(temp_var_name);
6534 if(
true == remove_eos)
6535 (*irv)->newname = get_CF_string(temp_var_name);
6537 string::size_type eos_info_pos = temp_var_name.find(eos_info_str);
6538 if(eos_info_pos !=string::npos)
6539 (*irv)->newname = temp_var_name.erase(eos_info_pos,eos_info_str.size());
6541 if(Remove_EOS5_Strings_NonEOS_Fields(temp_var_name)==
true)
6542 (*irv)->newname = get_CF_string(temp_var_name);
6547 for (vector<GMCVar *>::iterator irv = this->cvars.begin();
6548 irv != this->cvars.end(); irv++) {
6549 for (vector<Dimension*>::iterator ird = (*irv)->dims.begin();
6550 ird!=(*irv)->dims.end(); ++ird) {
6551 string temp_dim_name = (*ird)->newname;
6552 bool remove_eos = Remove_EOS5_Strings(temp_dim_name);
6554 if(
true == remove_eos)
6555 (*ird)->newname = get_CF_string(temp_dim_name);
6557 string::size_type eos_info_pos = temp_dim_name.find(eos_info_str);
6558 if(eos_info_pos !=string::npos)
6559 (*ird)->newname = temp_dim_name.erase(eos_info_pos,eos_info_str.size());
6561 if(Remove_EOS5_Strings_NonEOS_Fields(temp_dim_name)==
true)
6562 (*ird)->newname = get_CF_string(temp_dim_name);
6571 for (vector<Var *>::iterator irv = this->
vars.begin();
6572 irv != this->
vars.end(); irv++) {
6573 for(vector<Attribute *>::iterator ira = (*irv)->attrs.begin();
6574 ira != (*irv)->attrs.end();ira++) {
6577 if((*ira)->name ==
"coordinates") {
6578 string cor_values((*ira)->value.begin(),(*ira)->value.end()) ;
6579 bool change_cor_values =
false;
6581 if(cor_values.find(eos_str)==0) {
6582 if(cor_values.find(grid_str)!=string::npos) {
6583 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6584 cor_values = HDF5CFUtil::remove_substrings(cor_values,grid_str);
6585 string new_cor_values = HDF5CFUtil::remove_substrings(cor_values,df_str);
6586 if(new_cor_values.size() < cor_values.size()){
6587 change_cor_values =
true;
6588 cor_values = new_cor_values;
6591 else if(cor_values.find(zas_str)!=string::npos) {
6592 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6593 cor_values = HDF5CFUtil::remove_substrings(cor_values,zas_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(swath_str)!=string::npos) {
6601 cor_values = HDF5CFUtil::remove_substrings(cor_values,eos_str);
6602 cor_values = HDF5CFUtil::remove_substrings(cor_values,swath_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 new_cor_values = HDF5CFUtil::remove_substrings(cor_values,gf_str);
6610 if(new_cor_values.size() < cor_values.size()){
6611 change_cor_values =
true;
6612 cor_values = new_cor_values;
6617 if(
true == change_cor_values) {
6618 (*ira)->value.resize(cor_values.size());
6619 (*ira)->fstrsize=cor_values.size();
6620 (*ira)->strsize[0] = cor_values.size();
6621 copy(cor_values.begin(), cor_values.end(), (*ira)->value.begin());
6632 bool GMFile:: Remove_EOS5_Strings(
string &var_name) {
6634 string eos_str=
"HDFEOS_";
6635 string grid_str=
"GRIDS_";
6636 string swath_str=
"SWATHS_";
6637 string zas_str=
"ZAS_";
6638 string df_str=
"Data_Fields_";
6639 string gf_str=
"Geolocation_Fields_";
6640 string temp_var_name = var_name;
6642 bool remove_eos =
false;
6644 string::size_type eos_pos = temp_var_name.find(eos_str);
6645 if(eos_pos!=string::npos) {
6646 temp_var_name.erase(eos_pos,eos_str.size());
6648 string::size_type grid_pos=temp_var_name.find(grid_str);
6649 string::size_type grid_df_pos=string::npos;
6650 if(grid_pos!=string::npos)
6651 grid_df_pos = temp_var_name.find(df_str,grid_pos);
6652 string::size_type zas_pos = string::npos;
6653 string::size_type zas_df_pos=string::npos;
6654 if(grid_pos==string::npos || grid_df_pos ==string::npos)
6655 zas_pos=temp_var_name.find(zas_str);
6656 if(zas_pos!=string::npos)
6657 zas_df_pos=temp_var_name.find(df_str,zas_pos);
6659 if(grid_pos !=string::npos && grid_df_pos!=string::npos) {
6660 temp_var_name.erase(grid_pos,grid_str.size());
6661 grid_df_pos = temp_var_name.find(df_str);
6662 temp_var_name.erase(grid_df_pos,df_str.size());
6665 else if(zas_pos!=string::npos && zas_df_pos!=string::npos){
6666 temp_var_name.erase(zas_pos,zas_str.size());
6667 zas_df_pos = temp_var_name.find(df_str);
6668 temp_var_name.erase(zas_df_pos,df_str.size());
6673 string::size_type swath_pos=temp_var_name.find(swath_str);
6674 string::size_type swath_df_pos=string::npos;
6675 if(swath_pos!=string::npos)
6676 swath_df_pos=temp_var_name.find(df_str,swath_pos);
6678 string::size_type swath_gf_pos=string::npos;
6679 if(swath_pos!=string::npos && swath_df_pos == string::npos)
6680 swath_gf_pos=temp_var_name.find(gf_str,swath_pos);
6682 if(swath_pos !=string::npos) {
6684 if(swath_df_pos!=string::npos) {
6685 temp_var_name.erase(swath_pos,swath_str.size());
6686 swath_df_pos = temp_var_name.find(df_str);
6687 temp_var_name.erase(swath_df_pos,df_str.size());
6690 else if(swath_gf_pos!=string::npos) {
6691 temp_var_name.erase(swath_pos,swath_str.size());
6692 swath_gf_pos = temp_var_name.find(gf_str);
6693 temp_var_name.erase(swath_gf_pos,gf_str.size());
6699 if(
true == remove_eos)
6700 var_name = temp_var_name;
6705 bool GMFile:: Remove_EOS5_Strings_NonEOS_Fields(
string &var_name) {
6707 string eos_str=
"HDFEOS_";
6708 string grid_str=
"GRIDS_";
6709 string swath_str=
"SWATHS_";
6710 string zas_str=
"ZAS_";
6711 string temp_var_name = var_name;
6713 bool remove_eos =
false;
6715 string::size_type eos_pos = temp_var_name.find(eos_str);
6716 if(eos_pos!=string::npos) {
6717 temp_var_name.erase(eos_pos,eos_str.size());
6721 if(temp_var_name.find(grid_str)==0)
6722 temp_var_name.erase(0,grid_str.size());
6723 else if(temp_var_name.find(swath_str)==0)
6724 temp_var_name.erase(0,swath_str.size());
6725 else if(temp_var_name.find(zas_str)==0)
6726 temp_var_name.erase(0,zas_str.size());
6728 if(
true == remove_eos)
6729 var_name = temp_var_name;
6750 if(this->unsupported_var_dtype ==
true) {
6753 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
6754 ircv != this->cvars.end();) {
6755 if((*ircv)->newname.find(
"FakeDim")==0) {
6756 bool var_has_fakedim =
false;
6757 for (vector<Var*>::iterator irv2 = this->
vars.begin();
6758 irv2 != this->
vars.end(); irv2++) {
6759 for (vector<Dimension *>::iterator ird = (*irv2)->dims.begin();
6760 ird !=(*irv2)->dims.end(); ird++) {
6761 if((*ird)->newname == (*ircv)->newname){
6762 var_has_fakedim =
true;
6766 if(var_has_fakedim ==
true)
6769 if(var_has_fakedim ==
false) {
6772 ircv = this->cvars.erase(ircv);
6794 if(
true == this->have_nc4_non_coord) {
6795 string nc4_non_coord=
"_nc4_non_coord_";
6796 size_t nc4_non_coord_size= nc4_non_coord.size();
6797 for (vector<Var*>::iterator irv = this->
vars.begin();
6798 irv != this->
vars.end(); irv++) {
6799 if((*irv)->name.find(nc4_non_coord)==0)
6800 (*irv)->newname = (*irv)->newname.substr(nc4_non_coord_size,(*irv)->newname.size()-nc4_non_coord_size);
6803 for (vector<GMCVar *>::iterator ircv = this->cvars.begin();
6804 ircv != this->cvars.end();++ircv) {
6805 if((*ircv)->name.find(nc4_non_coord)==0)
6806 (*ircv)->newname = (*ircv)->newname.substr(nc4_non_coord_size,(*ircv)->newname.size()-nc4_non_coord_size);
6814 GMFile::release_standalone_GMCVar_vector(vector<GMCVar*>&tempgc_vars){
6816 for (vector<GMCVar *>::iterator i = tempgc_vars.begin();
6817 i != tempgc_vars.end(); ) {
6819 i = tempgc_vars.erase(i);
6826 GMFile::add_ignored_info_attrs(
bool is_grp,
bool is_first){
6830 GMFile::add_ignored_info_objs(
bool is_dim_related,
bool is_first) {
6837 GMFile::ignored_dimscale_ref_list(
Var *var) {
6839 bool ignored_dimscale =
true;
6840 if(General_Product == this->product_type && GENERAL_DIMSCALE== this->gproduct_pattern) {
6842 bool has_dimscale =
false;
6843 bool has_reference_list =
false;
6844 for(vector<Attribute *>::iterator ira = var->attrs.begin();
6845 ira != var->attrs.end();ira++) {
6846 if((*ira)->name ==
"REFERENCE_LIST" &&
6847 false == HDF5CFUtil::cf_strict_support_type((*ira)->getType()))
6848 has_reference_list =
true;
6849 if((*ira)->name ==
"CLASS") {
6850 Retrieve_H5_Attr_Value(*ira,var->fullpath);
6852 class_value.resize((*ira)->value.size());
6853 copy((*ira)->value.begin(),(*ira)->value.end(),class_value.begin());
6857 if (0 == class_value.compare(0,15,
"DIMENSION_SCALE")) {
6858 has_dimscale =
true;
6862 if(
true == has_dimscale &&
true == has_reference_list) {
6863 ignored_dimscale=
false;
6869 return ignored_dimscale;
void Adjust_H5_Attr_Value(Attribute *attr)
Adjust attribute values for general HDF5 products.
void Flatten_Obj_Name(bool include_attr)
Flatten the object name for general NASA HDF5 products.
virtual void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for datasets.
void Handle_SpVar()
Handle special variables for general NASA HDF5 products.
This class represents one HDF5 dataset(CF variable)
void Handle_Coor_Attr()
Handle "coordinates" attributes for general HDF5 products.
void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for general HDF5 products.
void Handle_CVar()
Handle coordinate variables for general NASA HDF5 products.
void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
void Handle_DimNameClashing()
std::vector< Attribute * > root_attrs
Root attribute vectors.
void Add_Dim_Name()
Add dimension name.
virtual void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
#define throw1(a1)
The followings are convenient functions to throw exceptions with different.
void Handle_Obj_NameClashing(bool)
Handle object name clashing 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 is a derived class of CVar. It represents a coordinate variable for general HDF5 files.
virtual void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes.
std::vector< Var * > vars
Var vectors.
void Handle_SpVar_Attr()
Handle special variable attributes for general NASA HDF5 products.
void Remove_Unused_FakeDimVars()
Unsupported datatype array may generate FakeDim. Remove them.
void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for general HDF5 products.
virtual void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes.
virtual void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name.
This class retrieves all information from an HDF5 file.
virtual void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes.
bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
void Adjust_Dim_Name()
Adjust dimension name for general NASA HDF5 products.
include the entry functions to execute the handlers
void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for general HDF5 products.
const std::vector< Dimension * > & getDimensions() const
Get the list of the dimensions.
void Remove_Unneeded_Objects()
Remove unneeded objects.
virtual void Retrieve_H5_Info(const char *path, hid_t file_id, bool)
void Update_Product_Type()
Update "product type" attributes for general HDF5 products.
This class represents one attribute.
static void Split(const char *s, int len, char sep, std::vector< std::string > &names)
void Adjust_Obj_Name()
Adjust object names based on different general NASA HDF5 products.
This class repersents one dimension of an HDF5 dataset(variable).
virtual bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
std::vector< Group * > groups
Non-root group vectors.
void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
virtual void Flatten_Obj_Name(bool)
Flatten the object name.
void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
This class specifies the core engineering of mapping HDF5 to DAP by following CF.
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.