37#include <libdap/InternalErr.h>
62using namespace HDF5CF;
65void map_gmh5_cfdds(DDS &dds, hid_t file_id,
const string& filename){
67 BESDEBUG(
"h5",
"Coming to GM products DDS mapping function map_gmh5_cfdds() "<<endl);
69 H5GCFProduct product_type = check_product(file_id);
71 GMPattern gproduct_pattern = OTHERGMS;
74 auto f_unique = make_unique<GMFile>(filename.c_str(),file_id,product_type,gproduct_pattern);
75 auto f = f_unique.get();
78 bool include_attr =
false;
81 f->Retrieve_H5_Info(filename.c_str(),file_id,include_attr);
89 f->Update_Product_Type();
91 f->Remove_Unneeded_Objects();
112 if ((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
113 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr)){
116 f->Handle_Unsupported_Dtype(
true);
119 f->Handle_Unsupported_Dspace(
true);
122 f->Retrieve_H5_CVar_Supported_Attr_Values();
128 f->Handle_Unsupported_Dtype(include_attr);
131 f->Handle_Unsupported_Dspace(include_attr);
136 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
137 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
138 f->Add_Supplement_Attrs(HDF5RequestHandler::get_add_path_attrs());
141 f->Adjust_Obj_Name();
144 f->Flatten_Obj_Name(include_attr);
149 if(General_Product == product_type ||
150 true == HDF5RequestHandler::get_check_name_clashing())
151 f->Handle_Obj_NameClashing(include_attr);
154 f->Adjust_Dim_Name();
155 if(General_Product == product_type ||
156 true == HDF5RequestHandler::get_check_name_clashing())
157 f->Handle_DimNameClashing();
159 f->Handle_Hybrid_EOS5();
160 if(
true == f->Have_Grid_Mapping_Attrs())
161 f->Handle_Grid_Mapping_Vars();
163 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
164 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
165 f->Handle_Coor_Attr();
167 f->Remove_Unused_FakeDimVars();
168 f->Rename_NC4_NonCoordVars();
170 if (f->HaveUnlimitedDim())
171 f->Update_NC4_PureDimSize();
175 throw InternalErr(e.what());
180 gen_gmh5_cfdds(dds,f);
189void map_gmh5_cfdas(DAS &das, hid_t file_id,
const string& filename){
191 BESDEBUG(
"h5",
"Coming to GM products DAS mapping function map_gmh5_cfdas() "<<endl);
193 H5GCFProduct product_type = check_product(file_id);
194 GMPattern gproduct_pattern = OTHERGMS;
196 auto f_unique = make_unique<GMFile>(filename.c_str(),file_id,product_type,gproduct_pattern);
197 auto f = f_unique.get();
199 bool include_attr =
true;
201 f->Retrieve_H5_Info(filename.c_str(),file_id,include_attr);
204 f->Update_Product_Type();
206 f->Remove_Unneeded_Objects();
211 f->Handle_Unsupported_Dtype(include_attr);
214 f->Handle_Unsupported_Dspace(include_attr);
217 f->Retrieve_H5_Supported_Attr_Values();
224 f->Handle_Unsupported_Others(include_attr);
230 f->Add_Supplement_Attrs(HDF5RequestHandler::get_add_path_attrs());
231 f->Adjust_Obj_Name();
232 f->Flatten_Obj_Name(include_attr);
233 if(General_Product == product_type ||
234 true == HDF5RequestHandler::get_check_name_clashing())
235 f->Handle_Obj_NameClashing(include_attr);
236 if(f->HaveUnlimitedDim() ==
true)
237 f->Adjust_Dim_Name();
239 if (f->is_special_gpm_l3()==
false)
240 f->Handle_Coor_Attr();
242 f->Handle_Hybrid_EOS5();
243 if(
true == f->Have_Grid_Mapping_Attrs())
244 f->Handle_Grid_Mapping_Vars();
246 f->Remove_Unused_FakeDimVars();
248 f->Rename_NC4_NonCoordVars();
250 if(
true == HDF5RequestHandler::get_enable_coord_attr_add_path() && f->is_special_gpm_l3()==
false)
251 f->Add_Path_Coord_Attr();
253 f->Update_Bounds_Attr();
256 throw InternalErr(e.what());
261 gen_gmh5_cfdas(das,f);
270void map_gmh5_cfdmr(D4Group *d4_root, hid_t file_id,
const string& filename){
272 BESDEBUG(
"h5",
"Coming to GM products DMR mapping function map_gmh5_cfdmr() "<<endl);
274 H5GCFProduct product_type = check_product(file_id);
276 GMPattern gproduct_pattern = OTHERGMS;
278 auto f_unique = make_unique<GMFile>(filename.c_str(),file_id,product_type,gproduct_pattern);
279 auto f = f_unique.get();
282 bool include_attr =
true;
289 f->Retrieve_H5_Info(filename.c_str(),file_id,include_attr);
297 f->Update_Product_Type();
299 f->Remove_Unneeded_Objects();
318 f->Handle_Unsupported_Dtype(
true);
321 f->Handle_Unsupported_Dspace(
true);
324 f->Retrieve_H5_Supported_Attr_Values();
327 f->Handle_Unsupported_Others(include_attr);
330 f->Add_Supplement_Attrs(HDF5RequestHandler::get_add_path_attrs());
333 f->Adjust_Obj_Name();
336 f->Flatten_Obj_Name(include_attr);
341 if (General_Product == product_type ||
342 true == HDF5RequestHandler::get_check_name_clashing())
343 f->Handle_Obj_NameClashing(include_attr);
346 f->Adjust_Dim_Name();
347 if (General_Product == product_type ||
348 true == HDF5RequestHandler::get_check_name_clashing())
349 f->Handle_DimNameClashing();
352 f->Handle_Coor_Attr();
354 f->Handle_Hybrid_EOS5();
355 if(
true == f->Have_Grid_Mapping_Attrs())
356 f->Handle_Grid_Mapping_Vars();
359 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
360 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
361 f->Handle_Coor_Attr();
364 f->Remove_Unused_FakeDimVars();
365 f->Rename_NC4_NonCoordVars();
367 if(
true == HDF5RequestHandler::get_enable_coord_attr_add_path())
368 f->Add_Path_Coord_Attr();
370 f->Update_Bounds_Attr();
372 if (f->HaveUnlimitedDim())
373 f->Update_NC4_PureDimSize();
377 throw InternalErr(e.what());
382 gen_gmh5_cfdmr(d4_root,f);
391void gen_gmh5_cfdds( DDS & dds, HDF5CF:: GMFile *f) {
393 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdds() "<<endl);
395 const vector<HDF5CF::Var *>& vars = f->getVars();
396 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
397 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
398 const string filename = f->getPath();
399 const hid_t fileid = f->getFileID();
404 bool dmr_64bit_support =
false;
405 if (HDF5RequestHandler::get_dmr_long_int()==
true &&
406 HDF5RequestHandler::get_dmr_64bit_int()!=
nullptr) {
407 for (
const auto &var:vars) {
408 if (H5INT64 == var->getType() || H5UINT64 == var->getType()){
409 dmr_64bit_support =
true;
416 if(
true == dmr_64bit_support) {
418 f->Handle_Unsupported_Dtype(
true);
421 f->Handle_Unsupported_Dspace(
true);
425 for (
auto &var:vars) {
426 BESDEBUG(
"h5",
"variable full path= "<< var->getFullPath() <<endl);
428 if(need_attr_values_for_dap4(var) ==
true)
429 f->Retrieve_H5_Var_Attr_Values(var);
430 gen_dap_onevar_dds(dds,var,fileid, filename);
432 for (
const auto &cvar:cvars) {
433 BESDEBUG(
"h5",
"variable full path= "<< cvar->getFullPath() <<endl);
434 gen_dap_onegmcvar_dds(dds,cvar,fileid, filename);
437 for (
const auto &spvar:spvars) {
438 BESDEBUG(
"h5",
"variable full path= "<< spvar->getFullPath() <<endl);
439 gen_dap_onegmspvar_dds(dds,spvar,fileid, filename);
445void gen_gmh5_cfdas( DAS & das, HDF5CF:: GMFile *f) {
447 BESDEBUG(
"h5",
"Coming to GM DAS generation function gen_gmh5_cfdas() "<<endl);
450 if(
true == f->Get_IgnoredInfo_Flag()) {
451 gen_gmh5_cf_ignored_obj_info(das, f);
455 const vector<HDF5CF::Var *>& vars = f->getVars();
456 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
457 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
458 const vector<HDF5CF::Group *>& grps = f->getGroups();
459 const vector<HDF5CF::Attribute *>& root_attrs = f->getAttributes();
465 if (
false == root_attrs.empty()) {
467 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
469 at = das.add_table(FILE_ATTR_TABLE_NAME, obtain_new_attr_table());
471 for (
const auto &root_attr:root_attrs) {
473 check_update_int64_attr(
"",root_attr);
474 gen_dap_oneobj_das(at,root_attr,
nullptr);
478 if (
false == grps.empty()) {
479 for (
const auto &grp:grps) {
480 AttrTable *at = das.get_table(grp->getNewName());
482 at = das.add_table(grp->getNewName(), obtain_new_attr_table());
484 for (
const auto &grp_attr:grp->getAttributes()) {
485 check_update_int64_attr(grp->getNewName(),grp_attr);
486 gen_dap_oneobj_das(at,grp_attr,
nullptr);
491 for (
const auto &var:vars) {
493 if (
false == (var->getAttributes().empty())) {
499 if(H5INT64 == var->getType() || H5UINT64 == var->getType()){
503 AttrTable *at = das.get_table(var->getNewName());
505 at = das.add_table(var->getNewName(), obtain_new_attr_table());
507 for (
const auto &attr:var->getAttributes())
508 gen_dap_oneobj_das(at,attr,var);
518 if (GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
519 || GPM_L1 == f->getProductType())
520 update_GPM_special_attrs(das,var,
false);
524 for (
const auto &cvar:cvars) {
525 if (
false == (cvar->getAttributes().empty())) {
528 if(H5INT64 == cvar->getType() || H5UINT64 == cvar->getType()){
532 AttrTable *at = das.get_table(cvar->getNewName());
534 at = das.add_table(cvar->getNewName(), obtain_new_attr_table());
536 for (
const auto &attr:cvar->getAttributes())
537 gen_dap_oneobj_das(at,attr,cvar);
541 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
542 || GPM_L1 == f->getProductType())
543 update_GPM_special_attrs(das,cvar,
true);
548 for (
const auto &spvar:spvars) {
549 if (
false == (spvar->getAttributes().empty())) {
551 AttrTable *at = das.get_table(spvar->getNewName());
553 at = das.add_table(spvar->getNewName(), obtain_new_attr_table());
555 for (
const auto &attr:spvar->getAttributes())
556 gen_dap_oneobj_das(at,attr,spvar);
561 if(f->HaveUnlimitedDim() ==
true) {
563 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DAS generation function gen_gmh5_cfdas() "<<endl);
568 if(cvars.empty()==
false ){
572 bool still_has_unlimited =
false;
573 for (
const auto &cvar:cvars) {
576 for (
const auto &dim:cvar->getDimensions()) {
581 if(dim->HaveUnlimitedDim() ==
true) {
582 still_has_unlimited =
true;
586 if (
true == still_has_unlimited)
590 if (
true == still_has_unlimited) {
591 AttrTable* at = das.get_table(
"DODS_EXTRA");
593 at = das.add_table(
"DODS_EXTRA", obtain_new_attr_table());
595 string unlimited_names;
597 for (
const auto &cvar:cvars) {
600 for (
const auto &dim:cvar->getDimensions()) {
605 if (dim->HaveUnlimitedDim() ==
true) {
606 if (unlimited_names==
"") {
607 unlimited_names = dim->getNewName();
609 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
612 if(unlimited_names.rfind(dim->getNewName()) == string::npos) {
613 unlimited_names = unlimited_names+
" "+dim->getNewName();
615 at->append_attr(
"Unlimited_Dimension",
"String",dim->getNewName());
634 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdmr() "<<endl);
636 const vector<HDF5CF::Var *>& vars = f->
getVars();
637 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
638 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
639 const string filename = f->
getPath();
641 const vector<HDF5CF::Group *>& grps = f->
getGroups();
642 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
648 if (
false == root_attrs.empty()) {
649 for (
const auto &root_attr:root_attrs)
650 map_cfh5_grp_attr_to_dap4(d4_root,root_attr);
654 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
656 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
657 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
658 gen_dap_onegmcvar_dmr(d4_root,*it_cv,fileid, filename);
661 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
662 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
663 gen_dap_onevar_dmr(d4_root,*it_v,fileid, filename);
669 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
670 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
671 gen_dap_onevar_dmr(d4_root,*it_v,fileid, filename);
674 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
675 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
676 gen_dap_onegmcvar_dmr(d4_root,*it_cv,fileid, filename);
681 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
682 || GPM_L1 == f->getProductType())
683 update_GPM_special_attrs_cfdmr(d4_root,cvars);
685 for (
auto it_spv = spvars.begin(); it_spv !=spvars.end();it_spv++) {
686 BESDEBUG(
"h5",
"variable full path= "<< (*it_spv)->getFullPath() <<endl);
687 gen_dap_onegmspvar_dmr(d4_root,*it_spv,fileid, filename);
691 if (
false == grps.empty()) {
693 for (
const auto &grp:grps) {
695 auto tmp_grp_unique = make_unique<D4Attribute>();
696 auto tmp_grp = tmp_grp_unique.release();
697 tmp_grp->set_name(grp->getNewName());
700 tmp_grp->set_type(attr_container_c);
702 for (
const auto &attr: grp->getAttributes())
703 map_cfh5_attr_container_to_dap4(tmp_grp,attr);
705 d4_root->attributes()->add_attribute_nocopy(tmp_grp);
712 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DMR generation function gen_gmh5_cfdmr() "<<endl);
717 if(cvars.empty()==
false ){
721 bool still_has_unlimited =
false;
722 for (
const auto &cvar:cvars) {
725 for (
const auto &dim:cvar->getDimensions()) {
730 if(dim->HaveUnlimitedDim() ==
true) {
731 still_has_unlimited =
true;
735 if(
true == still_has_unlimited)
739 if(
true == still_has_unlimited) {
741 string dods_extra =
"DODS_EXTRA";
744 if(d4_root->attributes() !=
nullptr) {
749 string unlimited_dim_names;
751 for (
const auto &cvar:cvars) {
754 for (
const auto& dim:cvar->getDimensions()) {
759 if(dim->HaveUnlimitedDim() ==
true) {
761 string unlimited_dim_name = dim->getNewName();
762 if(unlimited_dim_names==
"")
763 unlimited_dim_names = unlimited_dim_name;
765 if(unlimited_dim_names.rfind(unlimited_dim_name) == string::npos)
766 unlimited_dim_names = unlimited_dim_names+
" "+unlimited_dim_name;
772 if(unlimited_dim_names.empty() ==
false) {
773 auto unlimited_dim_attr_unique = make_unique<D4Attribute>(
"Unlimited_Dimension",attr_str_c);
774 auto unlimited_dim_attr = unlimited_dim_attr_unique.release();
775 unlimited_dim_attr->add_value(unlimited_dim_names);
776 auto dods_extra_attr_unique = make_unique<D4Attribute>(dods_extra,attr_container_c);
777 auto dods_extra_attr = dods_extra_attr_unique.release();
778 dods_extra_attr->attributes()->add_attribute_nocopy(unlimited_dim_attr);
779 d4_root->attributes()->add_attribute_nocopy(dods_extra_attr);
783 throw InternalErr(__FILE__, __LINE__,
"Unlimited dimension should exist.");
792 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
795 vector <string> cvar_name;
796 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv)
797 cvar_name.emplace_back((*it_cv)->getNewName());
799 add_dap4_coverage(d4_root,cvar_name,f->getIsCOARD());
807 BESDEBUG(
"h5",
"Coming to gen_gmh5_cf_ignored_obj_info() "<<endl);
808 AttrTable *at = das.get_table(
"Ignored_Object_Info");
810 at = das.add_table(
"Ignored_Object_Info", obtain_new_attr_table());
817void gen_dap_onegmcvar_dds(DDS &dds,
const HDF5CF::GMCVar* cvar,
const hid_t file_id,
const string & filename) {
819 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
824 BaseType *bt =
nullptr;
827#define HANDLE_CASE(tid,type) \
829 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
840 HANDLE_CASE(H5FSTRING,
Str)
841 HANDLE_CASE(H5VSTRING,
Str)
844 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
850 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
851 vector <HDF5CF::Dimension*>:: const_iterator it_d;
852 vector <size_t> dimsizes;
853 dimsizes.resize(cvar->
getRank());
854 for(
int i = 0; i <cvar->
getRank();i++)
855 dimsizes[i] = (dims[i])->getSize();
859 throw InternalErr(__FILE__, __LINE__,
"the coordinate variable cannot be a scalar");
868 bool is_latlon = cvar->isLatLon();
870 auto ar_unique = make_unique< HDF5CFArray>
877 cvar->getTotalElems(),
884 ar = ar_unique.get();
886 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
887 if (((*it_d)->getNewName()).empty())
888 ar->append_dim((
int)((*it_d)->getSize()));
890 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
902 auto ar_unique = make_unique<HDF5GMCFMissLLArray>
912 ar = ar_unique.get();
914 for (it_d = dims.begin(); it_d != dims.end(); ++it_d) {
915 if (((*it_d)->getNewName()).empty())
916 ar->append_dim((
int)((*it_d)->getSize()));
918 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
924 case CV_NONLATLON_MISS:
929 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
935 auto ar_unique = make_unique<HDF5GMCFMissNonLLCVArray>
940 ar = ar_unique.get();
942 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
943 if (((*it_d)->getNewName()).empty())
944 ar->append_dim((
int)((*it_d)->getSize()));
946 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
956 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
961 auto ar_unique = make_unique<HDF5GMCFFillIndexArray>
967 ar = ar_unique.get();
969 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
970 if (((*it_d)->getNewName()).empty())
971 ar->append_dim((
int)((*it_d)->getSize()));
973 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
984 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
988 auto ar_unique = make_unique<HDF5GMCFSpecialCVArray>(
995 auto ar = ar_unique.get();
997 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
998 if (((*it_d)->getNewName()).empty())
999 ar->append_dim((
int)((*it_d)->getSize()));
1001 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1010 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
1017void gen_dap_onegmspvar_dds(DDS &dds,
const HDF5CF::GMSPVar* spvar,
const hid_t fileid,
const string & filename) {
1019 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dds() "<<endl);
1020 BaseType *bt =
nullptr;
1023#define HANDLE_CASE(tid,type) \
1025 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \
1036 HANDLE_CASE(H5FSTRING,
Str)
1037 HANDLE_CASE(H5VSTRING,
Str)
1039 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1045 const vector<HDF5CF::Dimension *>& dims = spvar->
getDimensions();
1049 throw InternalErr(__FILE__, __LINE__,
"Currently don't support scalar special variables. ");
1053 auto ar_unique = make_unique<HDF5GMSPCFArray> (
1059 spvar->getOriginalType(),
1060 spvar->getStartBit(),
1064 ar = ar_unique.get();
1066 for (
auto const &dim:dims) {
1067 if ((dim->getNewName()).empty())
1068 ar->append_dim((
int)(dim->getSize()));
1070 ar->append_dim((
int)(dim->getSize()), dim->getNewName());
1083void update_GPM_special_attrs(DAS& das,
const HDF5CF::Var *var,
bool is_cvar) {
1085 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs() "<<endl);
1086 if(H5FLOAT64 == var->
getType() ||
1087 H5FLOAT32 == var->
getType() ||
1091 AttrTable *at = das.get_table(var->
getNewName());
1093 at = das.add_table(var->
getNewName(), obtain_new_attr_table());
1094 bool has_fillvalue =
false;
1095 AttrTable::Attr_iter it = at->attr_begin();
1096 while (it!=at->attr_end() &&
false==has_fillvalue) {
1097 if (at->get_name(it) ==
"_FillValue")
1099 has_fillvalue =
true;
1100 string fillvalue =
"";
1101 if(H5FLOAT32 == var->
getType()) {
1102 const string cor_fill_value =
"-9999.9";
1103 fillvalue = (*at->get_attr_vector(it)->begin());
1104 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
1105 at->del_attr(
"_FillValue");
1106 at->append_attr(
"_FillValue",
"Float32",cor_fill_value);
1109 else if(H5FLOAT64 == var->
getType()) {
1110 const string cor_fill_value =
"-9999.9";
1111 const string exist_fill_value_substr =
"-9999.8999";
1112 fillvalue = (*at->get_attr_vector(it)->begin());
1113 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
1114 at->del_attr(
"_FillValue");
1115 at->append_attr(
"_FillValue",
"Float64",cor_fill_value);
1124 if(
false == is_cvar ) {
1127 if (has_fillvalue !=
true ) {
1129 if(H5FLOAT32 == var->
getType())
1130 at->append_attr(
"_FillValue",
"Float32",
"-9999.9");
1131 else if(H5FLOAT64 == var->
getType())
1132 at->append_attr(
"_FillValue",
"Float64",
"-9999.9");
1133 else if (H5INT16 == var->
getType())
1134 at->append_attr(
"_FillValue",
"Int16",
"-9999");
1135 else if (H5CHAR == var->
getType())
1136 at->append_attr(
"_FillValue",
"Int16",
"-99");
1148void update_GPM_special_attrs_cfdmr(libdap::D4Group* d4_root,
const vector<HDF5CF::GMCVar *>& cvars) {
1150 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs_cfdmr() "<<endl);
1153 Constructor::Vars_iter vi = d4_root->var_begin();
1154 Constructor::Vars_iter ve = d4_root->var_end();
1156 for (; vi != ve; vi++) {
1162 Type var_type = (*vi)->type();
1163 if ((*vi)->type() == dods_array_c)
1164 var_type = (*vi)->var()->type();
1165 if (dods_float64_c == var_type ||
1166 dods_float32_c == var_type ||
1167 dods_int16_c == var_type ||
1168 dods_int8_c == var_type) {
1170 const D4Attribute *d4_attr = (*vi)->attributes()->find(
"_FillValue");
1175 bool is_cvar =
false;
1176 for (
const auto &cvar:cvars) {
1184 if(
false == is_cvar) {
1186 D4Attribute *d4_fv =
nullptr;
1187 if (dods_float64_c == var_type ) {
1188 auto d4_fv_unique = make_unique<D4Attribute>(
"_FillValue",attr_float64_c);
1189 d4_fv = d4_fv_unique.release();
1190 d4_fv->add_value(
"-9999.9");
1192 else if (dods_float32_c == var_type) {
1193 auto d4_fv_unique = make_unique<D4Attribute>(
"_FillValue",attr_float32_c);
1194 d4_fv = d4_fv_unique.release();
1195 d4_fv->add_value(
"-9999.9");
1197 else if (dods_int16_c == var_type) {
1198 auto d4_fv_unique = make_unique<D4Attribute>(
"_FillValue",attr_int16_c);
1199 d4_fv = d4_fv_unique.release();
1200 d4_fv->add_value(
"-9999");
1202 else if (dods_int8_c == var_type) {
1203 auto d4_fv_unique = make_unique<D4Attribute>(
"_FillValue",attr_int8_c);
1204 d4_fv = d4_fv_unique.release();
1205 d4_fv->add_value(
"-99");
1207 (*vi)->attributes()->add_attribute_nocopy(d4_fv);
1211 D4Attribute *d4_fv =
nullptr;
1212 if (dods_float64_c == var_type ) {
1213 const string cor_fill_value =
"-9999.9";
1214 const string exist_fill_value_substr =
"-9999.8999";
1215 string fillvalue = d4_attr->value(0);
1216 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
1217 (*vi)->attributes()->erase(
"_FillValue");
1218 auto d4_fv_unique = make_unique<D4Attribute>(
"_FillValue",attr_float64_c);
1219 d4_fv = d4_fv_unique.release();
1220 d4_fv->add_value(cor_fill_value);
1221 (*vi)->attributes()->add_attribute_nocopy(d4_fv);
1224 else if (dods_float32_c == var_type) {
1225 const string cor_fill_value =
"-9999.9";
1226 string fillvalue = d4_attr->value(0);
1228 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
1229 (*vi)->attributes()->erase(
"_FillValue");
1230 auto d4_fv_unique = make_unique<D4Attribute>(
"_FillValue",attr_float32_c);
1231 d4_fv = d4_fv_unique.release();
1232 d4_fv->add_value(cor_fill_value);
1233 (*vi)->attributes()->add_attribute_nocopy(d4_fv);
1241void gen_dap_onegmcvar_dmr(D4Group*d4_root,
const GMCVar* cvar,
const hid_t fileid,
const string &filename) {
1243 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
1245 BaseType *bt =
nullptr;
1248#define HANDLE_CASE(tid,type) \
1250 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
1263 HANDLE_CASE(H5FSTRING,
Str)
1264 HANDLE_CASE(H5VSTRING,
Str)
1267 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1273 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
1274 vector <HDF5CF::Dimension*>:: const_iterator it_d;
1275 vector <size_t> dimsizes;
1276 dimsizes.resize(cvar->
getRank());
1278 for(
int i = 0; i <cvar->
getRank();i++)
1279 dimsizes[i] = (dims[i])->getSize();
1283 throw InternalErr(__FILE__, __LINE__,
"the coordinate variable cannot be a scalar");
1292 bool is_latlon = cvar->isLatLon();
1294 bool is_dap4 =
true;
1295 auto ar_unique = make_unique<HDF5CFArray> (
1302 cvar->getTotalElems(),
1309 ar = ar_unique.get();
1311 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1312 if (((*it_d)->getNewName()).empty())
1313 ar->append_dim_ll((
int)((*it_d)->getSize()));
1315 ar->append_dim_ll((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1318 ar->set_is_dap4(
true);
1319 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1320 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1321 d4_root->add_var_nocopy(d4_var);
1330 auto ar_unique = make_unique<HDF5GMCFMissLLArray> (
1340 ar = ar_unique.get();
1342 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1343 if (((*it_d)->getNewName()).empty())
1344 ar->append_dim_ll((*it_d)->getSize());
1346 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
1349 ar->set_is_dap4(
true);
1350 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1351 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1352 d4_root->add_var_nocopy(d4_var);
1356 case CV_NONLATLON_MISS:
1361 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
1367 auto ar_unique = make_unique<HDF5GMCFMissNonLLCVArray>(
1372 ar = ar_unique.get();
1374 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1375 if (((*it_d)->getNewName()).empty())
1376 ar->append_dim_ll((*it_d)->getSize());
1378 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
1380 ar->set_is_dap4(
true);
1381 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1382 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1383 d4_root->add_var_nocopy(d4_var);
1392 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
1397 auto ar_unique = make_unique<HDF5GMCFFillIndexArray>(
1403 ar = ar_unique.get();
1405 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1406 if (((*it_d)->getNewName()).empty())
1407 ar->append_dim_ll((*it_d)->getSize());
1409 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
1411 ar->set_is_dap4(
true);
1412 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1413 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1414 d4_root->add_var_nocopy(d4_var);
1423 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
1427 auto ar_unique = make_unique<HDF5GMCFSpecialCVArray>(cvar->
getType(),
1433 auto ar = ar_unique.get();
1434 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1435 if (((*it_d)->getNewName()).empty())
1436 ar->append_dim_ll((*it_d)->getSize());
1438 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
1441 ar->set_is_dap4(
true);
1442 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1443 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1444 d4_root->add_var_nocopy(d4_var);
1450 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
1456void gen_dap_onegmspvar_dmr(D4Group*d4_root,
const GMSPVar*spvar,
const hid_t fileid,
const string &filename) {
1458 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dmr() "<<endl);
1459 BaseType *bt =
nullptr;
1467#define HANDLE_CASE(tid,type) \
1469 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \
1480 HANDLE_CASE(H5FSTRING,
Str)
1481 HANDLE_CASE(H5VSTRING,
Str)
1483 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1489 const vector<HDF5CF::Dimension *> &dims = spvar->
getDimensions();
1493 throw InternalErr(__FILE__, __LINE__,
"Currently don't support scalar special variables. ");
1498 auto ar_unique = make_unique<HDF5GMSPCFArray>(spvar->
getRank(),
1503 spvar->getOriginalType(),
1504 spvar->getStartBit(),
1508 ar = ar_unique.get();
1510 for (
const auto &dim:dims) {
1511 if (
""==dim->getNewName())
1512 ar->append_dim_ll(dim->getSize());
1514 ar->append_dim_ll(dim->getSize(), dim->getNewName());
1517 ar->set_is_dap4(
true);
1518 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1519 map_cfh5_var_attrs_to_dap4(spvar,d4_var);
1520 d4_root->add_var_nocopy(d4_var);
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
This class provides a way to map HDF5 byte to DAP byte for the CF option.
This class provides a way to map HDF5 float to DAP float for the CF option.
This class provides a way to map HDF5 64-bit floating-point(double) to DAP 64-bit floating-point for ...
This class provides a way to map HDF5 int16 to DAP int16 for the CF option.
This class provides a way to map HDF5 32-bit integer to DAP Int32 for the CF option.
This class provides a way to map HDF5 64-bit integer to DAP4 Int64 for the CF option.
This class provides a way to map HDF5 int8 to DAP int16 for the CF option.
This class provides a way to map HDF5 Str to DAP Str for the CF option.
This class provides a way to map HDF5 unsigned 16-bit integer to DAP uint16 for the CF option.
This class provides a way to map HDF5 unsigned 32-bit integer to DAP uint32 for the CF option.
This class provides a way to map HDF5 64-bit unsigned integer to DAP4 UInt64 for the CF option.
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
This class specifies the retrieval of the missing lat/lon values for general HDF5 products.
This class specifies the retrieval of the values of non-lat/lon coordinate variables for general HDF5...
This class specifies the retrieval of the missing lat/lon values for general HDF5 products.
This class specifies the retrieval of data values for special HDF5 products Currently this only appli...
include the entry functions to execute the handlers
CVType getCVType() const
Get the coordinate variable type of this variable.
bool HaveUnlimitedDim() const
Has unlimited dimensions.
hid_t getFileID() const
Obtain the HDF5 file ID.
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain information of all attributes under the root group.
const std::vector< Group * > & getGroups() const
Public interface to obtain all the group info.
const std::string & getPath() const
Obtain the path of the file.
const std::vector< Var * > & getVars() const
Public interface to obtain information of all variables.
This class is a derived class of CVar. It represents a coordinate variable for general HDF5 files.
H5GCFProduct getPtType() const
Get the data type of this variable.
This class is a derived class of File. It includes methods applied to general HDF5 files only.
const std::string & Get_Ignored_Msg() override
Get the message that contains the ignored obj. info.
This class is a derived class of Var. It represents a special general HDF5 product(currently ACOS and...
This class represents one HDF5 dataset(CF variable)
float getCompRatio() const
Get the compression ratio of this dataset.
int getRank() const
Get the dimension rank of this variable.
const std::string & getFullPath() const
Get the full path of this variable.
H5DataType getType() const
Get the data type of this variable(Not HDF5 datatype id)
const std::vector< Dimension * > & getDimensions() const
Get the list of the dimensions.
const std::string & getNewName() const
Get the new name of this variable.
Helper functions for generating DAS attributes and a function to check BES Key.
Map and generate DDS and DAS for the CF option for generic HDF5 products.