33 #include <sys/types.h>
41 #include <InternalErr.h>
63 using namespace HDF5CF;
66 void map_gmh5_cfdds(DDS &dds, hid_t file_id,
const string& filename){
68 BESDEBUG(
"h5",
"Coming to GM products DDS mapping function map_gmh5_cfdds() "<<endl);
70 H5GCFProduct product_type = check_product(file_id);
72 GMPattern gproduct_pattern = OTHERGMS;
77 f =
new GMFile(filename.c_str(),file_id,product_type,gproduct_pattern);
80 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate memory for GMFile ");
83 bool include_attr =
false;
118 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
119 (HDF5RequestHandler::get_srdata_mem_cache() != NULL)){
142 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
143 (HDF5RequestHandler::get_srdata_mem_cache() != NULL))
155 if(General_Product == product_type ||
156 true == HDF5RequestHandler::get_check_name_clashing())
161 if(General_Product == product_type ||
162 true == HDF5RequestHandler::get_check_name_clashing())
165 f->Handle_Hybrid_EOS5();
169 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
170 (HDF5RequestHandler::get_srdata_mem_cache() != NULL))
179 throw InternalErr(e.what());
184 gen_gmh5_cfdds(dds,f);
197 void map_gmh5_cfdas(DAS &das, hid_t file_id,
const string& filename){
199 BESDEBUG(
"h5",
"Coming to GM products DAS mapping function map_gmh5_cfdas() "<<endl);
201 H5GCFProduct product_type = check_product(file_id);
202 GMPattern gproduct_pattern = OTHERGMS;
207 f =
new GMFile(filename.c_str(),file_id,product_type,gproduct_pattern);
210 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate memory for GMFile ");
213 bool include_attr =
true;
247 if(General_Product == product_type ||
248 true == HDF5RequestHandler::get_check_name_clashing())
255 f->Handle_Hybrid_EOS5();
263 if(
true == HDF5RequestHandler::get_enable_coord_attr_add_path())
269 throw InternalErr(e.what());
274 gen_gmh5_cfdas(das,f);
290 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdds() "<<endl);
292 const vector<HDF5CF::Var *>& vars = f->
getVars();
293 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
294 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
295 const string filename = f->
getPath();
300 vector<HDF5CF::Var *>::const_iterator it_v;
301 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
302 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
306 bool dmr_64bit_support =
false;
307 if(HDF5RequestHandler::get_dmr_long_int()==
true &&
308 HDF5RequestHandler::get_dmr_64bit_int()!=NULL) {
309 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
310 if (H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
311 dmr_64bit_support =
true;
318 if(
true == dmr_64bit_support) {
327 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
328 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
330 if(need_attr_values_for_dap4(*it_v) ==
true)
332 gen_dap_onevar_dds(dds,*it_v,fileid, filename);
334 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
335 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
336 gen_dap_onegmcvar_dds(dds,*it_cv,fileid, filename);
339 for (it_spv = spvars.begin(); it_spv !=spvars.end();it_spv++) {
340 BESDEBUG(
"h5",
"variable full path= "<< (*it_spv)->getFullPath() <<endl);
341 gen_dap_onegmspvar_dds(dds,*it_spv,fileid, filename);
349 BESDEBUG(
"h5",
"Coming to GM DAS generation function gen_gmh5_cfdas() "<<endl);
353 gen_gmh5_cf_ignored_obj_info(das, f);
357 const vector<HDF5CF::Var *>& vars = f->
getVars();
358 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
359 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
360 const vector<HDF5CF::Group *>& grps = f->
getGroups();
361 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
364 vector<HDF5CF::Var *>::const_iterator it_v;
365 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
366 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
367 vector<HDF5CF::Group *>::const_iterator it_g;
368 vector<HDF5CF::Attribute *>::const_iterator it_ra;
373 if (
false == root_attrs.empty()) {
375 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
377 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
379 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra) {
381 check_update_int64_attr(
"",*it_ra);
382 gen_dap_oneobj_das(at,*it_ra,NULL);
386 if (
false == grps.empty()) {
387 for (it_g = grps.begin();
388 it_g != grps.end(); ++it_g) {
389 AttrTable *at = das.get_table((*it_g)->getNewName());
391 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
393 for (it_ra = (*it_g)->getAttributes().begin();
394 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
395 check_update_int64_attr((*it_g)->getNewName(),*it_ra);
396 gen_dap_oneobj_das(at,*it_ra,NULL);
401 for (it_v = vars.begin();
402 it_v != vars.end(); ++it_v) {
403 if (
false == ((*it_v)->getAttributes().empty())) {
409 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
413 AttrTable *at = das.get_table((*it_v)->getNewName());
415 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
417 for (it_ra = (*it_v)->getAttributes().begin();
418 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
419 gen_dap_oneobj_das(at,*it_ra,*it_v);
429 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
430 || GPM_L1 == f->getProductType())
431 update_GPM_special_attrs(das,*it_v,
false);
435 for (it_cv = cvars.begin();
436 it_cv != cvars.end(); ++it_cv) {
437 if (
false == ((*it_cv)->getAttributes().empty())) {
440 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
444 AttrTable *at = das.get_table((*it_cv)->getNewName());
446 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
448 for (it_ra = (*it_cv)->getAttributes().begin();
449 it_ra != (*it_cv)->getAttributes().end(); ++it_ra){
450 gen_dap_oneobj_das(at,*it_ra,*it_cv);
455 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
456 || GPM_L1 == f->getProductType())
457 update_GPM_special_attrs(das,*it_cv,
true);
462 for (it_spv = spvars.begin();
463 it_spv != spvars.end(); ++it_spv) {
464 if (
false == ((*it_spv)->getAttributes().empty())) {
466 AttrTable *at = das.get_table((*it_spv)->getNewName());
468 at = das.add_table((*it_spv)->getNewName(),
new AttrTable);
473 for (it_ra = (*it_spv)->getAttributes().begin();
474 it_ra != (*it_spv)->getAttributes().end(); ++it_ra)
475 gen_dap_oneobj_das(at,*it_ra,*it_spv);
482 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DAS generation function gen_gmh5_cfdas() "<<endl);
487 if(cvars.empty()==
false ){
491 bool still_has_unlimited =
false;
492 for (it_cv = cvars.begin();
493 it_cv != cvars.end(); ++it_cv) {
495 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
496 ird != (*it_cv)->getDimensions().end(); ++ird) {
501 if((*ird)->HaveUnlimitedDim() ==
true) {
502 still_has_unlimited =
true;
506 if(
true == still_has_unlimited)
510 if(
true == still_has_unlimited) {
511 AttrTable* at = das.get_table(
"DODS_EXTRA");
513 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
515 string unlimited_names;
517 for (it_cv = cvars.begin();
518 it_cv != cvars.end(); ++it_cv) {
520 bool has_unlimited_dim =
false;
523 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
524 ird != (*it_cv)->getDimensions().end(); ++ird) {
529 if((*ird)->HaveUnlimitedDim() ==
true) {
530 if(unlimited_names==
"") {
531 unlimited_names = (*ird)->getNewName();
533 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
536 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
537 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
539 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
559 BESDEBUG(
"h5",
"Coming to gen_gmh5_cf_ignored_obj_info() "<<endl);
560 AttrTable *at = das.get_table(
"Ignored_Object_Info");
562 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
569 void gen_dap_onegmcvar_dds(DDS &dds,
const HDF5CF::GMCVar* cvar,
const hid_t file_id,
const string & filename) {
571 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
578 #define HANDLE_CASE(tid,type) \
580 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
591 HANDLE_CASE(H5FSTRING, Str);
592 HANDLE_CASE(H5VSTRING, Str);
595 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
601 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
602 vector <HDF5CF::Dimension*>:: const_iterator it_d;
603 vector <size_t> dimsizes;
604 dimsizes.resize(cvar->
getRank());
605 for(
int i = 0; i <cvar->
getRank();i++)
606 dimsizes[i] = (dims[i])->getSize();
610 throw InternalErr(__FILE__,__LINE__,
"the coordinate variable cannot be a scalar");
619 bool is_latlon = cvar->isLatLon();
629 cvar->getTotalElems(),
638 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5CFArray. ");
641 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
642 if (
""==(*it_d)->getNewName())
643 ar->append_dim((*it_d)->getSize());
645 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
673 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissLLArray. ");
677 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
678 if (
""==(*it_d)->getNewName())
679 ar->append_dim((*it_d)->getSize());
681 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
690 case CV_NONLATLON_MISS:
695 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
710 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
714 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
715 if (
""==(*it_d)->getNewName())
716 ar->append_dim((*it_d)->getSize());
718 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
731 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
745 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
749 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
750 if (
""==(*it_d)->getNewName())
751 ar->append_dim((*it_d)->getSize());
753 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
767 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
780 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
781 if (
""==(*it_d)->getNewName())
782 ar->append_dim((*it_d)->getSize());
784 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
796 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
802 void gen_dap_onegmspvar_dds(DDS &dds,
const HDF5CF::GMSPVar* spvar,
const hid_t fileid,
const string & filename) {
804 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dds() "<<endl);
808 #define HANDLE_CASE(tid,type) \
810 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \
821 HANDLE_CASE(H5FSTRING, Str);
822 HANDLE_CASE(H5VSTRING, Str);
824 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
830 const vector<HDF5CF::Dimension *>& dims = spvar->
getDimensions();
831 vector <HDF5CF::Dimension*>:: const_iterator it_d;
834 throw InternalErr(__FILE__,__LINE__,
"Currently don't support scalar special variables. ");
845 spvar->getOriginalType(),
846 spvar->getStartBit(),
853 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
857 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
858 if (
""==(*it_d)->getNewName())
859 ar->append_dim((*it_d)->getSize());
861 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
875 void update_GPM_special_attrs(DAS& das,
const HDF5CF::Var *var,
bool is_cvar) {
877 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs() "<<endl);
878 if(H5FLOAT64 == var->
getType() ||
883 AttrTable *at = das.get_table(var->
getNewName());
885 at = das.add_table(var->
getNewName(),
new AttrTable);
886 bool has_fillvalue =
false;
887 AttrTable::Attr_iter it = at->attr_begin();
888 while (it!=at->attr_end() &&
false==has_fillvalue) {
889 if (at->get_name(it) ==
"_FillValue")
891 has_fillvalue =
true;
892 string fillvalue =
"";
893 if(H5FLOAT32 == var->
getType()) {
894 const string cor_fill_value =
"-9999.9";
895 fillvalue = (*at->get_attr_vector(it)->begin());
896 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
897 at->del_attr(
"_FillValue");
898 at->append_attr(
"_FillValue",
"Float32",cor_fill_value);
901 else if(H5FLOAT64 == var->
getType()) {
902 const string cor_fill_value =
"-9999.9";
903 const string exist_fill_value_substr =
"-9999.8999";
904 fillvalue = (*at->get_attr_vector(it)->begin());
905 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
906 at->del_attr(
"_FillValue");
907 at->append_attr(
"_FillValue",
"Float64",cor_fill_value);
916 if(
false == is_cvar ) {
919 if (has_fillvalue !=
true ) {
921 if(H5FLOAT32 == var->
getType())
922 at->append_attr(
"_FillValue",
"Float32",
"-9999.9");
923 else if(H5FLOAT64 == var->
getType())
924 at->append_attr(
"_FillValue",
"Float64",
"-9999.9");
925 else if (H5INT16 == var->
getType())
926 at->append_attr(
"_FillValue",
"Int16",
"-9999");
927 else if (H5CHAR == var->
getType())
928 at->append_attr(
"_FillValue",
"Int16",
"-99");
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 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 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.
virtual void Retrieve_H5_Var_Attr_Values(Var *var)
Retrieve attribute values for a variable.
const std::string & getPath() const
Obtain the path of the file.
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< Var * > & getVars() const
Public interface to obtain information of all variables.
const std::vector< Group * > & getGroups() const
Public interface to obtain all the group info.
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.
virtual void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for general HDF5 products.
virtual void Adjust_Obj_Name()
Adjust object names based on different general NASA HDF5 products.
virtual void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
void Add_Path_Coord_Attr()
Update the coordinate attribute to include path and also flatten.
virtual bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
virtual void Adjust_Dim_Name()
Adjust dimension name for general NASA HDF5 products.
void Handle_Obj_NameClashing(bool)
Handle object name clashing for general NASA HDF5 products.
void Remove_Unused_FakeDimVars()
Unsupported datatype array may generate FakeDim. Remove them.
void Update_Product_Type()
Update "product type" attributes for general HDF5 products.
virtual 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.
virtual void Handle_SpVar()
Handle special variables for general NASA HDF5 products.
virtual bool Get_IgnoredInfo_Flag()
Obtain ignored info. flag.
virtual void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for general HDF5 products.
virtual void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for general HDF5 products.
virtual const std::string & Get_Ignored_Msg()
Get the message that contains the ignored obj. info.
void Remove_Unneeded_Objects()
Remove unneeded objects.
void Add_Dim_Name()
Add dimension name.
virtual void Flatten_Obj_Name(bool include_attr)
Flatten the object name for general NASA HDF5 products.
virtual void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
virtual void Handle_DimNameClashing()
virtual void Handle_Coor_Attr()
Handle "coordinates" attributes for general HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
virtual void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
virtual void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
virtual void Handle_CVar()
Handle coordinate variables for general NASA HDF5 products.
This class is a derived class of Var. It represents a special general HDF5 product(currently ACOS and...
This class represents one HDF5 dataset(CF variable)
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.
int getCompRatio() const
Get the compression ratio of this dataset.
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.