33 #include <sys/types.h>
60 #include "he5dds.tab.hh"
63 #include "he5das.tab.hh"
65 struct yy_buffer_state;
67 yy_buffer_state *he5dds_scan_string(
const char *str);
69 int he5dasparse(libdap::parser_arg *arg);
70 int he5ddslex_destroy();
71 int he5daslex_destroy();
76 using namespace HDF5CF;
79 void map_eos5_cfdds(DDS &dds, hid_t file_id,
const string & filename) {
81 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
89 string product_str=
"";
94 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
97 "unable to obtain the HDF-EOS5 struct metadata ";
98 throw InternalErr(__FILE__, __LINE__, msg);
101 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
106 f =
new EOS5File(filename.c_str(),file_id);
109 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
112 bool include_attr =
false;
120 he5dds_scan_string(st_str.c_str());
125 p.add_projparams(st_str);
131 if (c.check_grids_unknown_parameters(&p)) {
132 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
135 if (c.check_grids_missing_projcode(&p)) {
136 throw InternalErr(
"The HDF-EOS5 is missing project code ");
140 if (c.check_grids_support_projcode(&p)) {
141 throw InternalErr(
"The current project code is not supported");
145 c.set_grids_missing_pixreg_orig(&p);
148 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
166 throw InternalErr(e.what());
192 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
193 (HDF5RequestHandler::get_srdata_mem_cache() != NULL)){
220 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
221 (HDF5RequestHandler::get_srdata_mem_cache() != NULL))
232 if(
true == is_check_nameclashing)
240 if(
true == is_check_nameclashing)
252 throw InternalErr(e.what());
257 gen_eos5_cfdds(dds,f);
270 void map_eos5_cfdas(DAS &das, hid_t file_id,
const string &filename) {
272 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS mapping function map_eos5_cfdas "<<endl);
277 string subset_str=
"";
278 string product_str=
"";
279 string other_str =
"";
282 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
285 "unable to obtain the HDF-EOS5 struct metadata ";
286 throw InternalErr(__FILE__, __LINE__, msg);
289 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
291 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
295 f =
new EOS5File(filename.c_str(),file_id);
298 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
300 bool include_attr =
true;
307 he5dds_scan_string(st_str.c_str());
311 p.add_projparams(st_str);
317 if (c.check_grids_unknown_parameters(&p)) {
318 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
321 if (c.check_grids_missing_projcode(&p)) {
322 throw InternalErr(
"The HDF-EOS5 is missing project code ");
324 if (c.check_grids_support_projcode(&p)) {
325 throw InternalErr(
"The current project code is not supported");
327 c.set_grids_missing_pixreg_orig(&p);
329 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
339 throw InternalErr(e.what());
371 if (
true == is_check_nameclashing)
391 throw InternalErr(e.what());
396 gen_eos5_cfdas(das,file_id,f);
412 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function gen_eos5_cfdds "<<endl);
413 const vector<HDF5CF::Var *>& vars = f->
getVars();
414 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
415 const string filename = f->
getPath();
419 vector<HDF5CF::Var *>::const_iterator it_v;
420 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
422 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
423 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
424 gen_dap_onevar_dds(dds,*it_v,file_id,filename);
427 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
428 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
429 gen_dap_oneeos5cvar_dds(dds,*it_cv,file_id,filename);
436 unsigned short cv_lat_miss_index = 1;
437 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
438 if((*it_cv)->getCVType() == CV_LAT_MISS) {
439 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
443 gen_dap_oneeos5cf_dds(dds,*it_cv);
444 add_cf_grid_mapinfo_var(dds,(*it_cv)->getProjCode(),cv_lat_miss_index);
453 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_dds() "<<endl);
455 float cv_point_lower = cvar->getPointLower();
456 float cv_point_upper = cvar->getPointUpper();
457 float cv_point_left = cvar->getPointLeft();
458 float cv_point_right = cvar->getPointRight();
459 EOS5GridPCType cv_proj_code = cvar->getProjCode();
460 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
462 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
463 add_cf_grid_cvs(dds,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
467 void gen_dap_oneeos5cf_das(DAS &das,
const vector<HDF5CF::Var*>& vars,
const HDF5CF::EOS5CVar* cvar,
const unsigned short g_suffix) {
469 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_das() "<<endl);
471 float cv_point_lower = cvar->getPointLower();
472 float cv_point_upper = cvar->getPointUpper();
473 float cv_point_left = cvar->getPointLeft();
474 float cv_point_right = cvar->getPointRight();
476 EOS5GridPCType cv_proj_code = cvar->getProjCode();
477 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
480 cerr<<
"cv_point_lower is "<<cv_point_lower <<endl;
481 cerr<<
"cvar name is "<<cvar->
getName() <<endl;
482 for(vector<HDF5CF::Dimension*>::const_iterator it_d = dims.begin(); it_d != dims.end(); ++it_d)
483 cerr<<
"dim name das is "<<(*it_d)->getNewName() <<endl;
487 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
489 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);
491 add_cf_grid_cv_attrs(das,vars,cv_proj_code,dims,cvar->getParams(),g_suffix);
498 BESDEBUG(
"h5",
"Coming to gen_eos5_cf_ignored_obj_info() "<<endl);
499 AttrTable *at = das.get_table(
"Ignored_Object_Info");
501 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
509 void gen_dap_oneeos5cvar_dds(DDS &dds,
const HDF5CF::EOS5CVar* cvar,
const hid_t file_id,
const string & filename) {
511 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dds() "<<endl);
518 #define HANDLE_CASE(tid,type) \
520 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
531 HANDLE_CASE(H5FSTRING, Str);
532 HANDLE_CASE(H5VSTRING, Str);
534 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
540 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
541 vector <HDF5CF::Dimension*>:: const_iterator it_d;
542 vector <size_t> dimsizes;
543 dimsizes.resize(cvar->
getRank());
544 for(
int i = 0; i <cvar->
getRank();i++)
545 dimsizes[i] = (dims[i])->getSize();
549 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
556 for(vector<HDF5CF::Attribute *>::const_iterator it_ra = cvar->getAttributes().begin();
557 it_ra != cvar->getAttributes().end(); ++it_ra) {
558 cerr<<
"cvar attribute name is "<<(*it_ra)->getNewName() <<endl;
559 cerr<<
"cvar attribute value type is "<<(*it_ra)->getType() <<endl;
561 cerr<<
"cvar new name exist at he s5cfdap.cc is "<<cvar->
getNewName() <<endl;
563 bool is_latlon = cvar->isLatLon();
573 cvar->getTotalElems(),
582 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
585 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
586 if (
""==(*it_d)->getNewName())
587 ar->append_dim((*it_d)->getSize());
589 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
605 cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
606 cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
607 cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
615 cvar->getPointLower(),
616 cvar->getPointUpper(),
617 cvar->getPointLeft(),
618 cvar->getPointRight(),
632 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissLLArray.");
635 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
636 if (
""==(*it_d)->getNewName())
637 ar->append_dim((*it_d)->getSize());
639 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
648 case CV_NONLATLON_MISS:
653 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
667 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissNonLLCVArray.");
671 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
672 if (
""==(*it_d)->getNewName())
673 ar->append_dim((*it_d)->getSize());
675 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
691 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
709 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
713 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
714 if (
""==(*it_d)->getNewName())
715 ar->append_dim((*it_d)->getSize());
717 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
727 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
737 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS generation function gen_eos5_cfdas "<<endl);
741 gen_eos5_cf_ignored_obj_info(das, f);
745 const vector<HDF5CF::Var *>& vars = f->
getVars();
746 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
747 const vector<HDF5CF::Group *>& grps = f->
getGroups();
748 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
750 vector<HDF5CF::Var *>::const_iterator it_v;
751 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
752 vector<HDF5CF::Group *>::const_iterator it_g;
753 vector<HDF5CF::Attribute *>::const_iterator it_ra;
757 if (
false == root_attrs.empty()) {
758 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
760 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
762 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); it_ra++) {
763 gen_dap_oneobj_das(at,*it_ra,NULL);
767 if (
false == grps.empty()) {
768 for (it_g = grps.begin();
769 it_g != grps.end(); ++it_g) {
770 AttrTable *at = das.get_table((*it_g)->getNewName());
772 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
774 for (it_ra = (*it_g)->getAttributes().begin();
775 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
778 if((*it_ra)->getNewName()==
"Conventions" &&((*it_g)->getNewName() ==
"HDFEOS_ADDITIONAL_FILE_ATTRIBUTES")
779 && (
true==HDF5RequestHandler::get_eos5_rm_convention_attr_path())) {
780 AttrTable *at_das = das.get_table(FILE_ATTR_TABLE_NAME);
782 at_das = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
783 gen_dap_oneobj_das(at_das,*it_ra,NULL);
786 gen_dap_oneobj_das(at,*it_ra,NULL);
791 for (it_v = vars.begin();
792 it_v != vars.end(); ++it_v) {
793 if (
false == ((*it_v)->getAttributes().empty())) {
796 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
800 AttrTable *at = das.get_table((*it_v)->getNewName());
802 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
804 for (it_ra = (*it_v)->getAttributes().begin();
805 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
806 gen_dap_oneobj_das(at,*it_ra,*it_v);
811 for (it_cv = cvars.begin(); it_cv !=cvars.end();it_cv++) {
813 if (
false == ((*it_cv)->getAttributes().empty())) {
816 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
820 AttrTable *at = das.get_table((*it_cv)->getNewName());
822 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
825 for (it_ra = (*it_cv)->getAttributes().begin();
826 it_ra != (*it_cv)->getAttributes().end(); ++it_ra) {
827 gen_dap_oneobj_das(at,*it_ra,*it_cv);
833 unsigned short cv_lat_miss_index = 1;
835 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
836 if((*it_cv)->getCVType() == CV_LAT_MISS) {
837 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
838 gen_dap_oneeos5cf_das(das,vars,*it_cv,cv_lat_miss_index);
844 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
845 if((*it_cv)->getProjCode() == HE5_GCTP_LAMAZ) {
846 if((*it_cv)->getCVType() == CV_LAT_MISS || (*it_cv)->getCVType() == CV_LON_MISS) {
847 AttrTable *at = das.get_table((*it_cv)->getNewName());
849 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
850 if((*it_cv)->getCVType() == CV_LAT_MISS)
851 add_ll_valid_range(at,
true);
853 add_ll_valid_range(at,
false);
859 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
861 if(disable_ecsmetadata ==
false) {
870 string subset_str=
"";
871 string product_str=
"";
872 string other_str =
"";
873 bool st_only =
false;
875 read_ecs_metadata(file_id, st_str, core_str, arch_str, xml_str,
876 subset_str, product_str, other_str, st_only);
879 if(st_str!=
"")
"h5",
"Final structmetadata "<<st_str <<endl;
880 if(core_str!=
"")
"h5",
"Final coremetadata "<<core_str <<endl;
881 if(arch_str!=
"")
"h5",
"Final archivedmetadata "<<arch_str <<endl;
882 if(xml_str!=
"")
"h5",
"Final xmlmetadata "<<xml_str <<endl;
883 if(subset_str!=
"")
"h5",
"Final subsetmetadata "<<subset_str <<endl;
884 if(product_str!=
"")
"h5",
"Final productmetadata "<<product_str <<endl;
885 if(other_str!=
"")
"h5",
"Final othermetadata "<<other_str <<endl;
891 string check_disable_smetadata_key =
"H5.DisableStructMetaAttr";
892 bool is_check_disable_smetadata =
false;
893 is_check_disable_smetadata = HDF5CFDAPUtil::check_beskeys(check_disable_smetadata_key);
895 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
897 if (
false == is_check_disable_smetadata) {
899 AttrTable *at = das.get_table(
"StructMetadata");
901 at = das.add_table(
"StructMetadata",
new AttrTable);
905 if (he5dasparse(&arg) != 0
906 ||
false == arg.status()){
908 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
909 <<
"StructMetadata " <<
" HDFEOS attribute" << endl;
918 AttrTable *at = das.get_table(
"CoreMetadata");
920 at = das.add_table(
"CoreMetadata",
new AttrTable);
923 if (he5dasparse(&arg) != 0
924 ||
false == arg.status()){
926 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
927 <<
"CoreMetadata " <<
" HDFEOS attribute" << endl;
933 AttrTable *at = das.get_table(
"ArchiveMetadata");
935 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
938 if (he5dasparse(&arg) != 0
939 ||
false == arg.status()){
941 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
942 <<
"ArchiveMetadata " <<
" HDFEOS attribute" << endl;
951 AttrTable *at = das.get_table(
"XMLMetadata");
953 at = das.add_table(
"XMLMetadata",
new AttrTable);
954 HDF5CFDAPUtil::replace_double_quote(xml_str);
955 at->append_attr(
"Contents",
"String",xml_str);
961 if(subset_str !=
""){
962 AttrTable *at = das.get_table(
"SubsetMetadata");
964 at = das.add_table(
"SubsetMetadata",
new AttrTable);
967 if (he5dasparse(&arg) != 0
968 ||
false == arg.status()) {
970 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
971 <<
"SubsetMetadata " <<
" HDFEOS attribute" << endl;
975 if(product_str !=
""){
976 AttrTable *at = das.get_table(
"ProductMetadata");
978 at = das.add_table(
"ProductMetadata",
new AttrTable);
981 if (he5dasparse(&arg) != 0
982 ||
false == arg.status()){
983 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
984 <<
"ProductMetadata " <<
" HDFEOS attribute" << endl;
992 if (other_str !=
""){
993 AttrTable *at = das.get_table(
"OtherMetadata");
995 at = das.add_table(
"OtherMetadata",
new AttrTable);
996 at->append_attr(
"Contents",
"String",other_str);
1003 AttrTable *at = das.get_table(
"DODS_EXTRA");
1005 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
1006 string unlimited_names;
1008 for (it_cv = cvars.begin();
1009 it_cv != cvars.end(); it_cv++) {
1011 bool has_unlimited_dim =
false;
1014 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
1015 ird != (*it_cv)->getDimensions().end(); ++ird) {
1020 if((*ird)->HaveUnlimitedDim() ==
true) {
1022 if(unlimited_names==
"") {
1023 unlimited_names = (*ird)->getNewName();
1024 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
1027 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
1028 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
1029 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
1050 void read_ecs_metadata(hid_t s_file_id,
1051 string &total_strmeta_value,
1052 string &total_coremeta_value,
1053 string &total_archmeta_value,
1054 string &total_xmlmeta_value,
1055 string &total_submeta_value,
1056 string &total_prometa_value,
1057 string &total_othermeta_value,
1060 BESDEBUG(
"h5",
"Coming to read_ecs_metadata() "<<endl);
1061 string ecs_group =
"/HDFEOS INFORMATION";
1062 hid_t ecs_grp_id = -1;
1063 if ((ecs_grp_id = H5Gopen(s_file_id, ecs_group.c_str(),H5P_DEFAULT))<0) {
1065 "h5_ecs_meta: unable to open the HDF5 group ";
1067 throw InternalErr(__FILE__, __LINE__, msg);
1073 if (H5Gget_info(ecs_grp_id,&g_info) <0) {
1075 "h5_ecs_meta: unable to obtain the HDF5 group info. for ";
1077 H5Gclose(ecs_grp_id);
1078 throw InternalErr(__FILE__, __LINE__, msg);
1081 nelems = g_info.nlinks;
1083 ssize_t oname_size = 0;
1085 int cur_archmeta_suffix = 0;
1086 int cur_coremeta_suffix = 0;
1087 int cur_strmeta_suffix = 0;
1088 int cur_xmlmeta_suffix = 0;
1091 int archmeta_num = -1;
1092 int coremeta_num = -1;
1093 int xmlmeta_num = -1;
1094 int strmeta_num = -1;
1095 int submeta_num = -1;
1096 int prometa_num = -1;
1099 int archmeta_num_total = 0;
1100 int coremeta_num_total = 0;
1101 int xmlmeta_num_total = 0;
1102 int strmeta_num_total = 0;
1103 int submeta_num_total = 0;
1104 int prometa_num_total = 0;
1105 int othermeta_num_total = 0;
1107 bool archmeta_no_suffix =
true;
1108 bool coremeta_no_suffix =
true;
1109 bool strmeta_no_suffix =
true;
1110 bool xmlmeta_no_suffix =
true;
1111 bool submeta_no_suffix =
true;
1112 bool prometa_no_suffix =
true;
1115 vector<string> s_oname(nelems);
1119 EOS5Metadata metatype[nelems];
1121 for (
unsigned int i =0; i<nelems; i++)
1122 metatype[i] = OtherMeta;
1124 for (hsize_t i = 0; i < nelems; i++) {
1128 H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
1130 if (oname_size <= 0) {
1131 string msg =
"hdf5 object name error from: ";
1133 H5Gclose(ecs_grp_id);
1134 throw InternalErr(__FILE__, __LINE__, msg);
1138 vector<char> oname(oname_size + 1);
1139 if (H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
1140 (
size_t)(oname_size+1), H5P_DEFAULT)<0){
1141 string msg =
"hdf5 object name error from: ";
1143 H5Gclose(ecs_grp_id);
1144 throw InternalErr(__FILE__, __LINE__, msg);
1150 if (H5Lget_info(ecs_grp_id,&oname[0],&linfo,H5P_DEFAULT)<0) {
1151 string msg =
"hdf5 link name error from: ";
1153 H5Gclose(ecs_grp_id);
1154 throw InternalErr(__FILE__, __LINE__, msg);
1158 if (linfo.type == H5L_TYPE_SOFT){
1159 string msg =
"hdf5 link name error from: ";
1161 H5Gclose(ecs_grp_id);
1162 throw InternalErr(__FILE__, __LINE__, msg);
1167 if (H5Oget_info_by_idx(ecs_grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
1168 i, &oinfo, H5P_DEFAULT)<0) {
1169 string msg =
"Cannot obtain the object info ";
1171 H5Gclose(ecs_grp_id);
1172 throw InternalErr(__FILE__, __LINE__, msg);
1175 if(oinfo.type != H5O_TYPE_DATASET) {
1176 string msg =
"hdf5 link name error from: ";
1178 H5Gclose(ecs_grp_id);
1179 throw InternalErr(__FILE__, __LINE__, msg);
1183 string s_one_oname(oname.begin(),oname.end()-1);
1184 s_oname[i] = s_one_oname;
1187 if (((s_one_oname.find(
"StructMetadata"))==0) ||
1188 ((s_one_oname.find(
"structmetadata"))==0)){
1190 metatype[i] = StructMeta;
1197 if (
false == strmeta_no_suffix) {
1198 string msg =
"StructMetadata/structmetadata without suffix should only appear once. ";
1199 H5Gclose(ecs_grp_id);
1200 throw InternalErr(__FILE__, __LINE__, msg);
1203 else if(strmeta_num_total >0)
1204 strmeta_num_total++;
1206 if ((0 == s_one_oname.compare(
"StructMetadata"))||
1207 (0 == s_one_oname.compare(
"structmetadata")))
1208 strmeta_no_suffix =
false;
1209 else strmeta_num_total++;
1212 "h5",
"strmeta_num_total= "<<strmeta_num_total <<endl;
1213 if(strmeta_no_suffix)
"h5",
"structmeta data has the suffix" <<endl;
1214 else "h5",
"structmeta data doesn't have the suffix" <<endl;
1218 if(
false == s_st_only) {
1220 if ((0 == (s_one_oname.find(
"CoreMetadata"))) ||
1221 (0 == (s_one_oname.find(
"coremetadata")))){
1223 metatype[i] = CoreMeta;
1229 if (
false == coremeta_no_suffix) {
1230 string msg =
"CoreMetadata/coremetadata without suffix should only appear once. ";
1231 H5Gclose(ecs_grp_id);
1232 throw InternalErr(__FILE__, __LINE__, msg);
1235 else if(coremeta_num_total >0)
1236 coremeta_num_total++;
1241 if ((0 == s_one_oname.compare(
"CoreMetadata")) ||
1242 (0 == s_one_oname.compare(
"coremetadata")))
1243 coremeta_no_suffix =
false;
1244 else coremeta_num_total++;
1247 "h5",
"coremeta_num_total= "<<coremeta_num_total <<endl;
1248 if(coremeta_no_suffix)
"h5",
"coreuctmeta data has the suffix" <<endl;
1249 else "h5",
"coremeta data doesn't have the suffix" <<endl;
1254 else if ((0 == (s_one_oname.find(
"ArchivedMetadata"))) ||
1255 (0 == (s_one_oname.find(
"archivedmetadata"))) ||
1256 (0 == (s_one_oname.find(
"ArchiveMetadata"))) ||
1257 (0 == (s_one_oname.find(
"archivemetadata")))){
1259 metatype[i] = ArchivedMeta;
1264 if (
false == archmeta_no_suffix) {
1265 string msg =
"archivedmetadata/ArchivedMetadata without suffix should only appear once. ";
1266 H5Gclose(ecs_grp_id);
1267 throw InternalErr(__FILE__, __LINE__, msg);
1270 else if(archmeta_num_total >0)
1271 archmeta_num_total++;
1273 if ((0 == s_one_oname.compare(
"ArchivedMetadata"))||
1274 (0 == s_one_oname.compare(
"archivedmetadata")) ||
1275 (0 == s_one_oname.compare(
"archivemetadata")) ||
1276 (0 == s_one_oname.compare(
"ArchiveMetadata")))
1277 archmeta_no_suffix =
false;
1279 archmeta_num_total++;
1282 "h5",
"archmeta_num_total= "<<archmeta_num_total <<endl;
1283 if(archmeta_no_suffix)
"h5",
"archuctmeta data has the suffix" <<endl;
1284 else "h5",
"archmeta data doesn't have the suffix" <<endl;
1289 else if (((s_one_oname.find(
"SubsetMetadata"))==0) ||
1290 ((s_one_oname.find(
"subsetmetadata"))==0)){
1292 metatype[i] = SubsetMeta;
1297 if (
false == submeta_no_suffix) {
1298 H5Gclose(ecs_grp_id);
1299 string msg =
"submetadata/SubMetadata without suffix should only appear once. ";
1300 throw InternalErr(__FILE__, __LINE__, msg);
1303 else if(submeta_num_total >0)
1304 submeta_num_total++;
1306 if ((0 == s_one_oname.compare(
"SubsetMetadata"))||
1307 (0 == s_one_oname.compare(
"subsetmetadata")))
1308 submeta_no_suffix =
false;
1309 else submeta_num_total++;
1312 "h5",
"submeta_num_total= "<<submeta_num_total <<endl;
1313 if(submeta_no_suffix)
"h5",
"subuctmeta data has the suffix" <<endl;
1314 else "h5",
"submeta data doesn't have the suffix" <<endl;
1319 else if ((0 == (s_one_oname.find(
"XmlMetadata"))) ||
1320 (0 == (s_one_oname.find(
"xmlmetadata")))){
1322 metatype[i] = XMLMeta;
1328 if (
false == xmlmeta_no_suffix) {
1329 H5Gclose(ecs_grp_id);
1330 string msg =
"xmlmetadata/Xmlmetadata without suffix should only appear once. ";
1331 throw InternalErr(__FILE__, __LINE__, msg);
1334 else if(xmlmeta_num_total >0)
1335 xmlmeta_num_total++;
1337 if ((0 == s_one_oname.compare(
"XmlMetadata"))||
1338 (0 == s_one_oname.compare(
"xmlmetadata")))
1339 xmlmeta_no_suffix =
false;
1340 else xmlmeta_num_total++;
1343 "h5",
"xmlmeta_num_total= "<<xmlmeta_num_total <<endl;
1344 if(xmlmeta_no_suffix)
"h5",
"xmluctmeta data doesn't have the suffix" <<endl;
1345 else "h5",
"xmlmeta data has the suffix" <<endl;
1350 else if ((0 == (s_one_oname.find(
"ProductMetadata"))) ||
1351 (0 == (s_one_oname.find(
"productmetadata")))){
1353 metatype[i] = ProductMeta;
1358 if (!prometa_no_suffix) {
1359 H5Gclose(ecs_grp_id);
1360 string msg =
"productmetadata/ProductMetadata without suffix should only appear once. ";
1361 throw InternalErr(__FILE__, __LINE__, msg);
1364 else if(prometa_num_total >0) prometa_num_total++;
1366 if ((0 == s_one_oname.compare(
"ProductMetadata"))||
1367 (0 == s_one_oname.compare(
"productmetadata")))
1368 prometa_no_suffix =
false;
1369 else prometa_num_total++;
1375 else othermeta_num_total++;
1379 s_one_oname.clear();
1384 vector<string> strmeta_value;
1385 if (strmeta_num_total <= 0) {
1386 string msg =
"hdf5 object name error from: ";
1387 H5Gclose(ecs_grp_id);
1388 throw InternalErr(__FILE__, __LINE__, msg);
1391 strmeta_value.resize(strmeta_num_total);
1392 for (
int i = 0; i < strmeta_num_total; i++)
1393 strmeta_value[i]=
"";
1398 vector<string> archmeta_value;
1399 if (archmeta_num_total >0) {
1400 archmeta_value.resize(archmeta_num_total);
1401 for (
int i = 0; i < archmeta_num_total; i++)
1402 archmeta_value[i]=
"";
1406 vector<string> coremeta_value;
1407 if (coremeta_num_total >0) {
1408 coremeta_value.resize(coremeta_num_total);
1409 for (
int i = 0; i < coremeta_num_total; i++)
1410 coremeta_value[i]=
"";
1414 vector<string> xmlmeta_value;
1415 if (xmlmeta_num_total >0) {
1416 xmlmeta_value.resize(xmlmeta_num_total);
1417 for (
int i = 0; i < xmlmeta_num_total; i++)
1418 xmlmeta_value[i]=
"";
1422 vector<string> submeta_value;
1423 if (submeta_num_total >0) {
1424 submeta_value.resize(submeta_num_total);
1425 for (
int i = 0; i < submeta_num_total; i++)
1426 submeta_value[i]=
"";
1430 vector<string> prometa_value;
1431 if (prometa_num_total >0) {
1432 prometa_value.resize(prometa_num_total);
1433 for (
int i = 0; i < prometa_num_total; i++)
1434 prometa_value[i]=
"";
1442 for (hsize_t i = 0; i < nelems; i++) {
1450 if (
true == s_st_only &&
1451 (((s_oname[i].find(
"StructMetadata"))!=0) &&
1452 ((s_oname[i].find(
"structmetadata"))!=0))){
1457 hid_t s_dset_id = -1;
1458 hid_t s_space_id = -1;
1460 hssize_t s_nelms = -1;
1461 size_t dtype_size = -1;
1463 if ((s_dset_id = H5Dopen(ecs_grp_id,s_oname[i].c_str(),H5P_DEFAULT))<0){
1464 string msg =
"Cannot open HDF5 dataset ";
1466 H5Gclose(ecs_grp_id);
1467 throw InternalErr(__FILE__, __LINE__, msg);
1470 if ((s_space_id = H5Dget_space(s_dset_id))<0) {
1471 string msg =
"Cannot open the data space of HDF5 dataset ";
1473 H5Dclose(s_dset_id);
1474 H5Gclose(ecs_grp_id);
1475 throw InternalErr(__FILE__, __LINE__, msg);
1478 if ((s_ty_id = H5Dget_type(s_dset_id)) < 0) {
1479 string msg =
"Cannot get the data type of HDF5 dataset ";
1481 H5Sclose(s_space_id);
1482 H5Dclose(s_dset_id);
1483 H5Gclose(ecs_grp_id);
1484 throw InternalErr(__FILE__, __LINE__, msg);
1486 if ((s_nelms = H5Sget_simple_extent_npoints(s_space_id))<0) {
1487 string msg =
"Cannot get the number of points of HDF5 dataset ";
1490 H5Sclose(s_space_id);
1491 H5Dclose(s_dset_id);
1492 H5Gclose(ecs_grp_id);
1493 throw InternalErr(__FILE__, __LINE__, msg);
1495 if ((dtype_size = H5Tget_size(s_ty_id))==0) {
1497 string msg =
"Cannot get the data type size of HDF5 dataset ";
1500 H5Sclose(s_space_id);
1501 H5Dclose(s_dset_id);
1502 H5Gclose(ecs_grp_id);
1503 throw InternalErr(__FILE__, __LINE__, msg);
1507 vector<char> s_buf(dtype_size*s_nelms +1);
1509 if ((H5Dread(s_dset_id,s_ty_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,&s_buf[0]))<0) {
1511 string msg =
"Cannot read HDF5 dataset ";
1514 H5Sclose(s_space_id);
1515 H5Dclose(s_dset_id);
1516 H5Gclose(ecs_grp_id);
1517 throw InternalErr(__FILE__, __LINE__, msg);
1522 H5Sclose(s_space_id);
1523 H5Dclose(s_dset_id);
1527 string tempstr(s_buf.begin(),s_buf.end());
1529 size_t temp_null_pos = tempstr.find_first_of(
'\0');
1534 string finstr = tempstr.substr(0,temp_null_pos);
1537 if (StructMeta == metatype[i]) {
1541 strmeta_num = get_metadata_num(s_oname[i]);
1544 H5Gclose(ecs_grp_id);
1545 throw InternalErr(__FILE__,__LINE__,
"Obtain structmetadata suffix error.");
1552 if (-1 == strmeta_num)
1553 total_strmeta_value = finstr;
1555 else if (strmeta_value[strmeta_num]!=
"") {
1556 string msg =
"The structmeta value array at this index should be empty string ";
1557 H5Gclose(ecs_grp_id);
1558 throw InternalErr(__FILE__, __LINE__, msg);
1562 strmeta_value[strmeta_num] = finstr;
1566 if (
false == s_st_only &&
1567 (metatype[i] != StructMeta)) {
1569 switch (metatype[i]) {
1573 if (coremeta_num_total < 0) {
1574 string msg =
"There may be no coremetadata or coremetadata is not counted ";
1575 H5Gclose(ecs_grp_id);
1576 throw InternalErr(__FILE__, __LINE__, msg);
1581 coremeta_num = get_metadata_num(s_oname[i]);
1584 H5Gclose(ecs_grp_id);
1585 throw InternalErr(__FILE__,__LINE__,
"Obtain coremetadata suffix error.");
1591 if ( -1 == coremeta_num )
1592 total_coremeta_value = finstr;
1593 else if (coremeta_value[coremeta_num]!=
"") {
1594 string msg =
"The coremeta value array at this index should be empty string ";
1595 H5Gclose(ecs_grp_id);
1596 throw InternalErr(__FILE__, __LINE__, msg);
1601 coremeta_value[coremeta_num] = finstr;
1607 if (archmeta_num_total < 0) {
1608 string msg =
"There may be no archivemetadata or archivemetadata is not counted ";
1609 H5Gclose(ecs_grp_id);
1610 throw InternalErr(__FILE__, __LINE__, msg);
1613 archmeta_num = get_metadata_num(s_oname[i]);
1616 H5Gclose(ecs_grp_id);
1617 throw InternalErr(__FILE__,__LINE__,
"Obtain archivemetadata suffix error.");
1619 if (-1 == archmeta_num )
1620 total_archmeta_value = finstr;
1621 else if (archmeta_value[archmeta_num]!=
"") {
1622 string msg =
"The archivemeta value array at this index should be empty string ";
1623 H5Gclose(ecs_grp_id);
1624 throw InternalErr(__FILE__, __LINE__, msg);
1629 archmeta_value[archmeta_num] = finstr;
1634 if (submeta_num_total < 0) {
1635 string msg =
"The subsetemeta value array at this index should be empty string ";
1636 H5Gclose(ecs_grp_id);
1637 throw InternalErr(__FILE__, __LINE__, msg);
1640 submeta_num = get_metadata_num(s_oname[i]);
1643 H5Gclose(ecs_grp_id);
1644 throw InternalErr(__FILE__,__LINE__,
"Obtain subsetmetadata suffix error.");
1646 if (-1 == submeta_num )
1647 total_submeta_value = finstr;
1648 else if (submeta_value[submeta_num]!=
"") {
1649 string msg =
"The submeta value array at this index should be empty string ";
1650 H5Gclose(ecs_grp_id);
1651 throw InternalErr(__FILE__, __LINE__, msg);
1655 submeta_value[submeta_num] = finstr;
1660 if (prometa_num_total < 0) {
1661 string msg =
"There may be no productmetadata or productmetadata is not counted ";
1662 H5Gclose(ecs_grp_id);
1663 throw InternalErr(__FILE__, __LINE__, msg);
1666 prometa_num = get_metadata_num(s_oname[i]);
1669 H5Gclose(ecs_grp_id);
1670 throw InternalErr(__FILE__,__LINE__,
"Obtain productmetadata suffix error.");
1672 if (prometa_num == -1)
1673 total_prometa_value = finstr;
1674 else if (prometa_value[prometa_num]!=
"") {
1675 string msg =
"The productmeta value array at this index should be empty string ";
1676 H5Gclose(ecs_grp_id);
1677 throw InternalErr(__FILE__, __LINE__, msg);
1681 prometa_value[prometa_num] = finstr;
1686 if (xmlmeta_num_total < 0) {
1687 string msg =
"There may be no xmlmetadata or xmlmetadata is not counted ";
1688 H5Gclose(ecs_grp_id);
1689 throw InternalErr(__FILE__, __LINE__, msg);
1692 xmlmeta_num = get_metadata_num(s_oname[i]);
1695 H5Gclose(ecs_grp_id);
1696 throw InternalErr(__FILE__,__LINE__,
"Obtain XMLmetadata suffix error.");
1698 if (-1 == xmlmeta_num )
1699 total_xmlmeta_value = finstr;
1700 else if (xmlmeta_value[xmlmeta_num]!=
"") {
1701 string msg =
"The xmlmeta value array at this index should be empty string ";
1702 H5Gclose(ecs_grp_id);
1703 throw InternalErr(__FILE__, __LINE__, msg);
1707 xmlmeta_value[xmlmeta_num] = finstr;
1712 if (othermeta_num_total < 0) {
1713 string msg =
"There may be no othermetadata or other metadata is not counted ";
1714 H5Gclose(ecs_grp_id);
1715 throw InternalErr(__FILE__, __LINE__, msg);
1717 total_othermeta_value = total_othermeta_value + finstr;
1722 string msg =
"Unsupported metadata type ";
1723 H5Gclose(ecs_grp_id);
1724 throw InternalErr(__FILE__, __LINE__, msg);
1734 if (strmeta_num_total > 0) {
1736 if (strmeta_num != -1) {
1737 for (
int i = 0; i <strmeta_num_total; i++)
1738 total_strmeta_value +=strmeta_value[i];
1743 if (
false == s_st_only) {
1745 if (coremeta_num_total >0) {
1746 if (coremeta_num != -1) {
1747 for(
int i = 0; i <coremeta_num_total; i++)
1748 total_coremeta_value +=coremeta_value[i];
1752 if (archmeta_num_total >0) {
1753 if (archmeta_num != -1) {
1754 for(
int i = 0; i <archmeta_num_total; i++)
1755 total_archmeta_value +=archmeta_value[i];
1759 if (submeta_num_total >0) {
1760 if (submeta_num != -1) {
1761 for(
int i = 0; i <submeta_num_total; i++)
1762 total_submeta_value +=submeta_value[i];
1766 if (xmlmeta_num_total >0) {
1767 if (xmlmeta_num != -1) {
1768 for(
int i = 0; i <xmlmeta_num_total; i++)
1769 total_xmlmeta_value +=xmlmeta_value[i];
1773 if (prometa_num_total >0) {
1774 if (prometa_num != -1) {
1775 for(
int i = 0; i <prometa_num_total; i++)
1776 total_prometa_value +=prometa_value[i];
1780 H5Gclose(ecs_grp_id);
1784 int get_metadata_num(
const string & meta_str) {
1789 size_t dot_pos = meta_str.find(
".");
1790 if (dot_pos == string::npos)
1792 else if (meta_str.find_first_of(
".") == meta_str.find_last_of(
".")) {
1793 string num_str = meta_str.substr(dot_pos+1);
1794 stringstream ssnum(num_str);
1798 throw InternalErr(__FILE__,__LINE__,
"Suffix after dots is not a number.");
1802 string str_after_first_dot = meta_str.substr(dot_pos+1);
1803 if (str_after_first_dot.find_first_of(
".") != str_after_first_dot.find_last_of(
"."))
1804 throw InternalErr(__FILE__,__LINE__,
"Currently don't support metadata names containing more than two dots.");
1809 size_t second_dot_pos = str_after_first_dot.find(
".");
1810 string num_str = str_after_first_dot.substr(second_dot_pos+1);
1811 stringstream ssnum(num_str);