32 #include "config_hdf5.h"
34 #include <sys/types.h>
61 #include "he5dds.tab.hh"
64 #include "he5das.tab.hh"
66 struct yy_buffer_state;
68 yy_buffer_state *he5dds_scan_string(
const char *str);
70 int he5dasparse(libdap::parser_arg *arg);
71 int he5ddslex_destroy();
72 int he5daslex_destroy();
77 using namespace HDF5CF;
80 void map_eos5_cfdds(DDS &dds, hid_t file_id,
const string & filename) {
82 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
90 string product_str=
"";
95 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
98 "unable to obtain the HDF-EOS5 struct metadata ";
99 throw InternalErr(__FILE__, __LINE__, msg);
102 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
107 f =
new EOS5File(filename.c_str(),file_id);
110 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
113 bool include_attr =
false;
121 he5dds_scan_string(st_str.c_str());
126 p.add_projparams(st_str);
132 if (c.check_grids_unknown_parameters(&p)) {
133 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
136 if (c.check_grids_missing_projcode(&p)) {
137 throw InternalErr(
"The HDF-EOS5 is missing project code ");
141 if (c.check_grids_support_projcode(&p)) {
142 throw InternalErr(
"The current project code is not supported");
146 c.set_grids_missing_pixreg_orig(&p);
149 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
167 throw InternalErr(e.what());
193 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
194 (HDF5RequestHandler::get_srdata_mem_cache() != NULL)){
221 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
222 (HDF5RequestHandler::get_srdata_mem_cache() != NULL))
233 if(
true == is_check_nameclashing)
241 if(
true == is_check_nameclashing)
253 throw InternalErr(e.what());
258 gen_eos5_cfdds(dds,f);
271 void map_eos5_cfdas(DAS &das, hid_t file_id,
const string &filename) {
273 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS mapping function map_eos5_cfdas "<<endl);
278 string subset_str=
"";
279 string product_str=
"";
280 string other_str =
"";
283 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
286 "unable to obtain the HDF-EOS5 struct metadata ";
287 throw InternalErr(__FILE__, __LINE__, msg);
290 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
292 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
296 f =
new EOS5File(filename.c_str(),file_id);
299 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
301 bool include_attr =
true;
308 he5dds_scan_string(st_str.c_str());
312 p.add_projparams(st_str);
318 if (c.check_grids_unknown_parameters(&p)) {
319 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
322 if (c.check_grids_missing_projcode(&p)) {
323 throw InternalErr(
"The HDF-EOS5 is missing project code ");
325 if (c.check_grids_support_projcode(&p)) {
326 throw InternalErr(
"The current project code is not supported");
328 c.set_grids_missing_pixreg_orig(&p);
330 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
340 throw InternalErr(e.what());
372 if (
true == is_check_nameclashing)
392 throw InternalErr(e.what());
397 gen_eos5_cfdas(das,file_id,f);
413 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function gen_eos5_cfdds "<<endl);
414 const vector<HDF5CF::Var *>& vars = f->
getVars();
415 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
416 const string filename = f->
getPath();
420 vector<HDF5CF::Var *>::const_iterator it_v;
421 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
423 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
424 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
425 gen_dap_onevar_dds(dds,*it_v,file_id,filename);
428 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
429 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
430 gen_dap_oneeos5cvar_dds(dds,*it_cv,file_id,filename);
437 unsigned short cv_lat_miss_index = 1;
438 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
439 if((*it_cv)->getCVType() == CV_LAT_MISS) {
440 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
444 gen_dap_oneeos5cf_dds(dds,*it_cv);
445 add_cf_grid_mapinfo_var(dds,(*it_cv)->getProjCode(),cv_lat_miss_index);
454 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_dds() "<<endl);
456 float cv_point_lower = cvar->getPointLower();
457 float cv_point_upper = cvar->getPointUpper();
458 float cv_point_left = cvar->getPointLeft();
459 float cv_point_right = cvar->getPointRight();
460 EOS5GridPCType cv_proj_code = cvar->getProjCode();
461 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
463 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
464 add_cf_grid_cvs(dds,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
468 void gen_dap_oneeos5cf_das(DAS &das,
const vector<HDF5CF::Var*>& vars,
const HDF5CF::EOS5CVar* cvar,
const unsigned short g_suffix) {
470 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_das() "<<endl);
472 float cv_point_lower = cvar->getPointLower();
473 float cv_point_upper = cvar->getPointUpper();
474 float cv_point_left = cvar->getPointLeft();
475 float cv_point_right = cvar->getPointRight();
477 EOS5GridPCType cv_proj_code = cvar->getProjCode();
478 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
481 cerr<<
"cv_point_lower is "<<cv_point_lower <<endl;
482 cerr<<
"cvar name is "<<cvar->
getName() <<endl;
483 for(vector<HDF5CF::Dimension*>::const_iterator it_d = dims.begin(); it_d != dims.end(); ++it_d)
484 cerr<<
"dim name das is "<<(*it_d)->getNewName() <<endl;
488 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
490 add_cf_grid_cv_attrs(das,vars,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims,cvar->getParams(),g_suffix);
492 add_cf_grid_cv_attrs(das,vars,cv_proj_code,dims,cvar->getParams(),g_suffix);
499 BESDEBUG(
"h5",
"Coming to gen_eos5_cf_ignored_obj_info() "<<endl);
500 AttrTable *at = das.get_table(
"Ignored_Object_Info");
502 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
510 void gen_dap_oneeos5cvar_dds(DDS &dds,
const HDF5CF::EOS5CVar* cvar,
const hid_t file_id,
const string & filename) {
512 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dds() "<<endl);
519 #define HANDLE_CASE(tid,type) \
521 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
532 HANDLE_CASE(H5FSTRING,
Str);
533 HANDLE_CASE(H5VSTRING,
Str);
535 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
541 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
542 vector <HDF5CF::Dimension*>:: const_iterator it_d;
543 vector <size_t> dimsizes;
544 dimsizes.resize(cvar->
getRank());
545 for(
int i = 0; i <cvar->
getRank();i++)
546 dimsizes[i] = (dims[i])->getSize();
550 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
557 for(vector<HDF5CF::Attribute *>::const_iterator it_ra = cvar->getAttributes().begin();
558 it_ra != cvar->getAttributes().end(); ++it_ra) {
559 cerr<<
"cvar attribute name is "<<(*it_ra)->getNewName() <<endl;
560 cerr<<
"cvar attribute value type is "<<(*it_ra)->getType() <<endl;
562 cerr<<
"cvar new name exist at he s5cfdap.cc is "<<cvar->
getNewName() <<endl;
564 bool is_latlon = cvar->isLatLon();
574 cvar->getTotalElems(),
583 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
586 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
587 if (
""==(*it_d)->getNewName())
588 ar->append_dim((*it_d)->getSize());
590 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
606 cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
607 cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
608 cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
616 cvar->getPointLower(),
617 cvar->getPointUpper(),
618 cvar->getPointLeft(),
619 cvar->getPointRight(),
633 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissLLArray.");
636 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
637 if (
""==(*it_d)->getNewName())
638 ar->append_dim((*it_d)->getSize());
640 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
649 case CV_NONLATLON_MISS:
654 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
668 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissNonLLCVArray.");
672 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
673 if (
""==(*it_d)->getNewName())
674 ar->append_dim((*it_d)->getSize());
676 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
692 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
710 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
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());
728 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
738 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS generation function gen_eos5_cfdas "<<endl);
742 gen_eos5_cf_ignored_obj_info(das, f);
746 const vector<HDF5CF::Var *>& vars = f->
getVars();
747 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
748 const vector<HDF5CF::Group *>& grps = f->
getGroups();
749 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
751 vector<HDF5CF::Var *>::const_iterator it_v;
752 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
753 vector<HDF5CF::Group *>::const_iterator it_g;
754 vector<HDF5CF::Attribute *>::const_iterator it_ra;
758 if (
false == root_attrs.empty()) {
759 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
761 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
763 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); it_ra++) {
764 gen_dap_oneobj_das(at,*it_ra,NULL);
768 if (
false == grps.empty()) {
769 for (it_g = grps.begin();
770 it_g != grps.end(); ++it_g) {
771 AttrTable *at = das.get_table((*it_g)->getNewName());
773 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
775 for (it_ra = (*it_g)->getAttributes().begin();
776 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
779 if((*it_ra)->getNewName()==
"Conventions" &&((*it_g)->getNewName() ==
"HDFEOS_ADDITIONAL_FILE_ATTRIBUTES")
780 && (
true==HDF5RequestHandler::get_eos5_rm_convention_attr_path())) {
781 AttrTable *at_das = das.get_table(FILE_ATTR_TABLE_NAME);
783 at_das = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
784 gen_dap_oneobj_das(at_das,*it_ra,NULL);
787 gen_dap_oneobj_das(at,*it_ra,NULL);
792 for (it_v = vars.begin();
793 it_v != vars.end(); ++it_v) {
794 if (
false == ((*it_v)->getAttributes().empty())) {
797 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
801 AttrTable *at = das.get_table((*it_v)->getNewName());
803 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
805 for (it_ra = (*it_v)->getAttributes().begin();
806 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
807 gen_dap_oneobj_das(at,*it_ra,*it_v);
812 for (it_cv = cvars.begin(); it_cv !=cvars.end();it_cv++) {
814 if (
false == ((*it_cv)->getAttributes().empty())) {
817 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
821 AttrTable *at = das.get_table((*it_cv)->getNewName());
823 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
826 for (it_ra = (*it_cv)->getAttributes().begin();
827 it_ra != (*it_cv)->getAttributes().end(); ++it_ra) {
828 gen_dap_oneobj_das(at,*it_ra,*it_cv);
834 unsigned short cv_lat_miss_index = 1;
836 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
837 if((*it_cv)->getCVType() == CV_LAT_MISS) {
838 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
839 gen_dap_oneeos5cf_das(das,vars,*it_cv,cv_lat_miss_index);
845 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
846 if((*it_cv)->getProjCode() == HE5_GCTP_LAMAZ) {
847 if((*it_cv)->getCVType() == CV_LAT_MISS || (*it_cv)->getCVType() == CV_LON_MISS) {
848 AttrTable *at = das.get_table((*it_cv)->getNewName());
850 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
851 if((*it_cv)->getCVType() == CV_LAT_MISS)
852 add_ll_valid_range(at,
true);
854 add_ll_valid_range(at,
false);
860 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
862 if(disable_ecsmetadata ==
false) {
871 string subset_str=
"";
872 string product_str=
"";
873 string other_str =
"";
874 bool st_only =
false;
876 read_ecs_metadata(file_id, st_str, core_str, arch_str, xml_str,
877 subset_str, product_str, other_str, st_only);
880 if(st_str!=
"")
"h5",
"Final structmetadata "<<st_str <<endl;
881 if(core_str!=
"")
"h5",
"Final coremetadata "<<core_str <<endl;
882 if(arch_str!=
"")
"h5",
"Final archivedmetadata "<<arch_str <<endl;
883 if(xml_str!=
"")
"h5",
"Final xmlmetadata "<<xml_str <<endl;
884 if(subset_str!=
"")
"h5",
"Final subsetmetadata "<<subset_str <<endl;
885 if(product_str!=
"")
"h5",
"Final productmetadata "<<product_str <<endl;
886 if(other_str!=
"")
"h5",
"Final othermetadata "<<other_str <<endl;
892 string check_disable_smetadata_key =
"H5.DisableStructMetaAttr";
893 bool is_check_disable_smetadata =
false;
894 is_check_disable_smetadata = HDF5CFDAPUtil::check_beskeys(check_disable_smetadata_key);
896 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
898 if (
false == is_check_disable_smetadata) {
900 AttrTable *at = das.get_table(
"StructMetadata");
902 at = das.add_table(
"StructMetadata",
new AttrTable);
906 if (he5dasparse(&arg) != 0
907 ||
false == arg.status()){
909 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
910 <<
"StructMetadata " <<
" HDFEOS attribute" << endl);
919 AttrTable *at = das.get_table(
"CoreMetadata");
921 at = das.add_table(
"CoreMetadata",
new AttrTable);
924 if (he5dasparse(&arg) != 0
925 ||
false == arg.status()){
927 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
928 <<
"CoreMetadata " <<
" HDFEOS attribute" << endl);
934 AttrTable *at = das.get_table(
"ArchiveMetadata");
936 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
939 if (he5dasparse(&arg) != 0
940 ||
false == arg.status()){
942 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
943 <<
"ArchiveMetadata " <<
" HDFEOS attribute" << endl);
952 AttrTable *at = das.get_table(
"XMLMetadata");
954 at = das.add_table(
"XMLMetadata",
new AttrTable);
955 HDF5CFDAPUtil::replace_double_quote(xml_str);
956 at->append_attr(
"Contents",
"String",xml_str);
962 if(subset_str !=
""){
963 AttrTable *at = das.get_table(
"SubsetMetadata");
965 at = das.add_table(
"SubsetMetadata",
new AttrTable);
968 if (he5dasparse(&arg) != 0
969 ||
false == arg.status()) {
971 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
972 <<
"SubsetMetadata " <<
" HDFEOS attribute" << endl);
976 if(product_str !=
""){
977 AttrTable *at = das.get_table(
"ProductMetadata");
979 at = das.add_table(
"ProductMetadata",
new AttrTable);
982 if (he5dasparse(&arg) != 0
983 ||
false == arg.status()){
984 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
985 <<
"ProductMetadata " <<
" HDFEOS attribute" << endl);
993 if (other_str !=
""){
994 AttrTable *at = das.get_table(
"OtherMetadata");
996 at = das.add_table(
"OtherMetadata",
new AttrTable);
997 at->append_attr(
"Contents",
"String",other_str);
1004 AttrTable *at = das.get_table(
"DODS_EXTRA");
1006 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
1007 string unlimited_names;
1009 for (it_cv = cvars.begin();
1010 it_cv != cvars.end(); it_cv++) {
1012 bool has_unlimited_dim =
false;
1015 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
1016 ird != (*it_cv)->getDimensions().end(); ++ird) {
1021 if((*ird)->HaveUnlimitedDim() ==
true) {
1023 if(unlimited_names==
"") {
1024 unlimited_names = (*ird)->getNewName();
1025 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
1028 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
1029 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
1030 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
1051 void read_ecs_metadata(hid_t s_file_id,
1052 string &total_strmeta_value,
1053 string &total_coremeta_value,
1054 string &total_archmeta_value,
1055 string &total_xmlmeta_value,
1056 string &total_submeta_value,
1057 string &total_prometa_value,
1058 string &total_othermeta_value,
1061 BESDEBUG(
"h5",
"Coming to read_ecs_metadata() "<<endl);
1062 string ecs_group =
"/HDFEOS INFORMATION";
1063 hid_t ecs_grp_id = -1;
1064 if ((ecs_grp_id = H5Gopen(s_file_id, ecs_group.c_str(),H5P_DEFAULT))<0) {
1066 "h5_ecs_meta: unable to open the HDF5 group ";
1068 throw InternalErr(__FILE__, __LINE__, msg);
1074 if (H5Gget_info(ecs_grp_id,&g_info) <0) {
1076 "h5_ecs_meta: unable to obtain the HDF5 group info. for ";
1078 H5Gclose(ecs_grp_id);
1079 throw InternalErr(__FILE__, __LINE__, msg);
1082 nelems = g_info.nlinks;
1084 ssize_t oname_size = 0;
1086 int cur_archmeta_suffix = 0;
1087 int cur_coremeta_suffix = 0;
1088 int cur_strmeta_suffix = 0;
1089 int cur_xmlmeta_suffix = 0;
1092 int archmeta_num = -1;
1093 int coremeta_num = -1;
1094 int xmlmeta_num = -1;
1095 int strmeta_num = -1;
1096 int submeta_num = -1;
1097 int prometa_num = -1;
1100 int archmeta_num_total = 0;
1101 int coremeta_num_total = 0;
1102 int xmlmeta_num_total = 0;
1103 int strmeta_num_total = 0;
1104 int submeta_num_total = 0;
1105 int prometa_num_total = 0;
1106 int othermeta_num_total = 0;
1108 bool archmeta_no_suffix =
true;
1109 bool coremeta_no_suffix =
true;
1110 bool strmeta_no_suffix =
true;
1111 bool xmlmeta_no_suffix =
true;
1112 bool submeta_no_suffix =
true;
1113 bool prometa_no_suffix =
true;
1116 vector<string> s_oname(nelems);
1120 EOS5Metadata metatype[nelems];
1122 for (
unsigned int i =0; i<nelems; i++)
1123 metatype[i] = OtherMeta;
1125 for (hsize_t i = 0; i < nelems; i++) {
1129 H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
1131 if (oname_size <= 0) {
1132 string msg =
"hdf5 object name error from: ";
1134 H5Gclose(ecs_grp_id);
1135 throw InternalErr(__FILE__, __LINE__, msg);
1139 vector<char> oname(oname_size + 1);
1140 if (H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
1141 (
size_t)(oname_size+1), H5P_DEFAULT)<0){
1142 string msg =
"hdf5 object name error from: ";
1144 H5Gclose(ecs_grp_id);
1145 throw InternalErr(__FILE__, __LINE__, msg);
1151 if (H5Lget_info(ecs_grp_id,&oname[0],&linfo,H5P_DEFAULT)<0) {
1152 string msg =
"hdf5 link name error from: ";
1154 H5Gclose(ecs_grp_id);
1155 throw InternalErr(__FILE__, __LINE__, msg);
1159 if (linfo.type == H5L_TYPE_SOFT){
1160 string msg =
"hdf5 link name error from: ";
1162 H5Gclose(ecs_grp_id);
1163 throw InternalErr(__FILE__, __LINE__, msg);
1168 if (H5Oget_info_by_idx(ecs_grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
1169 i, &oinfo, H5P_DEFAULT)<0) {
1170 string msg =
"Cannot obtain the object info ";
1172 H5Gclose(ecs_grp_id);
1173 throw InternalErr(__FILE__, __LINE__, msg);
1176 if(oinfo.type != H5O_TYPE_DATASET) {
1177 string msg =
"hdf5 link name error from: ";
1179 H5Gclose(ecs_grp_id);
1180 throw InternalErr(__FILE__, __LINE__, msg);
1184 string s_one_oname(oname.begin(),oname.end()-1);
1185 s_oname[i] = s_one_oname;
1188 if (((s_one_oname.find(
"StructMetadata"))==0) ||
1189 ((s_one_oname.find(
"structmetadata"))==0)){
1191 metatype[i] = StructMeta;
1198 if (
false == strmeta_no_suffix) {
1199 string msg =
"StructMetadata/structmetadata without suffix should only appear once. ";
1200 H5Gclose(ecs_grp_id);
1201 throw InternalErr(__FILE__, __LINE__, msg);
1204 else if(strmeta_num_total >0)
1205 strmeta_num_total++;
1207 if ((0 == s_one_oname.compare(
"StructMetadata"))||
1208 (0 == s_one_oname.compare(
"structmetadata")))
1209 strmeta_no_suffix =
false;
1210 else strmeta_num_total++;
1213 "h5",
"strmeta_num_total= "<<strmeta_num_total <<endl;
1214 if(strmeta_no_suffix)
"h5",
"structmeta data has the suffix" <<endl;
1215 else "h5",
"structmeta data doesn't have the suffix" <<endl;
1219 if(
false == s_st_only) {
1221 if ((0 == (s_one_oname.find(
"CoreMetadata"))) ||
1222 (0 == (s_one_oname.find(
"coremetadata")))){
1224 metatype[i] = CoreMeta;
1230 if (
false == coremeta_no_suffix) {
1231 string msg =
"CoreMetadata/coremetadata without suffix should only appear once. ";
1232 H5Gclose(ecs_grp_id);
1233 throw InternalErr(__FILE__, __LINE__, msg);
1236 else if(coremeta_num_total >0)
1237 coremeta_num_total++;
1242 if ((0 == s_one_oname.compare(
"CoreMetadata")) ||
1243 (0 == s_one_oname.compare(
"coremetadata")))
1244 coremeta_no_suffix =
false;
1245 else coremeta_num_total++;
1248 "h5",
"coremeta_num_total= "<<coremeta_num_total <<endl;
1249 if(coremeta_no_suffix)
"h5",
"coreuctmeta data has the suffix" <<endl;
1250 else "h5",
"coremeta data doesn't have the suffix" <<endl;
1255 else if ((0 == (s_one_oname.find(
"ArchivedMetadata"))) ||
1256 (0 == (s_one_oname.find(
"archivedmetadata"))) ||
1257 (0 == (s_one_oname.find(
"ArchiveMetadata"))) ||
1258 (0 == (s_one_oname.find(
"archivemetadata")))){
1260 metatype[i] = ArchivedMeta;
1265 if (
false == archmeta_no_suffix) {
1266 string msg =
"archivedmetadata/ArchivedMetadata without suffix should only appear once. ";
1267 H5Gclose(ecs_grp_id);
1268 throw InternalErr(__FILE__, __LINE__, msg);
1271 else if(archmeta_num_total >0)
1272 archmeta_num_total++;
1274 if ((0 == s_one_oname.compare(
"ArchivedMetadata"))||
1275 (0 == s_one_oname.compare(
"archivedmetadata")) ||
1276 (0 == s_one_oname.compare(
"archivemetadata")) ||
1277 (0 == s_one_oname.compare(
"ArchiveMetadata")))
1278 archmeta_no_suffix =
false;
1280 archmeta_num_total++;
1283 "h5",
"archmeta_num_total= "<<archmeta_num_total <<endl;
1284 if(archmeta_no_suffix)
"h5",
"archuctmeta data has the suffix" <<endl;
1285 else "h5",
"archmeta data doesn't have the suffix" <<endl;
1290 else if (((s_one_oname.find(
"SubsetMetadata"))==0) ||
1291 ((s_one_oname.find(
"subsetmetadata"))==0)){
1293 metatype[i] = SubsetMeta;
1298 if (
false == submeta_no_suffix) {
1299 H5Gclose(ecs_grp_id);
1300 string msg =
"submetadata/SubMetadata without suffix should only appear once. ";
1301 throw InternalErr(__FILE__, __LINE__, msg);
1304 else if(submeta_num_total >0)
1305 submeta_num_total++;
1307 if ((0 == s_one_oname.compare(
"SubsetMetadata"))||
1308 (0 == s_one_oname.compare(
"subsetmetadata")))
1309 submeta_no_suffix =
false;
1310 else submeta_num_total++;
1313 "h5",
"submeta_num_total= "<<submeta_num_total <<endl;
1314 if(submeta_no_suffix)
"h5",
"subuctmeta data has the suffix" <<endl;
1315 else "h5",
"submeta data doesn't have the suffix" <<endl;
1320 else if ((0 == (s_one_oname.find(
"XmlMetadata"))) ||
1321 (0 == (s_one_oname.find(
"xmlmetadata")))){
1323 metatype[i] = XMLMeta;
1329 if (
false == xmlmeta_no_suffix) {
1330 H5Gclose(ecs_grp_id);
1331 string msg =
"xmlmetadata/Xmlmetadata without suffix should only appear once. ";
1332 throw InternalErr(__FILE__, __LINE__, msg);
1335 else if(xmlmeta_num_total >0)
1336 xmlmeta_num_total++;
1338 if ((0 == s_one_oname.compare(
"XmlMetadata"))||
1339 (0 == s_one_oname.compare(
"xmlmetadata")))
1340 xmlmeta_no_suffix =
false;
1341 else xmlmeta_num_total++;
1344 "h5",
"xmlmeta_num_total= "<<xmlmeta_num_total <<endl;
1345 if(xmlmeta_no_suffix)
"h5",
"xmluctmeta data doesn't have the suffix" <<endl;
1346 else "h5",
"xmlmeta data has the suffix" <<endl;
1351 else if ((0 == (s_one_oname.find(
"ProductMetadata"))) ||
1352 (0 == (s_one_oname.find(
"productmetadata")))){
1354 metatype[i] = ProductMeta;
1359 if (!prometa_no_suffix) {
1360 H5Gclose(ecs_grp_id);
1361 string msg =
"productmetadata/ProductMetadata without suffix should only appear once. ";
1362 throw InternalErr(__FILE__, __LINE__, msg);
1365 else if(prometa_num_total >0) prometa_num_total++;
1367 if ((0 == s_one_oname.compare(
"ProductMetadata"))||
1368 (0 == s_one_oname.compare(
"productmetadata")))
1369 prometa_no_suffix =
false;
1370 else prometa_num_total++;
1376 else othermeta_num_total++;
1380 s_one_oname.clear();
1385 vector<string> strmeta_value;
1386 if (strmeta_num_total <= 0) {
1387 string msg =
"hdf5 object name error from: ";
1388 H5Gclose(ecs_grp_id);
1389 throw InternalErr(__FILE__, __LINE__, msg);
1392 strmeta_value.resize(strmeta_num_total);
1393 for (
int i = 0; i < strmeta_num_total; i++)
1394 strmeta_value[i]=
"";
1399 vector<string> archmeta_value;
1400 if (archmeta_num_total >0) {
1401 archmeta_value.resize(archmeta_num_total);
1402 for (
int i = 0; i < archmeta_num_total; i++)
1403 archmeta_value[i]=
"";
1407 vector<string> coremeta_value;
1408 if (coremeta_num_total >0) {
1409 coremeta_value.resize(coremeta_num_total);
1410 for (
int i = 0; i < coremeta_num_total; i++)
1411 coremeta_value[i]=
"";
1415 vector<string> xmlmeta_value;
1416 if (xmlmeta_num_total >0) {
1417 xmlmeta_value.resize(xmlmeta_num_total);
1418 for (
int i = 0; i < xmlmeta_num_total; i++)
1419 xmlmeta_value[i]=
"";
1423 vector<string> submeta_value;
1424 if (submeta_num_total >0) {
1425 submeta_value.resize(submeta_num_total);
1426 for (
int i = 0; i < submeta_num_total; i++)
1427 submeta_value[i]=
"";
1431 vector<string> prometa_value;
1432 if (prometa_num_total >0) {
1433 prometa_value.resize(prometa_num_total);
1434 for (
int i = 0; i < prometa_num_total; i++)
1435 prometa_value[i]=
"";
1443 for (hsize_t i = 0; i < nelems; i++) {
1451 if (
true == s_st_only &&
1452 (((s_oname[i].find(
"StructMetadata"))!=0) &&
1453 ((s_oname[i].find(
"structmetadata"))!=0))){
1458 hid_t s_dset_id = -1;
1459 hid_t s_space_id = -1;
1461 hssize_t s_nelms = -1;
1462 size_t dtype_size = -1;
1464 if ((s_dset_id = H5Dopen(ecs_grp_id,s_oname[i].c_str(),H5P_DEFAULT))<0){
1465 string msg =
"Cannot open HDF5 dataset ";
1467 H5Gclose(ecs_grp_id);
1468 throw InternalErr(__FILE__, __LINE__, msg);
1471 if ((s_space_id = H5Dget_space(s_dset_id))<0) {
1472 string msg =
"Cannot open the data space of HDF5 dataset ";
1474 H5Dclose(s_dset_id);
1475 H5Gclose(ecs_grp_id);
1476 throw InternalErr(__FILE__, __LINE__, msg);
1479 if ((s_ty_id = H5Dget_type(s_dset_id)) < 0) {
1480 string msg =
"Cannot get the data type of HDF5 dataset ";
1482 H5Sclose(s_space_id);
1483 H5Dclose(s_dset_id);
1484 H5Gclose(ecs_grp_id);
1485 throw InternalErr(__FILE__, __LINE__, msg);
1487 if ((s_nelms = H5Sget_simple_extent_npoints(s_space_id))<0) {
1488 string msg =
"Cannot get the number of points of HDF5 dataset ";
1491 H5Sclose(s_space_id);
1492 H5Dclose(s_dset_id);
1493 H5Gclose(ecs_grp_id);
1494 throw InternalErr(__FILE__, __LINE__, msg);
1496 if ((dtype_size = H5Tget_size(s_ty_id))==0) {
1498 string msg =
"Cannot get the data type size of HDF5 dataset ";
1501 H5Sclose(s_space_id);
1502 H5Dclose(s_dset_id);
1503 H5Gclose(ecs_grp_id);
1504 throw InternalErr(__FILE__, __LINE__, msg);
1508 vector<char> s_buf(dtype_size*s_nelms +1);
1510 if ((H5Dread(s_dset_id,s_ty_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,&s_buf[0]))<0) {
1512 string msg =
"Cannot read HDF5 dataset ";
1515 H5Sclose(s_space_id);
1516 H5Dclose(s_dset_id);
1517 H5Gclose(ecs_grp_id);
1518 throw InternalErr(__FILE__, __LINE__, msg);
1523 H5Sclose(s_space_id);
1524 H5Dclose(s_dset_id);
1528 string tempstr(s_buf.begin(),s_buf.end());
1530 size_t temp_null_pos = tempstr.find_first_of(
'\0');
1535 string finstr = tempstr.substr(0,temp_null_pos);
1538 if (StructMeta == metatype[i]) {
1542 strmeta_num = get_metadata_num(s_oname[i]);
1545 H5Gclose(ecs_grp_id);
1546 throw InternalErr(__FILE__,__LINE__,
"Obtain structmetadata suffix error.");
1553 if (-1 == strmeta_num)
1554 total_strmeta_value = finstr;
1556 else if (strmeta_value[strmeta_num]!=
"") {
1557 string msg =
"The structmeta value array at this index should be empty string ";
1558 H5Gclose(ecs_grp_id);
1559 throw InternalErr(__FILE__, __LINE__, msg);
1563 strmeta_value[strmeta_num] = finstr;
1567 if (
false == s_st_only &&
1568 (metatype[i] != StructMeta)) {
1570 switch (metatype[i]) {
1574 if (coremeta_num_total < 0) {
1575 string msg =
"There may be no coremetadata or coremetadata is not counted ";
1576 H5Gclose(ecs_grp_id);
1577 throw InternalErr(__FILE__, __LINE__, msg);
1582 coremeta_num = get_metadata_num(s_oname[i]);
1585 H5Gclose(ecs_grp_id);
1586 throw InternalErr(__FILE__,__LINE__,
"Obtain coremetadata suffix error.");
1592 if ( -1 == coremeta_num )
1593 total_coremeta_value = finstr;
1594 else if (coremeta_value[coremeta_num]!=
"") {
1595 string msg =
"The coremeta value array at this index should be empty string ";
1596 H5Gclose(ecs_grp_id);
1597 throw InternalErr(__FILE__, __LINE__, msg);
1602 coremeta_value[coremeta_num] = finstr;
1608 if (archmeta_num_total < 0) {
1609 string msg =
"There may be no archivemetadata or archivemetadata is not counted ";
1610 H5Gclose(ecs_grp_id);
1611 throw InternalErr(__FILE__, __LINE__, msg);
1614 archmeta_num = get_metadata_num(s_oname[i]);
1617 H5Gclose(ecs_grp_id);
1618 throw InternalErr(__FILE__,__LINE__,
"Obtain archivemetadata suffix error.");
1620 if (-1 == archmeta_num )
1621 total_archmeta_value = finstr;
1622 else if (archmeta_value[archmeta_num]!=
"") {
1623 string msg =
"The archivemeta value array at this index should be empty string ";
1624 H5Gclose(ecs_grp_id);
1625 throw InternalErr(__FILE__, __LINE__, msg);
1630 archmeta_value[archmeta_num] = finstr;
1635 if (submeta_num_total < 0) {
1636 string msg =
"The subsetemeta value array at this index should be empty string ";
1637 H5Gclose(ecs_grp_id);
1638 throw InternalErr(__FILE__, __LINE__, msg);
1641 submeta_num = get_metadata_num(s_oname[i]);
1644 H5Gclose(ecs_grp_id);
1645 throw InternalErr(__FILE__,__LINE__,
"Obtain subsetmetadata suffix error.");
1647 if (-1 == submeta_num )
1648 total_submeta_value = finstr;
1649 else if (submeta_value[submeta_num]!=
"") {
1650 string msg =
"The submeta value array at this index should be empty string ";
1651 H5Gclose(ecs_grp_id);
1652 throw InternalErr(__FILE__, __LINE__, msg);
1656 submeta_value[submeta_num] = finstr;
1661 if (prometa_num_total < 0) {
1662 string msg =
"There may be no productmetadata or productmetadata is not counted ";
1663 H5Gclose(ecs_grp_id);
1664 throw InternalErr(__FILE__, __LINE__, msg);
1667 prometa_num = get_metadata_num(s_oname[i]);
1670 H5Gclose(ecs_grp_id);
1671 throw InternalErr(__FILE__,__LINE__,
"Obtain productmetadata suffix error.");
1673 if (prometa_num == -1)
1674 total_prometa_value = finstr;
1675 else if (prometa_value[prometa_num]!=
"") {
1676 string msg =
"The productmeta value array at this index should be empty string ";
1677 H5Gclose(ecs_grp_id);
1678 throw InternalErr(__FILE__, __LINE__, msg);
1682 prometa_value[prometa_num] = finstr;
1687 if (xmlmeta_num_total < 0) {
1688 string msg =
"There may be no xmlmetadata or xmlmetadata is not counted ";
1689 H5Gclose(ecs_grp_id);
1690 throw InternalErr(__FILE__, __LINE__, msg);
1693 xmlmeta_num = get_metadata_num(s_oname[i]);
1696 H5Gclose(ecs_grp_id);
1697 throw InternalErr(__FILE__,__LINE__,
"Obtain XMLmetadata suffix error.");
1699 if (-1 == xmlmeta_num )
1700 total_xmlmeta_value = finstr;
1701 else if (xmlmeta_value[xmlmeta_num]!=
"") {
1702 string msg =
"The xmlmeta value array at this index should be empty string ";
1703 H5Gclose(ecs_grp_id);
1704 throw InternalErr(__FILE__, __LINE__, msg);
1708 xmlmeta_value[xmlmeta_num] = finstr;
1713 if (othermeta_num_total < 0) {
1714 string msg =
"There may be no othermetadata or other metadata is not counted ";
1715 H5Gclose(ecs_grp_id);
1716 throw InternalErr(__FILE__, __LINE__, msg);
1718 total_othermeta_value = total_othermeta_value + finstr;
1723 string msg =
"Unsupported metadata type ";
1724 H5Gclose(ecs_grp_id);
1725 throw InternalErr(__FILE__, __LINE__, msg);
1735 if (strmeta_num_total > 0) {
1737 if (strmeta_num != -1) {
1738 for (
int i = 0; i <strmeta_num_total; i++)
1739 total_strmeta_value +=strmeta_value[i];
1744 if (
false == s_st_only) {
1746 if (coremeta_num_total >0) {
1747 if (coremeta_num != -1) {
1748 for(
int i = 0; i <coremeta_num_total; i++)
1749 total_coremeta_value +=coremeta_value[i];
1753 if (archmeta_num_total >0) {
1754 if (archmeta_num != -1) {
1755 for(
int i = 0; i <archmeta_num_total; i++)
1756 total_archmeta_value +=archmeta_value[i];
1760 if (submeta_num_total >0) {
1761 if (submeta_num != -1) {
1762 for(
int i = 0; i <submeta_num_total; i++)
1763 total_submeta_value +=submeta_value[i];
1767 if (xmlmeta_num_total >0) {
1768 if (xmlmeta_num != -1) {
1769 for(
int i = 0; i <xmlmeta_num_total; i++)
1770 total_xmlmeta_value +=xmlmeta_value[i];
1774 if (prometa_num_total >0) {
1775 if (prometa_num != -1) {
1776 for(
int i = 0; i <prometa_num_total; i++)
1777 total_prometa_value +=prometa_value[i];
1781 H5Gclose(ecs_grp_id);
1785 int get_metadata_num(
const string & meta_str) {
1790 size_t dot_pos = meta_str.find(
".");
1791 if (dot_pos == string::npos)
1793 else if (meta_str.find_first_of(
".") == meta_str.find_last_of(
".")) {
1794 string num_str = meta_str.substr(dot_pos+1);
1795 stringstream ssnum(num_str);
1799 throw InternalErr(__FILE__,__LINE__,
"Suffix after dots is not a number.");
1803 string str_after_first_dot = meta_str.substr(dot_pos+1);
1804 if (str_after_first_dot.find_first_of(
".") != str_after_first_dot.find_last_of(
"."))
1805 throw InternalErr(__FILE__,__LINE__,
"Currently don't support metadata names containing more than two dots.");
1810 size_t second_dot_pos = str_after_first_dot.find(
".");
1811 string num_str = str_after_first_dot.substr(second_dot_pos+1);
1812 stringstream ssnum(num_str);
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.
include the entry functions to execute the handlers
This class specifies the retrieval of the missing lat/lon values for HDF-EOS5 products.
This class specifies the retrieval of the missing lat/lon values for HDFEOS5 products.
This class specifies the retrieval of special coordinate variable values for HDF-EOS5 products.
A class for parsing NASA HDF-EOS5 StructMetadata.
A class for parsing NASA HDF-EOS5 StructMetadata.
CVType getCVType() const
Get the coordinate variable type of this variable.
This class is a derived class of CVar. It represents a coordinate variable for HDF-EOS5 files.
This class is a derived class of File. It includes methods applied to HDF-EOS5 files only.
virtual const std::string & Get_Ignored_Msg()
Obtain the message that contains the ignored object info.
void Add_EOS5File_Info(HE5Parser *, bool)
Add HDF-EOS5 dimension and coordinate variable related info. to EOS5Grid,EOS5Swath etc.
void Set_COARDS_Status()
Set COARDS flag.
virtual void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for HDF-EOS5 products.
void Adjust_Var_Dim_NewName_Before_Flattening()
Adjust variable dimension names before the flattening for HDF-EOS5 files.
void Adjust_Attr_Info()
Adjust the attribute info for HDF-EOS5 products.
void Handle_Obj_NameClashing(bool)
Handle the object name clashing for HDF-EOS5 products.
virtual void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
virtual void Adjust_Obj_Name()
This method is a no-op operation. Leave here since the method in the base class is pure virtual.
virtual void Handle_SpVar()
Handle special variables for HDF-EOS5 files.
virtual void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr)
Retrieve DDS information from the HDF5 file; a real implementation for HDF-EOS5 products.
const std::vector< EOS5CVar * > & getCVars() const
Obtain coordinate variables for HDF-EOS5 products.
virtual void Handle_DimNameClashing()
virtual void Handle_CVar()
Handle coordinate variable for HDF-EOS5 files.
virtual void Handle_SpVar_Attr()
Handle special variables for HDF-EOS5 files.
virtual void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for HDF-EOS5 products.
virtual void Handle_Coor_Attr()
Handle the coordinates attribute for HDF-EOS5 products.
void Adjust_Var_NewName_After_Parsing()
Adjust variable names for HDF-EOS5 files.
virtual void Add_Supplement_Attrs(bool)
Add the supplemental attributes for HDF-EOS5 products.
void Add_Dim_Name(HE5Parser *)
Add the dimension name for HDF-EOS5 files.
virtual void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for HDF-EOS5 products.
virtual void Flatten_Obj_Name(bool include_attr)
Flatten the object name for HDF-EOS5 files.
virtual void Adjust_Dim_Name()
Adjust the dimension name for HDF-EOS5 products.
virtual void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for HDF-EOS5 products.
void Check_Aura_Product_Status()
Check if the HDF-EOS5 file is an Aura file. Special CF operations need to be used.
virtual bool Get_IgnoredInfo_Flag()
Obtain the flag to see if ignored objects should be generated.
virtual void Adjust_EOS5Dim_Info(HE5Parser *strmeta_info)
Adjust HDF-EOS5 dimension information.
bool HaveUnlimitedDim() const
Has unlimited dimensions.
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.
int getRank() const
Get the dimension rank of this variable.
const std::string & getFullPath() const
Get the full path of this variable.
const std::string & getName() const
Get the original name 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.
yy_buffer_state * he5das_scan_string(const char *str)
Buffer state for NASA EOS metadata scanner.
Map and generate DDS and DAS for the CF option for HDF-EOS5 products.