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();
266 throw InternalErr(e.what());
271 gen_gmh5_cfdas(das,f);
287 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdds() "<<endl);
289 const vector<HDF5CF::Var *>& vars = f->
getVars();
290 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
291 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
292 const string filename = f->
getPath();
297 vector<HDF5CF::Var *>::const_iterator it_v;
298 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
299 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
301 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
302 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
304 if(need_attr_values_for_dap4(*it_v) ==
true)
306 gen_dap_onevar_dds(dds,*it_v,fileid, filename);
308 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
309 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
310 gen_dap_onegmcvar_dds(dds,*it_cv,fileid, filename);
313 for (it_spv = spvars.begin(); it_spv !=spvars.end();it_spv++) {
314 BESDEBUG(
"h5",
"variable full path= "<< (*it_spv)->getFullPath() <<endl);
315 gen_dap_onegmspvar_dds(dds,*it_spv,fileid, filename);
323 BESDEBUG(
"h5",
"Coming to GM DAS generation function gen_gmh5_cfdas() "<<endl);
327 gen_gmh5_cf_ignored_obj_info(das, f);
331 const vector<HDF5CF::Var *>& vars = f->
getVars();
332 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
333 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
334 const vector<HDF5CF::Group *>& grps = f->
getGroups();
335 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
338 vector<HDF5CF::Var *>::const_iterator it_v;
339 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
340 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
341 vector<HDF5CF::Group *>::const_iterator it_g;
342 vector<HDF5CF::Attribute *>::const_iterator it_ra;
347 if (
false == root_attrs.empty()) {
349 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
351 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
353 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra) {
355 check_update_int64_attr(
"",*it_ra);
356 gen_dap_oneobj_das(at,*it_ra,NULL);
360 if (
false == grps.empty()) {
361 for (it_g = grps.begin();
362 it_g != grps.end(); ++it_g) {
363 AttrTable *at = das.get_table((*it_g)->getNewName());
365 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
367 for (it_ra = (*it_g)->getAttributes().begin();
368 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
369 check_update_int64_attr((*it_g)->getNewName(),*it_ra);
370 gen_dap_oneobj_das(at,*it_ra,NULL);
375 for (it_v = vars.begin();
376 it_v != vars.end(); ++it_v) {
377 if (
false == ((*it_v)->getAttributes().empty())) {
383 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
387 AttrTable *at = das.get_table((*it_v)->getNewName());
389 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
391 for (it_ra = (*it_v)->getAttributes().begin();
392 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
393 gen_dap_oneobj_das(at,*it_ra,*it_v);
403 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
404 || GPM_L1 == f->getProductType())
405 update_GPM_special_attrs(das,*it_v,
false);
409 for (it_cv = cvars.begin();
410 it_cv != cvars.end(); ++it_cv) {
411 if (
false == ((*it_cv)->getAttributes().empty())) {
414 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
418 AttrTable *at = das.get_table((*it_cv)->getNewName());
420 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
422 for (it_ra = (*it_cv)->getAttributes().begin();
423 it_ra != (*it_cv)->getAttributes().end(); ++it_ra){
424 gen_dap_oneobj_das(at,*it_ra,*it_cv);
429 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
430 || GPM_L1 == f->getProductType())
431 update_GPM_special_attrs(das,*it_cv,
true);
436 for (it_spv = spvars.begin();
437 it_spv != spvars.end(); ++it_spv) {
438 if (
false == ((*it_spv)->getAttributes().empty())) {
440 AttrTable *at = das.get_table((*it_spv)->getNewName());
442 at = das.add_table((*it_spv)->getNewName(),
new AttrTable);
447 for (it_ra = (*it_spv)->getAttributes().begin();
448 it_ra != (*it_spv)->getAttributes().end(); ++it_ra)
449 gen_dap_oneobj_das(at,*it_ra,*it_spv);
456 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DAS generation function gen_gmh5_cfdas() "<<endl);
465 bool still_has_unlimited =
false;
466 for (it_cv = cvars.begin();
467 it_cv != cvars.end(); ++it_cv) {
469 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
470 ird != (*it_cv)->getDimensions().end(); ++ird) {
475 if((*ird)->HaveUnlimitedDim() ==
true) {
476 still_has_unlimited =
true;
480 if(
true == still_has_unlimited)
484 if(
true == still_has_unlimited) {
485 AttrTable* at = das.get_table(
"DODS_EXTRA");
487 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
489 string unlimited_names;
491 for (it_cv = cvars.begin();
492 it_cv != cvars.end(); ++it_cv) {
494 bool has_unlimited_dim =
false;
497 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
498 ird != (*it_cv)->getDimensions().end(); ++ird) {
503 if((*ird)->HaveUnlimitedDim() ==
true) {
504 if(unlimited_names==
"") {
505 unlimited_names = (*ird)->getNewName();
507 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
510 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
511 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
513 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
533 BESDEBUG(
"h5",
"Coming to gen_gmh5_cf_ignored_obj_info() "<<endl);
534 AttrTable *at = das.get_table(
"Ignored_Object_Info");
536 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
543 void gen_dap_onegmcvar_dds(DDS &dds,
const HDF5CF::GMCVar* cvar,
const hid_t file_id,
const string & filename) {
545 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
552 #define HANDLE_CASE(tid,type) \
554 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
565 HANDLE_CASE(H5FSTRING, Str);
566 HANDLE_CASE(H5VSTRING, Str);
569 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
575 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
576 vector <HDF5CF::Dimension*>:: const_iterator it_d;
577 vector <size_t> dimsizes;
578 dimsizes.resize(cvar->
getRank());
579 for(
int i = 0; i <cvar->
getRank();i++)
580 dimsizes[i] = (dims[i])->getSize();
584 throw InternalErr(__FILE__,__LINE__,
"the coordinate variable cannot be a scalar");
593 bool is_latlon = cvar->isLatLon();
603 cvar->getTotalElems(),
612 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5CFArray. ");
615 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
616 if (
""==(*it_d)->getNewName())
617 ar->append_dim((*it_d)->getSize());
619 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
647 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissLLArray. ");
651 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
652 if (
""==(*it_d)->getNewName())
653 ar->append_dim((*it_d)->getSize());
655 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
664 case CV_NONLATLON_MISS:
669 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
684 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
688 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
689 if (
""==(*it_d)->getNewName())
690 ar->append_dim((*it_d)->getSize());
692 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
705 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
719 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
723 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
724 if (
""==(*it_d)->getNewName())
725 ar->append_dim((*it_d)->getSize());
727 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
741 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
754 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
755 if (
""==(*it_d)->getNewName())
756 ar->append_dim((*it_d)->getSize());
758 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
770 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
776 void gen_dap_onegmspvar_dds(DDS &dds,
const HDF5CF::GMSPVar* spvar,
const hid_t fileid,
const string & filename) {
778 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dds() "<<endl);
782 #define HANDLE_CASE(tid,type) \
784 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \
795 HANDLE_CASE(H5FSTRING, Str);
796 HANDLE_CASE(H5VSTRING, Str);
798 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
804 const vector<HDF5CF::Dimension *>& dims = spvar->
getDimensions();
805 vector <HDF5CF::Dimension*>:: const_iterator it_d;
808 throw InternalErr(__FILE__,__LINE__,
"Currently don't support scalar special variables. ");
819 spvar->getOriginalType(),
820 spvar->getStartBit(),
827 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
831 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
832 if (
""==(*it_d)->getNewName())
833 ar->append_dim((*it_d)->getSize());
835 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
849 void update_GPM_special_attrs(DAS& das,
const HDF5CF::Var *var,
bool is_cvar) {
851 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs() "<<endl);
852 if(H5FLOAT64 == var->
getType() ||
857 AttrTable *at = das.get_table(var->
getNewName());
859 at = das.add_table(var->
getNewName(),
new AttrTable);
860 bool has_fillvalue =
false;
861 AttrTable::Attr_iter it = at->attr_begin();
862 while (it!=at->attr_end() &&
false==has_fillvalue) {
863 if (at->get_name(it) ==
"_FillValue")
865 has_fillvalue =
true;
866 string fillvalue =
"";
867 if(H5FLOAT32 == var->
getType()) {
868 const string cor_fill_value =
"-9999.9";
869 fillvalue = (*at->get_attr_vector(it)->begin());
870 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
871 at->del_attr(
"_FillValue");
872 at->append_attr(
"_FillValue",
"Float32",cor_fill_value);
875 else if(H5FLOAT64 == var->
getType()) {
876 const string cor_fill_value =
"-9999.9";
877 const string exist_fill_value_substr =
"-9999.8999";
878 fillvalue = (*at->get_attr_vector(it)->begin());
879 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
880 at->del_attr(
"_FillValue");
881 at->append_attr(
"_FillValue",
"Float64",cor_fill_value);
890 if(
false == is_cvar ) {
893 if (has_fillvalue !=
true ) {
895 if(H5FLOAT32 == var->
getType())
896 at->append_attr(
"_FillValue",
"Float32",
"-9999.9");
897 else if(H5FLOAT64 == var->
getType())
898 at->append_attr(
"_FillValue",
"Float64",
"-9999.9");
899 else if (H5INT16 == var->
getType())
900 at->append_attr(
"_FillValue",
"Int16",
"-9999");
901 else if (H5CHAR == var->
getType())
902 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.
void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for general HDF5 products.
void Adjust_Obj_Name()
Adjust object names based on different general NASA HDF5 products.
void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
void Adjust_Dim_Name()
Adjust dimension name for general NASA HDF5 products.
void Handle_Obj_NameClashing(bool)
Handle object name clashing for general NASA HDF5 products.
void Remove_Unused_FakeDimVars()
Unsupported datatype array may generate FakeDim. Remove them.
void Update_Product_Type()
Update "product type" attributes for general HDF5 products.
void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr)
Retrieve DDS information from the HDF5 file; real implementation for general HDF5 products.
bool Get_IgnoredInfo_Flag()
Obtain ignored info. flag.
const std::string & Get_Ignored_Msg()
Get the message that contains the ignored obj. info.
void Handle_SpVar()
Handle special variables for general NASA HDF5 products.
void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for general HDF5 products.
void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for general HDF5 products.
void Remove_Unneeded_Objects()
Remove unneeded objects.
void Add_Dim_Name()
Add dimension name.
void Flatten_Obj_Name(bool include_attr)
Flatten the object name for general NASA HDF5 products.
void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
void Handle_DimNameClashing()
void Handle_Coor_Attr()
Handle "coordinates" attributes for general HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
void Handle_CVar()
Handle coordinate variables for general NASA HDF5 products.
This class is a derived class of Var. It represents a special general HDF5 product(currently ACOS and...
This class represents one HDF5 dataset(CF variable)
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.