41#include <libdap/InternalErr.h>
66using namespace HDF5CF;
69void map_gmh5_cfdds(DDS &dds, hid_t file_id,
const string& filename){
71 BESDEBUG(
"h5",
"Coming to GM products DDS mapping function map_gmh5_cfdds() "<<endl);
73 H5GCFProduct product_type = check_product(file_id);
75 GMPattern gproduct_pattern = OTHERGMS;
80 f =
new GMFile(filename.c_str(),file_id,product_type,gproduct_pattern);
83 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate memory for GMFile ");
86 bool include_attr =
false;
121 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
122 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr)){
145 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
146 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
158 if(General_Product == product_type ||
159 true == HDF5RequestHandler::get_check_name_clashing())
164 if(General_Product == product_type ||
165 true == HDF5RequestHandler::get_check_name_clashing())
168 f->Handle_Hybrid_EOS5();
172 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
173 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
182 throw InternalErr(e.what());
187 gen_gmh5_cfdds(dds,f);
200void map_gmh5_cfdas(DAS &das, hid_t file_id,
const string& filename){
202 BESDEBUG(
"h5",
"Coming to GM products DAS mapping function map_gmh5_cfdas() "<<endl);
204 H5GCFProduct product_type = check_product(file_id);
205 GMPattern gproduct_pattern = OTHERGMS;
210 f =
new GMFile(filename.c_str(),file_id,product_type,gproduct_pattern);
213 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate memory for GMFile ");
216 bool include_attr =
true;
250 if(General_Product == product_type ||
251 true == HDF5RequestHandler::get_check_name_clashing())
258 f->Handle_Hybrid_EOS5();
266 if(
true == HDF5RequestHandler::get_enable_coord_attr_add_path())
272 throw InternalErr(e.what());
277 gen_gmh5_cfdas(das,f);
291void map_gmh5_cfdmr(D4Group *d4_root, hid_t file_id,
const string& filename){
293 BESDEBUG(
"h5",
"Coming to GM products DMR mapping function map_gmh5_cfdmr() "<<endl);
295 H5GCFProduct product_type = check_product(file_id);
297 GMPattern gproduct_pattern = OTHERGMS;
302 f =
new GMFile(filename.c_str(),file_id,product_type,gproduct_pattern);
305 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate memory for GMFile ");
309 bool include_attr =
true;
369 if(General_Product == product_type ||
370 true == HDF5RequestHandler::get_check_name_clashing())
375 if(General_Product == product_type ||
376 true == HDF5RequestHandler::get_check_name_clashing())
382 f->Handle_Hybrid_EOS5();
387 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
388 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
395 if(
true == HDF5RequestHandler::get_enable_coord_attr_add_path())
402 throw InternalErr(e.what());
407 gen_gmh5_cfdmr(d4_root,f);
421void gen_gmh5_cfdds( DDS & dds, HDF5CF:: GMFile *f) {
423 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdds() "<<endl);
425 const vector<HDF5CF::Var *>& vars = f->getVars();
426 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
427 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
428 const string filename = f->getPath();
429 const hid_t fileid = f->getFileID();
441 bool dmr_64bit_support =
false;
442 if(HDF5RequestHandler::get_dmr_long_int()==
true &&
443 HDF5RequestHandler::get_dmr_64bit_int()!=
nullptr) {
444 for (
auto it_v = vars.begin(); it_v !=vars.end();++it_v) {
445 if (H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
446 dmr_64bit_support =
true;
453 if(
true == dmr_64bit_support) {
455 f->Handle_Unsupported_Dtype(
true);
458 f->Handle_Unsupported_Dspace(
true);
462 for (
auto it_v = vars.begin(); it_v !=vars.end();++it_v) {
463 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
465 if(need_attr_values_for_dap4(*it_v) ==
true)
466 f->Retrieve_H5_Var_Attr_Values(*it_v);
467 gen_dap_onevar_dds(dds,*it_v,fileid, filename);
469 for (
auto it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
470 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
471 gen_dap_onegmcvar_dds(dds,*it_cv,fileid, filename);
474 for (
auto it_spv = spvars.begin(); it_spv !=spvars.end();it_spv++) {
475 BESDEBUG(
"h5",
"variable full path= "<< (*it_spv)->getFullPath() <<endl);
476 gen_dap_onegmspvar_dds(dds,*it_spv,fileid, filename);
482void gen_gmh5_cfdas( DAS & das, HDF5CF:: GMFile *f) {
484 BESDEBUG(
"h5",
"Coming to GM DAS generation function gen_gmh5_cfdas() "<<endl);
487 if(
true == f->Get_IgnoredInfo_Flag()) {
488 gen_gmh5_cf_ignored_obj_info(das, f);
492 const vector<HDF5CF::Var *>& vars = f->getVars();
493 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
494 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
495 const vector<HDF5CF::Group *>& grps = f->getGroups();
496 const vector<HDF5CF::Attribute *>& root_attrs = f->getAttributes();
499 vector<HDF5CF::Var *>::const_iterator it_v;
500 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
501 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
502 vector<HDF5CF::Group *>::const_iterator it_g;
503 vector<HDF5CF::Attribute *>::const_iterator it_ra;
509 if (
false == root_attrs.empty()) {
511 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
513 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
515 for (
auto it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra) {
517 check_update_int64_attr(
"",*it_ra);
518 gen_dap_oneobj_das(at,*it_ra,
nullptr);
522 if (
false == grps.empty()) {
523 for (
auto it_g = grps.begin();
524 it_g != grps.end(); ++it_g) {
525 AttrTable *at = das.get_table((*it_g)->getNewName());
527 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
529 for (
auto it_ra = (*it_g)->getAttributes().begin();
530 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
531 check_update_int64_attr((*it_g)->getNewName(),*it_ra);
532 gen_dap_oneobj_das(at,*it_ra,
nullptr);
537 for (
auto it_v = vars.begin();
538 it_v != vars.end(); ++it_v) {
539 if (
false == ((*it_v)->getAttributes().empty())) {
545 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
549 AttrTable *at = das.get_table((*it_v)->getNewName());
551 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
553 for (
auto it_ra = (*it_v)->getAttributes().begin();
554 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
555 gen_dap_oneobj_das(at,*it_ra,*it_v);
565 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
566 || GPM_L1 == f->getProductType())
567 update_GPM_special_attrs(das,*it_v,
false);
571 for (
auto it_cv = cvars.begin();
572 it_cv != cvars.end(); ++it_cv) {
573 if (
false == ((*it_cv)->getAttributes().empty())) {
576 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
580 AttrTable *at = das.get_table((*it_cv)->getNewName());
582 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
584 for (
auto it_ra = (*it_cv)->getAttributes().begin();
585 it_ra != (*it_cv)->getAttributes().end(); ++it_ra){
586 gen_dap_oneobj_das(at,*it_ra,*it_cv);
591 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
592 || GPM_L1 == f->getProductType())
593 update_GPM_special_attrs(das,*it_cv,
true);
598 for (
auto it_spv = spvars.begin();
599 it_spv != spvars.end(); ++it_spv) {
600 if (
false == ((*it_spv)->getAttributes().empty())) {
602 AttrTable *at = das.get_table((*it_spv)->getNewName());
604 at = das.add_table((*it_spv)->getNewName(),
new AttrTable);
609 for (
auto it_ra = (*it_spv)->getAttributes().begin();
610 it_ra != (*it_spv)->getAttributes().end(); ++it_ra)
611 gen_dap_oneobj_das(at,*it_ra,*it_spv);
616 if(f->HaveUnlimitedDim() ==
true) {
618 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DAS generation function gen_gmh5_cfdas() "<<endl);
623 if(cvars.empty()==
false ){
627 bool still_has_unlimited =
false;
628 for (
auto it_cv = cvars.begin();
629 it_cv != cvars.end(); ++it_cv) {
631 for (
auto ird = (*it_cv)->getDimensions().begin();
632 ird != (*it_cv)->getDimensions().end(); ++ird) {
637 if((*ird)->HaveUnlimitedDim() ==
true) {
638 still_has_unlimited =
true;
642 if(
true == still_has_unlimited)
646 if(
true == still_has_unlimited) {
647 AttrTable* at = das.get_table(
"DODS_EXTRA");
649 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
651 string unlimited_names;
653 for (
auto it_cv = cvars.begin();
654 it_cv != cvars.end(); ++it_cv) {
656 bool has_unlimited_dim =
false;
659 for (
auto ird = (*it_cv)->getDimensions().begin();
660 ird != (*it_cv)->getDimensions().end(); ++ird) {
665 if((*ird)->HaveUnlimitedDim() ==
true) {
666 if(unlimited_names==
"") {
667 unlimited_names = (*ird)->getNewName();
669 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
672 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
673 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
675 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
694 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdmr() "<<endl);
696 const vector<HDF5CF::Var *>& vars = f->
getVars();
697 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
698 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
699 const string filename = f->
getPath();
701 const vector<HDF5CF::Group *>& grps = f->
getGroups();
702 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
704 vector<HDF5CF::Var *>::const_iterator it_v;
705 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
706 vector<HDF5CF::Attribute *>::const_iterator it_ra;
709 if (
false == root_attrs.empty()) {
710 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra)
711 map_cfh5_grp_attr_to_dap4(d4_root,*it_ra);
715 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
717 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
718 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
719 gen_dap_onegmcvar_dmr(d4_root,*it_cv,fileid, filename);
722 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
723 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
724 gen_dap_onevar_dmr(d4_root,*it_v,fileid, filename);
732 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
733 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
734 gen_dap_onevar_dmr(d4_root,*it_v,fileid, filename);
738 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
739 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
740 gen_dap_onegmcvar_dmr(d4_root,*it_cv,fileid, filename);
745 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
746 || GPM_L1 == f->getProductType())
747 update_GPM_special_attrs_cfdmr(d4_root,cvars);
750 for (
auto it_spv = spvars.begin(); it_spv !=spvars.end();it_spv++) {
751 BESDEBUG(
"h5",
"variable full path= "<< (*it_spv)->getFullPath() <<endl);
752 gen_dap_onegmspvar_dmr(d4_root,*it_spv,fileid, filename);
756 if (
false == grps.empty()) {
757 for (
auto it_g = grps.begin();
758 it_g != grps.end(); ++it_g) {
760 auto tmp_grp =
new D4Attribute;
761 tmp_grp->set_name((*it_g)->getNewName());
764 tmp_grp->set_type(attr_container_c);
766 for (it_ra = (*it_g)->getAttributes().begin();
767 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
768 map_cfh5_attr_container_to_dap4(tmp_grp,(*it_ra));
771 d4_root->attributes()->add_attribute_nocopy(tmp_grp);
778 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DMR generation function gen_gmh5_cfdmr() "<<endl);
783 if(cvars.empty()==
false ){
787 bool still_has_unlimited =
false;
788 for (it_cv = cvars.begin();
789 it_cv != cvars.end(); ++it_cv) {
791 for (
auto ird = (*it_cv)->getDimensions().begin();
792 ird != (*it_cv)->getDimensions().end(); ++ird) {
797 if((*ird)->HaveUnlimitedDim() ==
true) {
798 still_has_unlimited =
true;
802 if(
true == still_has_unlimited)
806 if(
true == still_has_unlimited) {
808 string dods_extra =
"DODS_EXTRA";
811 if(d4_root->attributes() !=
nullptr) {
815 string unlimited_dim_names =
"";
817 for (it_cv = cvars.begin();
818 it_cv != cvars.end(); it_cv++) {
821 for (
auto ird = (*it_cv)->getDimensions().begin();
822 ird != (*it_cv)->getDimensions().end(); ++ird) {
827 if((*ird)->HaveUnlimitedDim() ==
true) {
829 string unlimited_dim_name = (*ird)->getNewName();
830 if(unlimited_dim_names==
"")
831 unlimited_dim_names = unlimited_dim_name;
833 if(unlimited_dim_names.rfind(unlimited_dim_name) == string::npos)
834 unlimited_dim_names = unlimited_dim_names+
" "+unlimited_dim_name;
840 if(unlimited_dim_names !=
"") {
841 auto dods_extra_attr =
new D4Attribute(dods_extra,attr_container_c);
842 auto unlimited_dim_attr =
new D4Attribute(
"Unlimited_Dimension",attr_str_c);
843 unlimited_dim_attr->add_value(unlimited_dim_names);
844 dods_extra_attr->attributes()->add_attribute_nocopy(unlimited_dim_attr);
845 d4_root->attributes()->add_attribute_nocopy(dods_extra_attr);
849 throw InternalErr(__FILE__, __LINE__,
"Unlimited dimension should exist.");
858 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
861 vector <string> cvar_name;
862 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv)
863 cvar_name.emplace_back((*it_cv)->getNewName());
865 add_dap4_coverage(d4_root,cvar_name,f->getIsCOARD());
873 BESDEBUG(
"h5",
"Coming to gen_gmh5_cf_ignored_obj_info() "<<endl);
874 AttrTable *at = das.get_table(
"Ignored_Object_Info");
876 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
883void gen_dap_onegmcvar_dds(DDS &dds,
const HDF5CF::GMCVar* cvar,
const hid_t file_id,
const string & filename) {
885 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
889 BaseType *bt =
nullptr;
892#define HANDLE_CASE(tid,type) \
894 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
905 HANDLE_CASE(H5FSTRING,
Str)
906 HANDLE_CASE(H5VSTRING,
Str)
909 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
915 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
916 vector <HDF5CF::Dimension*>:: const_iterator it_d;
917 vector <size_t> dimsizes;
918 dimsizes.resize(cvar->
getRank());
919 for(
int i = 0; i <cvar->
getRank();i++)
920 dimsizes[i] = (dims[i])->getSize();
924 throw InternalErr(__FILE__,__LINE__,
"the coordinate variable cannot be a scalar");
933 bool is_latlon = cvar->isLatLon();
943 cvar->getTotalElems(),
953 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5CFArray. ");
956 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
957 if (
""==(*it_d)->getNewName())
958 ar->append_dim((
int)((*it_d)->getSize()));
960 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
988 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissLLArray. ");
992 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
993 if (
""==(*it_d)->getNewName())
994 ar->append_dim((
int)((*it_d)->getSize()));
996 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1005 case CV_NONLATLON_MISS:
1010 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
1025 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
1029 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1030 if (
""==(*it_d)->getNewName())
1031 ar->append_dim((
int)((*it_d)->getSize()));
1033 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1046 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
1061 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
1065 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1066 if (
""==(*it_d)->getNewName())
1067 ar->append_dim((
int)((*it_d)->getSize()));
1069 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1083 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
1096 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1097 if (
""==(*it_d)->getNewName())
1098 ar->append_dim((
int)((*it_d)->getSize()));
1100 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1112 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
1118void gen_dap_onegmspvar_dds(DDS &dds,
const HDF5CF::GMSPVar* spvar,
const hid_t fileid,
const string & filename) {
1120 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dds() "<<endl);
1121 BaseType *bt =
nullptr;
1124#define HANDLE_CASE(tid,type) \
1126 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \
1137 HANDLE_CASE(H5FSTRING,
Str)
1138 HANDLE_CASE(H5VSTRING,
Str)
1140 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1146 const vector<HDF5CF::Dimension *>& dims = spvar->
getDimensions();
1149 throw InternalErr(__FILE__,__LINE__,
"Currently don't support scalar special variables. ");
1160 spvar->getOriginalType(),
1161 spvar->getStartBit(),
1168 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
1172 for(
auto it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1173 if (
""==(*it_d)->getNewName())
1174 ar->append_dim((
int)((*it_d)->getSize()));
1176 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1190void update_GPM_special_attrs(DAS& das,
const HDF5CF::Var *var,
bool is_cvar) {
1192 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs() "<<endl);
1193 if(H5FLOAT64 == var->
getType() ||
1194 H5FLOAT32 == var->
getType() ||
1198 AttrTable *at = das.get_table(var->
getNewName());
1200 at = das.add_table(var->
getNewName(),
new AttrTable);
1201 bool has_fillvalue =
false;
1202 AttrTable::Attr_iter it = at->attr_begin();
1203 while (it!=at->attr_end() &&
false==has_fillvalue) {
1204 if (at->get_name(it) ==
"_FillValue")
1206 has_fillvalue =
true;
1207 string fillvalue =
"";
1208 if(H5FLOAT32 == var->
getType()) {
1209 const string cor_fill_value =
"-9999.9";
1210 fillvalue = (*at->get_attr_vector(it)->begin());
1211 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
1212 at->del_attr(
"_FillValue");
1213 at->append_attr(
"_FillValue",
"Float32",cor_fill_value);
1216 else if(H5FLOAT64 == var->
getType()) {
1217 const string cor_fill_value =
"-9999.9";
1218 const string exist_fill_value_substr =
"-9999.8999";
1219 fillvalue = (*at->get_attr_vector(it)->begin());
1220 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
1221 at->del_attr(
"_FillValue");
1222 at->append_attr(
"_FillValue",
"Float64",cor_fill_value);
1231 if(
false == is_cvar ) {
1234 if (has_fillvalue !=
true ) {
1236 if(H5FLOAT32 == var->
getType())
1237 at->append_attr(
"_FillValue",
"Float32",
"-9999.9");
1238 else if(H5FLOAT64 == var->
getType())
1239 at->append_attr(
"_FillValue",
"Float64",
"-9999.9");
1240 else if (H5INT16 == var->
getType())
1241 at->append_attr(
"_FillValue",
"Int16",
"-9999");
1242 else if (H5CHAR == var->
getType())
1243 at->append_attr(
"_FillValue",
"Int16",
"-99");
1255void update_GPM_special_attrs_cfdmr(libdap::D4Group* d4_root,
const vector<HDF5CF::GMCVar *>& cvars) {
1257 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs_cfdmr() "<<endl);
1260 Constructor::Vars_iter vi = d4_root->var_begin();
1261 Constructor::Vars_iter ve = d4_root->var_end();
1263 for (; vi != ve; vi++) {
1269 Type var_type = (*vi)->type();
1270 if ((*vi)->type() == dods_array_c)
1271 var_type = (*vi)->var()->type();
1272 if (dods_float64_c == var_type ||
1273 dods_float32_c == var_type ||
1274 dods_int16_c == var_type ||
1275 dods_int8_c == var_type) {
1277 D4Attribute *d4_attr = (*vi)->attributes()->find(
"_FillValue");
1282 bool is_cvar =
false;
1283 for (
auto it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
1284 if ((*it_cv)->getNewName() == (*vi)->name()) {
1291 if(
false == is_cvar) {
1293 D4Attribute *d4_fv =
nullptr;
1294 if (dods_float64_c == var_type ) {
1295 d4_fv =
new D4Attribute(
"_FillValue",attr_float64_c);
1296 d4_fv->add_value(
"-9999.9");
1298 else if (dods_float32_c == var_type) {
1299 d4_fv =
new D4Attribute(
"_FillValue",attr_float32_c);
1300 d4_fv->add_value(
"-9999.9");
1302 else if (dods_int16_c == var_type) {
1303 d4_fv =
new D4Attribute(
"_FillValue",attr_int16_c);
1304 d4_fv->add_value(
"-9999");
1306 else if (dods_int8_c == var_type) {
1307 d4_fv =
new D4Attribute(
"_FillValue",attr_int8_c);
1308 d4_fv->add_value(
"-99");
1310 (*vi)->attributes()->add_attribute_nocopy(d4_fv);
1315 D4Attribute *d4_fv =
nullptr;
1316 if (dods_float64_c == var_type ) {
1317 const string cor_fill_value =
"-9999.9";
1318 const string exist_fill_value_substr =
"-9999.8999";
1319 string fillvalue = d4_attr->value(0);
1320 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
1321 (*vi)->attributes()->erase(
"_FillValue");
1322 d4_fv =
new D4Attribute(
"_FillValue",attr_float64_c);
1323 d4_fv->add_value(cor_fill_value);
1324 (*vi)->attributes()->add_attribute_nocopy(d4_fv);
1327 else if (dods_float32_c == var_type) {
1328 const string cor_fill_value =
"-9999.9";
1329 string fillvalue = d4_attr->value(0);
1331 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
1332 (*vi)->attributes()->erase(
"_FillValue");
1333 d4_fv =
new D4Attribute(
"_FillValue",attr_float32_c);
1334 d4_fv->add_value(cor_fill_value);
1335 (*vi)->attributes()->add_attribute_nocopy(d4_fv);
1345void gen_dap_onegmcvar_dmr(D4Group*d4_root,
const GMCVar* cvar,
const hid_t fileid,
const string &filename) {
1347 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
1349 BaseType *bt =
nullptr;
1352#define HANDLE_CASE(tid,type) \
1354 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
1367 HANDLE_CASE(H5FSTRING,
Str)
1368 HANDLE_CASE(H5VSTRING,
Str)
1371 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1377 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
1378 vector <HDF5CF::Dimension*>:: const_iterator it_d;
1379 vector <size_t> dimsizes;
1380 dimsizes.resize(cvar->
getRank());
1382 for(
int i = 0; i <cvar->
getRank();i++)
1383 dimsizes[i] = (dims[i])->getSize();
1386 throw InternalErr(__FILE__,__LINE__,
"the coordinate variable cannot be a scalar");
1395 bool is_latlon = cvar->isLatLon();
1399 bool is_dap4 =
true;
1407 cvar->getTotalElems(),
1417 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5CFArray. ");
1420 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1421 if (
""==(*it_d)->getNewName())
1422 ar->append_dim((
int)((*it_d)->getSize()));
1424 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1427 ar->set_is_dap4(
true);
1428 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1429 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1430 d4_root->add_var_nocopy(d4_var);
1455 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissLLArray. ");
1458 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1459 if (
""==(*it_d)->getNewName())
1460 ar->append_dim((
int)((*it_d)->getSize()));
1462 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1465 ar->set_is_dap4(
true);
1466 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1467 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1468 d4_root->add_var_nocopy(d4_var);
1474 case CV_NONLATLON_MISS:
1479 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
1494 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
1498 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1499 if (
""==(*it_d)->getNewName())
1500 ar->append_dim((
int)((*it_d)->getSize()));
1502 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1504 ar->set_is_dap4(
true);
1505 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1506 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1507 d4_root->add_var_nocopy(d4_var);
1518 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
1533 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
1537 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1538 if (
""==(*it_d)->getNewName())
1539 ar->append_dim((
int)((*it_d)->getSize()));
1541 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1543 ar->set_is_dap4(
true);
1544 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1545 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1546 d4_root->add_var_nocopy(d4_var);
1558 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
1571 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1572 if (
""==(*it_d)->getNewName())
1573 ar->append_dim((
int)((*it_d)->getSize()));
1575 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1578 ar->set_is_dap4(
true);
1579 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1580 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
1581 d4_root->add_var_nocopy(d4_var);
1590 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
1597void gen_dap_onegmspvar_dmr(D4Group*d4_root,
const GMSPVar*spvar,
const hid_t fileid,
const string &filename) {
1599 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dmr() "<<endl);
1600 BaseType *bt =
nullptr;
1608#define HANDLE_CASE(tid,type) \
1610 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \
1621 HANDLE_CASE(H5FSTRING,
Str)
1622 HANDLE_CASE(H5VSTRING,
Str)
1624 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
1630 const vector<HDF5CF::Dimension *>& dims = spvar->
getDimensions();
1633 throw InternalErr(__FILE__,__LINE__,
"Currently don't support scalar special variables. ");
1644 spvar->getOriginalType(),
1645 spvar->getStartBit(),
1652 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
1656 for(
auto it_d = dims.begin(); it_d != dims.end(); ++it_d) {
1657 if (
""==(*it_d)->getNewName())
1658 ar->append_dim((
int)((*it_d)->getSize()));
1660 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
1663 ar->set_is_dap4(
true);
1664 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
1665 map_cfh5_var_attrs_to_dap4(spvar,d4_var);
1666 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.
void Add_Supplement_Attrs(bool) override
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
void Add_Path_Coord_Attr()
Update the coordinate attribute to include path and also flatten.
void Handle_Obj_NameClashing(bool)
Handle object name clashing for general NASA HDF5 products.
void Remove_Unused_FakeDimVars()
Unsupported datatype array may generate FakeDim. Remove them.
void Update_Product_Type()
Update "product type" attributes for general HDF5 products.
bool Have_Grid_Mapping_Attrs() override
Check if having Grid Mapping Attrs.
void Handle_DimNameClashing() override
void Handle_Grid_Mapping_Vars() override
Handle Grid Mapping Vars.
void Retrieve_H5_CVar_Supported_Attr_Values() override
Retrieve coordinate variable attributes.
void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr) override
Retrieve DDS information from the HDF5 file; real implementation for general HDF5 products.
void Handle_SpVar() override
Handle special variables for general NASA HDF5 products.
const std::string & Get_Ignored_Msg() override
Get the message that contains the ignored obj. info.
void Remove_Unneeded_Objects()
Remove unneeded objects.
void Handle_CVar() override
Handle coordinate variables for general NASA HDF5 products.
void Add_Dim_Name()
Add dimension name.
void Retrieve_H5_Supported_Attr_Values() override
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
void Handle_Coor_Attr() override
Handle "coordinates" attributes for general HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
void Handle_Unsupported_Dspace(bool) override
Handle unsupported HDF5 dataspaces for general HDF5 products.
void Handle_Unsupported_Others(bool) override
Handle other unmapped objects/attributes for general HDF5 products.
void Handle_Unsupported_Dtype(bool) override
Handle unsupported HDF5 datatypes for general HDF5 products.
void Flatten_Obj_Name(bool include_attr) override
Flatten the object name for general NASA HDF5 products.
void Adjust_Dim_Name() override
Adjust dimension name for general NASA HDF5 products.
void Adjust_Obj_Name() override
Adjust object names based on different general NASA HDF5 products.
This class is a derived class of Var. It represents a special general HDF5 product(currently ACOS and...
This class represents one HDF5 dataset(CF variable)
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.