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