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");