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())
254 f->Handle_Hybrid_EOS5();
265 throw InternalErr(e.what());
270 gen_gmh5_cfdas(das,f);
286 BESDEBUG(
"h5",
"Coming to GM DDS generation function gen_gmh5_cfdds() "<<endl);
288 const vector<HDF5CF::Var *>& vars = f->
getVars();
289 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
290 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
291 const string filename = f->
getPath();
296 vector<HDF5CF::Var *>::const_iterator it_v;
297 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
298 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
300 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
301 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
303 if(need_attr_values_for_dap4(*it_v) ==
true)
305 gen_dap_onevar_dds(dds,*it_v,fileid, filename);
307 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
308 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
309 gen_dap_onegmcvar_dds(dds,*it_cv,fileid, filename);
312 for (it_spv = spvars.begin(); it_spv !=spvars.end();it_spv++) {
313 BESDEBUG(
"h5",
"variable full path= "<< (*it_spv)->getFullPath() <<endl);
314 gen_dap_onegmspvar_dds(dds,*it_spv,fileid, filename);
322 BESDEBUG(
"h5",
"Coming to GM DAS generation function gen_gmh5_cfdas() "<<endl);
326 gen_gmh5_cf_ignored_obj_info(das, f);
330 const vector<HDF5CF::Var *>& vars = f->
getVars();
331 const vector<HDF5CF::GMCVar *>& cvars = f->getCVars();
332 const vector<HDF5CF::GMSPVar *>& spvars = f->getSPVars();
333 const vector<HDF5CF::Group *>& grps = f->
getGroups();
334 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
337 vector<HDF5CF::Var *>::const_iterator it_v;
338 vector<HDF5CF::GMCVar *>::const_iterator it_cv;
339 vector<HDF5CF::GMSPVar *>::const_iterator it_spv;
340 vector<HDF5CF::Group *>::const_iterator it_g;
341 vector<HDF5CF::Attribute *>::const_iterator it_ra;
346 if (
false == root_attrs.empty()) {
348 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
350 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
352 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra) {
354 check_update_int64_attr(
"",*it_ra);
355 gen_dap_oneobj_das(at,*it_ra,NULL);
359 if (
false == grps.empty()) {
360 for (it_g = grps.begin();
361 it_g != grps.end(); ++it_g) {
362 AttrTable *at = das.get_table((*it_g)->getNewName());
364 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
366 for (it_ra = (*it_g)->getAttributes().begin();
367 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
368 check_update_int64_attr((*it_g)->getNewName(),*it_ra);
369 gen_dap_oneobj_das(at,*it_ra,NULL);
374 for (it_v = vars.begin();
375 it_v != vars.end(); ++it_v) {
376 if (
false == ((*it_v)->getAttributes().empty())) {
382 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
386 AttrTable *at = das.get_table((*it_v)->getNewName());
388 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
390 for (it_ra = (*it_v)->getAttributes().begin();
391 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
392 gen_dap_oneobj_das(at,*it_ra,*it_v);
402 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
403 || GPM_L1 == f->getProductType())
404 update_GPM_special_attrs(das,*it_v,
false);
408 for (it_cv = cvars.begin();
409 it_cv != cvars.end(); ++it_cv) {
410 if (
false == ((*it_cv)->getAttributes().empty())) {
413 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
417 AttrTable *at = das.get_table((*it_cv)->getNewName());
419 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
421 for (it_ra = (*it_cv)->getAttributes().begin();
422 it_ra != (*it_cv)->getAttributes().end(); ++it_ra){
423 gen_dap_oneobj_das(at,*it_ra,*it_cv);
428 if(GPMS_L3 == f->getProductType() || GPMM_L3 == f->getProductType()
429 || GPM_L1 == f->getProductType())
430 update_GPM_special_attrs(das,*it_cv,
true);
435 for (it_spv = spvars.begin();
436 it_spv != spvars.end(); ++it_spv) {
437 if (
false == ((*it_spv)->getAttributes().empty())) {
439 AttrTable *at = das.get_table((*it_spv)->getNewName());
441 at = das.add_table((*it_spv)->getNewName(),
new AttrTable);
446 for (it_ra = (*it_spv)->getAttributes().begin();
447 it_ra != (*it_spv)->getAttributes().end(); ++it_ra)
448 gen_dap_oneobj_das(at,*it_ra,*it_spv);
455 BESDEBUG(
"h5",
"Find unlimited dimension in the GM DAS generation function gen_gmh5_cfdas() "<<endl);
464 bool still_has_unlimited =
false;
465 for (it_cv = cvars.begin();
466 it_cv != cvars.end(); ++it_cv) {
468 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
469 ird != (*it_cv)->getDimensions().end(); ++ird) {
474 if((*ird)->HaveUnlimitedDim() ==
true) {
475 still_has_unlimited =
true;
479 if(
true == still_has_unlimited)
483 if(
true == still_has_unlimited) {
484 AttrTable* at = das.get_table(
"DODS_EXTRA");
486 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
488 string unlimited_names;
490 for (it_cv = cvars.begin();
491 it_cv != cvars.end(); ++it_cv) {
493 bool has_unlimited_dim =
false;
496 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
497 ird != (*it_cv)->getDimensions().end(); ++ird) {
502 if((*ird)->HaveUnlimitedDim() ==
true) {
503 if(unlimited_names==
"") {
504 unlimited_names = (*ird)->getNewName();
506 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
509 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
510 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
512 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
532 BESDEBUG(
"h5",
"Coming to gen_gmh5_cf_ignored_obj_info() "<<endl);
533 AttrTable *at = das.get_table(
"Ignored_Object_Info");
535 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
542 void gen_dap_onegmcvar_dds(DDS &dds,
const HDF5CF::GMCVar* cvar,
const hid_t file_id,
const string & filename) {
544 BESDEBUG(
"h5",
"Coming to gen_dap_onegmcvar_dds() "<<endl);
551 #define HANDLE_CASE(tid,type) \ 553 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \ 564 HANDLE_CASE(H5FSTRING, Str);
565 HANDLE_CASE(H5VSTRING, Str);
568 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
574 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
575 vector <HDF5CF::Dimension*>:: const_iterator it_d;
576 vector <size_t> dimsizes;
577 dimsizes.resize(cvar->
getRank());
578 for(
int i = 0; i <cvar->
getRank();i++)
579 dimsizes[i] = (dims[i])->getSize();
583 throw InternalErr(__FILE__,__LINE__,
"the coordinate variable cannot be a scalar");
592 bool is_latlon = cvar->isLatLon();
602 cvar->getTotalElems(),
611 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5CFArray. ");
614 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
615 if (
""==(*it_d)->getNewName())
616 ar->append_dim((*it_d)->getSize());
618 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
646 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissLLArray. ");
650 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
651 if (
""==(*it_d)->getNewName())
652 ar->append_dim((*it_d)->getSize());
654 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
663 case CV_NONLATLON_MISS:
668 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
683 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
687 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
688 if (
""==(*it_d)->getNewName())
689 ar->append_dim((*it_d)->getSize());
691 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
704 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
718 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
722 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
723 if (
""==(*it_d)->getNewName())
724 ar->append_dim((*it_d)->getSize());
726 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
740 throw InternalErr(__FILE__, __LINE__,
"The rank of special coordinate variable must be 1");
753 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
754 if (
""==(*it_d)->getNewName())
755 ar->append_dim((*it_d)->getSize());
757 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
769 throw InternalErr(__FILE__,__LINE__,
"Coordinate variable type is not supported.");
775 void gen_dap_onegmspvar_dds(DDS &dds,
const HDF5CF::GMSPVar* spvar,
const hid_t fileid,
const string & filename) {
777 BESDEBUG(
"h5",
"Coming to gen_dap_onegmspvar_dds() "<<endl);
781 #define HANDLE_CASE(tid,type) \ 783 bt = new (type)(spvar->getNewName(),spvar->getFullPath()); \ 794 HANDLE_CASE(H5FSTRING, Str);
795 HANDLE_CASE(H5VSTRING, Str);
797 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
803 const vector<HDF5CF::Dimension *>& dims = spvar->
getDimensions();
804 vector <HDF5CF::Dimension*>:: const_iterator it_d;
807 throw InternalErr(__FILE__,__LINE__,
"Currently don't support scalar special variables. ");
818 spvar->getOriginalType(),
819 spvar->getStartBit(),
826 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate HDF5GMCFMissNonLLCVArray. ");
830 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
831 if (
""==(*it_d)->getNewName())
832 ar->append_dim((*it_d)->getSize());
834 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
848 void update_GPM_special_attrs(DAS& das,
const HDF5CF::Var *var,
bool is_cvar) {
850 BESDEBUG(
"h5",
"Coming to update_GPM_special_attrs() "<<endl);
851 if(H5FLOAT64 == var->
getType() ||
856 AttrTable *at = das.get_table(var->
getNewName());
858 at = das.add_table(var->
getNewName(),
new AttrTable);
859 bool has_fillvalue =
false;
860 AttrTable::Attr_iter it = at->attr_begin();
861 while (it!=at->attr_end() &&
false==has_fillvalue) {
862 if (at->get_name(it) ==
"_FillValue")
864 has_fillvalue =
true;
865 string fillvalue =
"";
866 if(H5FLOAT32 == var->
getType()) {
867 const string cor_fill_value =
"-9999.9";
868 fillvalue = (*at->get_attr_vector(it)->begin());
869 if((fillvalue.find(cor_fill_value) == 0) && (fillvalue!= cor_fill_value)) {
870 at->del_attr(
"_FillValue");
871 at->append_attr(
"_FillValue",
"Float32",cor_fill_value);
874 else if(H5FLOAT64 == var->
getType()) {
875 const string cor_fill_value =
"-9999.9";
876 const string exist_fill_value_substr =
"-9999.8999";
877 fillvalue = (*at->get_attr_vector(it)->begin());
878 if((fillvalue.find(exist_fill_value_substr) == 0) && (fillvalue!= cor_fill_value)) {
879 at->del_attr(
"_FillValue");
880 at->append_attr(
"_FillValue",
"Float64",cor_fill_value);
889 if(
false == is_cvar ) {
892 if (has_fillvalue !=
true ) {
894 if(H5FLOAT32 == var->
getType())
895 at->append_attr(
"_FillValue",
"Float32",
"-9999.9");
896 else if(H5FLOAT64 == var->
getType())
897 at->append_attr(
"_FillValue",
"Float64",
"-9999.9");
898 else if (H5INT16 == var->
getType())
899 at->append_attr(
"_FillValue",
"Int16",
"-9999");
900 else if (H5CHAR == var->
getType())
901 at->append_attr(
"_FillValue",
"Int16",
"-99");
This class provides a way to map HDF5 Str to DAP Str for the CF option.
void Flatten_Obj_Name(bool include_attr)
Flatten the object name for general NASA HDF5 products.
This class specifies the retrieval of the missing lat/lon values for general HDF5 products.
void Handle_SpVar()
Handle special variables for general NASA HDF5 products.
H5GCFProduct getPtType() const
Get the data type of this variable.
const std::string & getFullPath() const
Get the full path of this variable.
This class represents one HDF5 dataset(CF variable)
const std::string & Get_Ignored_Msg()
Get the message that contains the ignored obj. info.
void Handle_Coor_Attr()
Handle "coordinates" attributes for general HDF5 products.
void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for general HDF5 products.
void Handle_CVar()
Handle coordinate variables for general NASA HDF5 products.
void Handle_Grid_Mapping_Vars()
Handle Grid Mapping Vars.
const std::string & getNewName() const
Get the new name of this variable.
void Handle_DimNameClashing()
void Add_Dim_Name()
Add dimension name.
This class provides a way to map HDF5 unsigned 16-bit integer to DAP uint16 for the CF option.
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain information of all attributes under the root group.
void Handle_Obj_NameClashing(bool)
Handle object name clashing for general NASA HDF5 products.
This class provides a way to map HDF5 float to DAP float for the CF option.
This class is a derived class of Var. It represents a special general HDF5 product(currently ACOS and...
int getCompRatio() const
Get the compression ratio of this dataset.
This class is a derived class of CVar. It represents a coordinate variable for general HDF5 files.
int getRank() const
Get the dimension rank of this variable.
hid_t getFileID() const
Obtain the HDF5 file ID.
This class specifies the retrieval of the missing lat/lon values for general HDF5 products.
This class provides a way to map HDF5 int16 to DAP int16 for the CF option.
const std::vector< Var * > & getVars() const
Public interface to obtain information of all variables.
void Remove_Unused_FakeDimVars()
Unsupported datatype array may generate FakeDim. Remove them.
bool HaveUnlimitedDim() const
Has unlimited dimensions.
Map and generate DDS and DAS for the CF option for generic HDF5 products.
void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for general HDF5 products.
This class provides a way to map HDF5 64-bit floating-point(double) to DAP 64-bit floating-point for ...
bool Have_Grid_Mapping_Attrs()
Check if having Grid Mapping Attrs.
This class is a derived class of File. It includes methods applied to general HDF5 files only.
CVType getCVType() const
Get the coordinate variable type of this variable.
void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for general HDF5 products.
void Adjust_Dim_Name()
Adjust dimension name for general NASA HDF5 products.
include the entry functions to execute the handlers
This class specifies the retrieval of data values for special HDF5 products Currently this only appli...
void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for general HDF5 products.
const std::vector< Dimension * > & getDimensions() const
Get the list of the dimensions.
This class provides a way to map HDF5 32-bit integer to DAP Int32 for the CF option.
H5DataType getType() const
Get the data type of this variable(Not HDF5 datatype id)
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
virtual void Retrieve_H5_Var_Attr_Values(Var *var)
Retrieve attribute values for a variable.
void Remove_Unneeded_Objects()
Remove unneeded objects.
void Update_Product_Type()
Update "product type" attributes for general HDF5 products.
Helper functions for generating DAS attributes and a function to check BES Key.
This class provides a way to map HDF5 unsigned 32-bit integer to DAP uint32 for the CF option.
bool Get_IgnoredInfo_Flag()
Obtain ignored info. flag.
const std::vector< Group * > & getGroups() const
Public interface to obtain all the group info.
void Adjust_Obj_Name()
Adjust object names based on different general NASA HDF5 products.
This class specifies the retrieval of the values of non-lat/lon coordinate variables for general HDF5...
This class provides a way to map HDF5 byte to DAP byte for the CF option.
void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
const std::string & getPath() const
Obtain the path of the file.
void Add_Supplement_Attrs(bool)
Add supplemental attributes such as fullpath and original name for general NASA HDF5 products.
void Rename_NC4_NonCoordVars()
Remove the _nc4_non_coord from the variable new names.
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.