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) {
776 gen_dap_oneobj_das(at,*it_ra,NULL);
781 for (it_v = vars.begin();
782 it_v != vars.end(); ++it_v) {
783 if (
false == ((*it_v)->getAttributes().empty())) {
786 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
790 AttrTable *at = das.get_table((*it_v)->getNewName());
792 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
794 for (it_ra = (*it_v)->getAttributes().begin();
795 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
796 gen_dap_oneobj_das(at,*it_ra,*it_v);
801 for (it_cv = cvars.begin(); it_cv !=cvars.end();it_cv++) {
803 if (
false == ((*it_cv)->getAttributes().empty())) {
806 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
810 AttrTable *at = das.get_table((*it_cv)->getNewName());
812 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
815 for (it_ra = (*it_cv)->getAttributes().begin();
816 it_ra != (*it_cv)->getAttributes().end(); ++it_ra) {
817 gen_dap_oneobj_das(at,*it_ra,*it_cv);
823 unsigned short cv_lat_miss_index = 1;
825 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
826 if((*it_cv)->getCVType() == CV_LAT_MISS) {
827 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
828 gen_dap_oneeos5cf_das(das,vars,*it_cv,cv_lat_miss_index);
834 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
835 if((*it_cv)->getProjCode() == HE5_GCTP_LAMAZ) {
836 if((*it_cv)->getCVType() == CV_LAT_MISS || (*it_cv)->getCVType() == CV_LON_MISS) {
837 AttrTable *at = das.get_table((*it_cv)->getNewName());
839 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
840 if((*it_cv)->getCVType() == CV_LAT_MISS)
841 add_ll_valid_range(at,
true);
843 add_ll_valid_range(at,
false);
849 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
851 if(disable_ecsmetadata ==
false) {
860 string subset_str=
"";
861 string product_str=
"";
862 string other_str =
"";
863 bool st_only =
false;
865 read_ecs_metadata(file_id, st_str, core_str, arch_str, xml_str,
866 subset_str, product_str, other_str, st_only);
869 if(st_str!=
"")
"h5",
"Final structmetadata "<<st_str <<endl;
870 if(core_str!=
"")
"h5",
"Final coremetadata "<<core_str <<endl;
871 if(arch_str!=
"")
"h5",
"Final archivedmetadata "<<arch_str <<endl;
872 if(xml_str!=
"")
"h5",
"Final xmlmetadata "<<xml_str <<endl;
873 if(subset_str!=
"")
"h5",
"Final subsetmetadata "<<subset_str <<endl;
874 if(product_str!=
"")
"h5",
"Final productmetadata "<<product_str <<endl;
875 if(other_str!=
"")
"h5",
"Final othermetadata "<<other_str <<endl;
881 string check_disable_smetadata_key =
"H5.DisableStructMetaAttr";
882 bool is_check_disable_smetadata =
false;
883 is_check_disable_smetadata = HDF5CFDAPUtil::check_beskeys(check_disable_smetadata_key);
885 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
887 if (
false == is_check_disable_smetadata) {
889 AttrTable *at = das.get_table(
"StructMetadata");
891 at = das.add_table(
"StructMetadata",
new AttrTable);
895 if (he5dasparse(&arg) != 0
896 ||
false == arg.status()){
898 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
899 <<
"StructMetadata " <<
" HDFEOS attribute" << endl;
908 AttrTable *at = das.get_table(
"CoreMetadata");
910 at = das.add_table(
"CoreMetadata",
new AttrTable);
913 if (he5dasparse(&arg) != 0
914 ||
false == arg.status()){
916 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
917 <<
"CoreMetadata " <<
" HDFEOS attribute" << endl;
923 AttrTable *at = das.get_table(
"ArchiveMetadata");
925 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
928 if (he5dasparse(&arg) != 0
929 ||
false == arg.status()){
931 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
932 <<
"ArchiveMetadata " <<
" HDFEOS attribute" << endl;
941 AttrTable *at = das.get_table(
"XMLMetadata");
943 at = das.add_table(
"XMLMetadata",
new AttrTable);
944 HDF5CFDAPUtil::replace_double_quote(xml_str);
945 at->append_attr(
"Contents",
"String",xml_str);
951 if(subset_str !=
""){
952 AttrTable *at = das.get_table(
"SubsetMetadata");
954 at = das.add_table(
"SubsetMetadata",
new AttrTable);
957 if (he5dasparse(&arg) != 0
958 ||
false == arg.status()) {
960 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
961 <<
"SubsetMetadata " <<
" HDFEOS attribute" << endl;
965 if(product_str !=
""){
966 AttrTable *at = das.get_table(
"ProductMetadata");
968 at = das.add_table(
"ProductMetadata",
new AttrTable);
971 if (he5dasparse(&arg) != 0
972 ||
false == arg.status()){
973 (*BESLog::TheLog())<<
"HDF-EOS5 parse error while processing a "
974 <<
"ProductMetadata " <<
" HDFEOS attribute" << endl;
982 if (other_str !=
""){
983 AttrTable *at = das.get_table(
"OtherMetadata");
985 at = das.add_table(
"OtherMetadata",
new AttrTable);
986 at->append_attr(
"Contents",
"String",other_str);
993 AttrTable *at = das.get_table(
"DODS_EXTRA");
995 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
996 string unlimited_names;
998 for (it_cv = cvars.begin();
999 it_cv != cvars.end(); it_cv++) {
1001 bool has_unlimited_dim =
false;
1004 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
1005 ird != (*it_cv)->getDimensions().end(); ++ird) {
1010 if((*ird)->HaveUnlimitedDim() ==
true) {
1012 if(unlimited_names==
"") {
1013 unlimited_names = (*ird)->getNewName();
1014 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
1017 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
1018 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
1019 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
1040 void read_ecs_metadata(hid_t s_file_id,
1041 string &total_strmeta_value,
1042 string &total_coremeta_value,
1043 string &total_archmeta_value,
1044 string &total_xmlmeta_value,
1045 string &total_submeta_value,
1046 string &total_prometa_value,
1047 string &total_othermeta_value,
1050 BESDEBUG(
"h5",
"Coming to read_ecs_metadata() "<<endl);
1051 string ecs_group =
"/HDFEOS INFORMATION";
1052 hid_t ecs_grp_id = -1;
1053 if ((ecs_grp_id = H5Gopen(s_file_id, ecs_group.c_str(),H5P_DEFAULT))<0) {
1055 "h5_ecs_meta: unable to open the HDF5 group ";
1057 throw InternalErr(__FILE__, __LINE__, msg);
1063 if (H5Gget_info(ecs_grp_id,&g_info) <0) {
1065 "h5_ecs_meta: unable to obtain the HDF5 group info. for ";
1067 H5Gclose(ecs_grp_id);
1068 throw InternalErr(__FILE__, __LINE__, msg);
1071 nelems = g_info.nlinks;
1073 ssize_t oname_size = 0;
1075 int cur_archmeta_suffix = 0;
1076 int cur_coremeta_suffix = 0;
1077 int cur_strmeta_suffix = 0;
1078 int cur_xmlmeta_suffix = 0;
1081 int archmeta_num = -1;
1082 int coremeta_num = -1;
1083 int xmlmeta_num = -1;
1084 int strmeta_num = -1;
1085 int submeta_num = -1;
1086 int prometa_num = -1;
1089 int archmeta_num_total = 0;
1090 int coremeta_num_total = 0;
1091 int xmlmeta_num_total = 0;
1092 int strmeta_num_total = 0;
1093 int submeta_num_total = 0;
1094 int prometa_num_total = 0;
1095 int othermeta_num_total = 0;
1097 bool archmeta_no_suffix =
true;
1098 bool coremeta_no_suffix =
true;
1099 bool strmeta_no_suffix =
true;
1100 bool xmlmeta_no_suffix =
true;
1101 bool submeta_no_suffix =
true;
1102 bool prometa_no_suffix =
true;
1105 vector<string> s_oname(nelems);
1109 EOS5Metadata metatype[nelems];
1111 for (
unsigned int i =0; i<nelems; i++)
1112 metatype[i] = OtherMeta;
1114 for (hsize_t i = 0; i < nelems; i++) {
1118 H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
1120 if (oname_size <= 0) {
1121 string msg =
"hdf5 object name error from: ";
1123 H5Gclose(ecs_grp_id);
1124 throw InternalErr(__FILE__, __LINE__, msg);
1128 vector<char> oname(oname_size + 1);
1129 if (H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
1130 (
size_t)(oname_size+1), H5P_DEFAULT)<0){
1131 string msg =
"hdf5 object name error from: ";
1133 H5Gclose(ecs_grp_id);
1134 throw InternalErr(__FILE__, __LINE__, msg);
1140 if (H5Lget_info(ecs_grp_id,&oname[0],&linfo,H5P_DEFAULT)<0) {
1141 string msg =
"hdf5 link name error from: ";
1143 H5Gclose(ecs_grp_id);
1144 throw InternalErr(__FILE__, __LINE__, msg);
1148 if (linfo.type == H5L_TYPE_SOFT){
1149 string msg =
"hdf5 link name error from: ";
1151 H5Gclose(ecs_grp_id);
1152 throw InternalErr(__FILE__, __LINE__, msg);
1157 if (H5Oget_info_by_idx(ecs_grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
1158 i, &oinfo, H5P_DEFAULT)<0) {
1159 string msg =
"Cannot obtain the object info ";
1161 H5Gclose(ecs_grp_id);
1162 throw InternalErr(__FILE__, __LINE__, msg);
1165 if(oinfo.type != H5O_TYPE_DATASET) {
1166 string msg =
"hdf5 link name error from: ";
1168 H5Gclose(ecs_grp_id);
1169 throw InternalErr(__FILE__, __LINE__, msg);
1173 string s_one_oname(oname.begin(),oname.end()-1);
1174 s_oname[i] = s_one_oname;
1177 if (((s_one_oname.find(
"StructMetadata"))==0) ||
1178 ((s_one_oname.find(
"structmetadata"))==0)){
1180 metatype[i] = StructMeta;
1187 if (
false == strmeta_no_suffix) {
1188 string msg =
"StructMetadata/structmetadata without suffix should only appear once. ";
1189 H5Gclose(ecs_grp_id);
1190 throw InternalErr(__FILE__, __LINE__, msg);
1193 else if(strmeta_num_total >0)
1194 strmeta_num_total++;
1196 if ((0 == s_one_oname.compare(
"StructMetadata"))||
1197 (0 == s_one_oname.compare(
"structmetadata")))
1198 strmeta_no_suffix =
false;
1199 else strmeta_num_total++;
1202 "h5",
"strmeta_num_total= "<<strmeta_num_total <<endl;
1203 if(strmeta_no_suffix)
"h5",
"structmeta data has the suffix" <<endl;
1204 else "h5",
"structmeta data doesn't have the suffix" <<endl;
1208 if(
false == s_st_only) {
1210 if ((0 == (s_one_oname.find(
"CoreMetadata"))) ||
1211 (0 == (s_one_oname.find(
"coremetadata")))){
1213 metatype[i] = CoreMeta;
1219 if (
false == coremeta_no_suffix) {
1220 string msg =
"CoreMetadata/coremetadata without suffix should only appear once. ";
1221 H5Gclose(ecs_grp_id);
1222 throw InternalErr(__FILE__, __LINE__, msg);
1225 else if(coremeta_num_total >0)
1226 coremeta_num_total++;
1231 if ((0 == s_one_oname.compare(
"CoreMetadata")) ||
1232 (0 == s_one_oname.compare(
"coremetadata")))
1233 coremeta_no_suffix =
false;
1234 else coremeta_num_total++;
1237 "h5",
"coremeta_num_total= "<<coremeta_num_total <<endl;
1238 if(coremeta_no_suffix)
"h5",
"coreuctmeta data has the suffix" <<endl;
1239 else "h5",
"coremeta data doesn't have the suffix" <<endl;
1244 else if ((0 == (s_one_oname.find(
"ArchivedMetadata"))) ||
1245 (0 == (s_one_oname.find(
"archivedmetadata"))) ||
1246 (0 == (s_one_oname.find(
"ArchiveMetadata"))) ||
1247 (0 == (s_one_oname.find(
"archivemetadata")))){
1249 metatype[i] = ArchivedMeta;
1254 if (
false == archmeta_no_suffix) {
1255 string msg =
"archivedmetadata/ArchivedMetadata without suffix should only appear once. ";
1256 H5Gclose(ecs_grp_id);
1257 throw InternalErr(__FILE__, __LINE__, msg);
1260 else if(archmeta_num_total >0)
1261 archmeta_num_total++;
1263 if ((0 == s_one_oname.compare(
"ArchivedMetadata"))||
1264 (0 == s_one_oname.compare(
"archivedmetadata")) ||
1265 (0 == s_one_oname.compare(
"archivemetadata")) ||
1266 (0 == s_one_oname.compare(
"ArchiveMetadata")))
1267 archmeta_no_suffix =
false;
1269 archmeta_num_total++;
1272 "h5",
"archmeta_num_total= "<<archmeta_num_total <<endl;
1273 if(archmeta_no_suffix)
"h5",
"archuctmeta data has the suffix" <<endl;
1274 else "h5",
"archmeta data doesn't have the suffix" <<endl;
1279 else if (((s_one_oname.find(
"SubsetMetadata"))==0) ||
1280 ((s_one_oname.find(
"subsetmetadata"))==0)){
1282 metatype[i] = SubsetMeta;
1287 if (
false == submeta_no_suffix) {
1288 H5Gclose(ecs_grp_id);
1289 string msg =
"submetadata/SubMetadata without suffix should only appear once. ";
1290 throw InternalErr(__FILE__, __LINE__, msg);
1293 else if(submeta_num_total >0)
1294 submeta_num_total++;
1296 if ((0 == s_one_oname.compare(
"SubsetMetadata"))||
1297 (0 == s_one_oname.compare(
"subsetmetadata")))
1298 submeta_no_suffix =
false;
1299 else submeta_num_total++;
1302 "h5",
"submeta_num_total= "<<submeta_num_total <<endl;
1303 if(submeta_no_suffix)
"h5",
"subuctmeta data has the suffix" <<endl;
1304 else "h5",
"submeta data doesn't have the suffix" <<endl;
1309 else if ((0 == (s_one_oname.find(
"XmlMetadata"))) ||
1310 (0 == (s_one_oname.find(
"xmlmetadata")))){
1312 metatype[i] = XMLMeta;
1318 if (
false == xmlmeta_no_suffix) {
1319 H5Gclose(ecs_grp_id);
1320 string msg =
"xmlmetadata/Xmlmetadata without suffix should only appear once. ";
1321 throw InternalErr(__FILE__, __LINE__, msg);
1324 else if(xmlmeta_num_total >0)
1325 xmlmeta_num_total++;
1327 if ((0 == s_one_oname.compare(
"XmlMetadata"))||
1328 (0 == s_one_oname.compare(
"xmlmetadata")))
1329 xmlmeta_no_suffix =
false;
1330 else xmlmeta_num_total++;
1333 "h5",
"xmlmeta_num_total= "<<xmlmeta_num_total <<endl;
1334 if(xmlmeta_no_suffix)
"h5",
"xmluctmeta data doesn't have the suffix" <<endl;
1335 else "h5",
"xmlmeta data has the suffix" <<endl;
1340 else if ((0 == (s_one_oname.find(
"ProductMetadata"))) ||
1341 (0 == (s_one_oname.find(
"productmetadata")))){
1343 metatype[i] = ProductMeta;
1348 if (!prometa_no_suffix) {
1349 H5Gclose(ecs_grp_id);
1350 string msg =
"productmetadata/ProductMetadata without suffix should only appear once. ";
1351 throw InternalErr(__FILE__, __LINE__, msg);
1354 else if(prometa_num_total >0) prometa_num_total++;
1356 if ((0 == s_one_oname.compare(
"ProductMetadata"))||
1357 (0 == s_one_oname.compare(
"productmetadata")))
1358 prometa_no_suffix =
false;
1359 else prometa_num_total++;
1365 else othermeta_num_total++;
1369 s_one_oname.clear();
1374 vector<string> strmeta_value;
1375 if (strmeta_num_total <= 0) {
1376 string msg =
"hdf5 object name error from: ";
1377 H5Gclose(ecs_grp_id);
1378 throw InternalErr(__FILE__, __LINE__, msg);
1381 strmeta_value.resize(strmeta_num_total);
1382 for (
int i = 0; i < strmeta_num_total; i++)
1383 strmeta_value[i]=
"";
1388 vector<string> archmeta_value;
1389 if (archmeta_num_total >0) {
1390 archmeta_value.resize(archmeta_num_total);
1391 for (
int i = 0; i < archmeta_num_total; i++)
1392 archmeta_value[i]=
"";
1396 vector<string> coremeta_value;
1397 if (coremeta_num_total >0) {
1398 coremeta_value.resize(coremeta_num_total);
1399 for (
int i = 0; i < coremeta_num_total; i++)
1400 coremeta_value[i]=
"";
1404 vector<string> xmlmeta_value;
1405 if (xmlmeta_num_total >0) {
1406 xmlmeta_value.resize(xmlmeta_num_total);
1407 for (
int i = 0; i < xmlmeta_num_total; i++)
1408 xmlmeta_value[i]=
"";
1412 vector<string> submeta_value;
1413 if (submeta_num_total >0) {
1414 submeta_value.resize(submeta_num_total);
1415 for (
int i = 0; i < submeta_num_total; i++)
1416 submeta_value[i]=
"";
1420 vector<string> prometa_value;
1421 if (prometa_num_total >0) {
1422 prometa_value.resize(prometa_num_total);
1423 for (
int i = 0; i < prometa_num_total; i++)
1424 prometa_value[i]=
"";
1432 for (hsize_t i = 0; i < nelems; i++) {
1440 if (
true == s_st_only &&
1441 (((s_oname[i].find(
"StructMetadata"))!=0) &&
1442 ((s_oname[i].find(
"structmetadata"))!=0))){
1447 hid_t s_dset_id = -1;
1448 hid_t s_space_id = -1;
1450 hssize_t s_nelms = -1;
1451 size_t dtype_size = -1;
1453 if ((s_dset_id = H5Dopen(ecs_grp_id,s_oname[i].c_str(),H5P_DEFAULT))<0){
1454 string msg =
"Cannot open HDF5 dataset ";
1456 H5Gclose(ecs_grp_id);
1457 throw InternalErr(__FILE__, __LINE__, msg);
1460 if ((s_space_id = H5Dget_space(s_dset_id))<0) {
1461 string msg =
"Cannot open the data space of HDF5 dataset ";
1463 H5Dclose(s_dset_id);
1464 H5Gclose(ecs_grp_id);
1465 throw InternalErr(__FILE__, __LINE__, msg);
1468 if ((s_ty_id = H5Dget_type(s_dset_id)) < 0) {
1469 string msg =
"Cannot get the data type of HDF5 dataset ";
1471 H5Sclose(s_space_id);
1472 H5Dclose(s_dset_id);
1473 H5Gclose(ecs_grp_id);
1474 throw InternalErr(__FILE__, __LINE__, msg);
1476 if ((s_nelms = H5Sget_simple_extent_npoints(s_space_id))<0) {
1477 string msg =
"Cannot get the number of points of HDF5 dataset ";
1480 H5Sclose(s_space_id);
1481 H5Dclose(s_dset_id);
1482 H5Gclose(ecs_grp_id);
1483 throw InternalErr(__FILE__, __LINE__, msg);
1485 if ((dtype_size = H5Tget_size(s_ty_id))==0) {
1487 string msg =
"Cannot get the data type size of HDF5 dataset ";
1490 H5Sclose(s_space_id);
1491 H5Dclose(s_dset_id);
1492 H5Gclose(ecs_grp_id);
1493 throw InternalErr(__FILE__, __LINE__, msg);
1497 vector<char> s_buf(dtype_size*s_nelms +1);
1499 if ((H5Dread(s_dset_id,s_ty_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,&s_buf[0]))<0) {
1501 string msg =
"Cannot read HDF5 dataset ";
1504 H5Sclose(s_space_id);
1505 H5Dclose(s_dset_id);
1506 H5Gclose(ecs_grp_id);
1507 throw InternalErr(__FILE__, __LINE__, msg);
1512 H5Sclose(s_space_id);
1513 H5Dclose(s_dset_id);
1517 string tempstr(s_buf.begin(),s_buf.end());
1519 size_t temp_null_pos = tempstr.find_first_of(
'\0');
1524 string finstr = tempstr.substr(0,temp_null_pos);
1527 if (StructMeta == metatype[i]) {
1531 strmeta_num = get_metadata_num(s_oname[i]);
1534 H5Gclose(ecs_grp_id);
1535 throw InternalErr(__FILE__,__LINE__,
"Obtain structmetadata suffix error.");
1542 if (-1 == strmeta_num)
1543 total_strmeta_value = finstr;
1545 else if (strmeta_value[strmeta_num]!=
"") {
1546 string msg =
"The structmeta value array at this index should be empty string ";
1547 H5Gclose(ecs_grp_id);
1548 throw InternalErr(__FILE__, __LINE__, msg);
1552 strmeta_value[strmeta_num] = finstr;
1556 if (
false == s_st_only &&
1557 (metatype[i] != StructMeta)) {
1559 switch (metatype[i]) {
1563 if (coremeta_num_total < 0) {
1564 string msg =
"There may be no coremetadata or coremetadata is not counted ";
1565 H5Gclose(ecs_grp_id);
1566 throw InternalErr(__FILE__, __LINE__, msg);
1571 coremeta_num = get_metadata_num(s_oname[i]);
1574 H5Gclose(ecs_grp_id);
1575 throw InternalErr(__FILE__,__LINE__,
"Obtain coremetadata suffix error.");
1581 if ( -1 == coremeta_num )
1582 total_coremeta_value = finstr;
1583 else if (coremeta_value[coremeta_num]!=
"") {
1584 string msg =
"The coremeta value array at this index should be empty string ";
1585 H5Gclose(ecs_grp_id);
1586 throw InternalErr(__FILE__, __LINE__, msg);
1591 coremeta_value[coremeta_num] = finstr;
1597 if (archmeta_num_total < 0) {
1598 string msg =
"There may be no archivemetadata or archivemetadata is not counted ";
1599 H5Gclose(ecs_grp_id);
1600 throw InternalErr(__FILE__, __LINE__, msg);
1603 archmeta_num = get_metadata_num(s_oname[i]);
1606 H5Gclose(ecs_grp_id);
1607 throw InternalErr(__FILE__,__LINE__,
"Obtain archivemetadata suffix error.");
1609 if (-1 == archmeta_num )
1610 total_archmeta_value = finstr;
1611 else if (archmeta_value[archmeta_num]!=
"") {
1612 string msg =
"The archivemeta value array at this index should be empty string ";
1613 H5Gclose(ecs_grp_id);
1614 throw InternalErr(__FILE__, __LINE__, msg);
1619 archmeta_value[archmeta_num] = finstr;
1624 if (submeta_num_total < 0) {
1625 string msg =
"The subsetemeta value array at this index should be empty string ";
1626 H5Gclose(ecs_grp_id);
1627 throw InternalErr(__FILE__, __LINE__, msg);
1630 submeta_num = get_metadata_num(s_oname[i]);
1633 H5Gclose(ecs_grp_id);
1634 throw InternalErr(__FILE__,__LINE__,
"Obtain subsetmetadata suffix error.");
1636 if (-1 == submeta_num )
1637 total_submeta_value = finstr;
1638 else if (submeta_value[submeta_num]!=
"") {
1639 string msg =
"The submeta value array at this index should be empty string ";
1640 H5Gclose(ecs_grp_id);
1641 throw InternalErr(__FILE__, __LINE__, msg);
1645 submeta_value[submeta_num] = finstr;
1650 if (prometa_num_total < 0) {
1651 string msg =
"There may be no productmetadata or productmetadata is not counted ";
1652 H5Gclose(ecs_grp_id);
1653 throw InternalErr(__FILE__, __LINE__, msg);
1656 prometa_num = get_metadata_num(s_oname[i]);
1659 H5Gclose(ecs_grp_id);
1660 throw InternalErr(__FILE__,__LINE__,
"Obtain productmetadata suffix error.");
1662 if (prometa_num == -1)
1663 total_prometa_value = finstr;
1664 else if (prometa_value[prometa_num]!=
"") {
1665 string msg =
"The productmeta value array at this index should be empty string ";
1666 H5Gclose(ecs_grp_id);
1667 throw InternalErr(__FILE__, __LINE__, msg);
1671 prometa_value[prometa_num] = finstr;
1676 if (xmlmeta_num_total < 0) {
1677 string msg =
"There may be no xmlmetadata or xmlmetadata is not counted ";
1678 H5Gclose(ecs_grp_id);
1679 throw InternalErr(__FILE__, __LINE__, msg);
1682 xmlmeta_num = get_metadata_num(s_oname[i]);
1685 H5Gclose(ecs_grp_id);
1686 throw InternalErr(__FILE__,__LINE__,
"Obtain XMLmetadata suffix error.");
1688 if (-1 == xmlmeta_num )
1689 total_xmlmeta_value = finstr;
1690 else if (xmlmeta_value[xmlmeta_num]!=
"") {
1691 string msg =
"The xmlmeta value array at this index should be empty string ";
1692 H5Gclose(ecs_grp_id);
1693 throw InternalErr(__FILE__, __LINE__, msg);
1697 xmlmeta_value[xmlmeta_num] = finstr;
1702 if (othermeta_num_total < 0) {
1703 string msg =
"There may be no othermetadata or other metadata is not counted ";
1704 H5Gclose(ecs_grp_id);
1705 throw InternalErr(__FILE__, __LINE__, msg);
1707 total_othermeta_value = total_othermeta_value + finstr;
1712 string msg =
"Unsupported metadata type ";
1713 H5Gclose(ecs_grp_id);
1714 throw InternalErr(__FILE__, __LINE__, msg);
1724 if (strmeta_num_total > 0) {
1726 if (strmeta_num != -1) {
1727 for (
int i = 0; i <strmeta_num_total; i++)
1728 total_strmeta_value +=strmeta_value[i];
1733 if (
false == s_st_only) {
1735 if (coremeta_num_total >0) {
1736 if (coremeta_num != -1) {
1737 for(
int i = 0; i <coremeta_num_total; i++)
1738 total_coremeta_value +=coremeta_value[i];
1742 if (archmeta_num_total >0) {
1743 if (archmeta_num != -1) {
1744 for(
int i = 0; i <archmeta_num_total; i++)
1745 total_archmeta_value +=archmeta_value[i];
1749 if (submeta_num_total >0) {
1750 if (submeta_num != -1) {
1751 for(
int i = 0; i <submeta_num_total; i++)
1752 total_submeta_value +=submeta_value[i];
1756 if (xmlmeta_num_total >0) {
1757 if (xmlmeta_num != -1) {
1758 for(
int i = 0; i <xmlmeta_num_total; i++)
1759 total_xmlmeta_value +=xmlmeta_value[i];
1763 if (prometa_num_total >0) {
1764 if (prometa_num != -1) {
1765 for(
int i = 0; i <prometa_num_total; i++)
1766 total_prometa_value +=prometa_value[i];
1770 H5Gclose(ecs_grp_id);
1774 int get_metadata_num(
const string & meta_str) {
1779 size_t dot_pos = meta_str.find(
".");
1780 if (dot_pos == string::npos)
1782 else if (meta_str.find_first_of(
".") == meta_str.find_last_of(
".")) {
1783 string num_str = meta_str.substr(dot_pos+1);
1784 stringstream ssnum(num_str);
1788 throw InternalErr(__FILE__,__LINE__,
"Suffix after dots is not a number.");
1792 string str_after_first_dot = meta_str.substr(dot_pos+1);
1793 if (str_after_first_dot.find_first_of(
".") != str_after_first_dot.find_last_of(
"."))
1794 throw InternalErr(__FILE__,__LINE__,
"Currently don't support metadata names containing more than two dots.");
1799 size_t second_dot_pos = str_after_first_dot.find(
".");
1800 string num_str = str_after_first_dot.substr(second_dot_pos+1);
1801 stringstream ssnum(num_str);