32#include "config_hdf5.h"
44#include <libdap/parser.h>
62#include "HDF5CFGeoCF1D.h"
63#include "HDF5CFGeoCFProj.h"
65#include "h5apicompatible.h"
67#include "he5dds.tab.hh"
70#include "he5das.tab.hh"
72struct yy_buffer_state;
74yy_buffer_state *he5dds_scan_string(
const char *str);
76int he5dasparse(libdap::parser_arg *arg);
77int he5ddslex_destroy();
78int he5daslex_destroy();
83using namespace HDF5CF;
86void map_eos5_cfdds(DDS &dds, hid_t file_id,
const string & filename) {
88 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
96 string product_str=
"";
101 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
104 "unable to obtain the HDF-EOS5 struct metadata ";
105 throw InternalErr(__FILE__, __LINE__, msg);
108 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
113 f =
new EOS5File(filename.c_str(),file_id);
116 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
119 bool include_attr =
false;
127 he5dds_scan_string(st_str.c_str());
132 p.add_projparams(st_str);
138 if (c.check_grids_unknown_parameters(&p)) {
139 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
142 if (c.check_grids_missing_projcode(&p)) {
143 throw InternalErr(
"The HDF-EOS5 is missing project code ");
147 if (c.check_grids_support_projcode(&p)) {
148 throw InternalErr(
"The current project code is not supported");
152 c.set_grids_missing_pixreg_orig(&p);
155 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
173 throw InternalErr(e.what());
199 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
200 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr)){
227 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
228 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
239 if(
true == is_check_nameclashing)
247 if(
true == is_check_nameclashing)
259 throw InternalErr(e.what());
264 gen_eos5_cfdds(dds,f);
277void map_eos5_cfdas(DAS &das, hid_t file_id,
const string &filename) {
279 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS mapping function map_eos5_cfdas "<<endl);
284 string subset_str=
"";
285 string product_str=
"";
286 string other_str =
"";
289 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
292 "unable to obtain the HDF-EOS5 struct metadata ";
293 throw InternalErr(__FILE__, __LINE__, msg);
296 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
298 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
302 f =
new EOS5File(filename.c_str(),file_id);
305 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
307 bool include_attr =
true;
314 he5dds_scan_string(st_str.c_str());
318 p.add_projparams(st_str);
324 if (c.check_grids_unknown_parameters(&p)) {
325 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
328 if (c.check_grids_missing_projcode(&p)) {
329 throw InternalErr(
"The HDF-EOS5 is missing project code ");
331 if (c.check_grids_support_projcode(&p)) {
332 throw InternalErr(
"The current project code is not supported");
334 c.set_grids_missing_pixreg_orig(&p);
336 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
346 throw InternalErr(e.what());
378 if (
true == is_check_nameclashing)
398 throw InternalErr(e.what());
403 gen_eos5_cfdas(das,file_id,f);
419 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function gen_eos5_cfdds "<<endl);
420 const vector<HDF5CF::Var *>& vars = f->
getVars();
421 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
422 const string filename = f->
getPath();
426 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
428 for (
auto it_v = vars.begin(); it_v !=vars.end();++it_v) {
429 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
430 gen_dap_onevar_dds(dds,*it_v,file_id,filename);
433 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
434 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
435 gen_dap_oneeos5cvar_dds(dds,*it_cv,file_id,filename);
442 unsigned short cv_lat_miss_index = 1;
443 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
444 if((*it_cv)->getCVType() == CV_LAT_MISS) {
445 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
449 gen_dap_oneeos5cf_dds(dds,*it_cv);
450 add_cf_grid_mapinfo_var(dds,(*it_cv)->getProjCode(),cv_lat_miss_index);
459 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_dds() "<<endl);
461 float cv_point_lower = cvar->getPointLower();
462 float cv_point_upper = cvar->getPointUpper();
463 float cv_point_left = cvar->getPointLeft();
464 float cv_point_right = cvar->getPointRight();
465 EOS5GridPCType cv_proj_code = cvar->getProjCode();
466 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
468 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
469 add_cf_grid_cvs(dds,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
473void gen_dap_oneeos5cf_das(DAS &das,
const vector<HDF5CF::Var*>& vars,
const HDF5CF::EOS5CVar* cvar,
const unsigned short g_suffix) {
475 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_das() "<<endl);
477 float cv_point_lower = cvar->getPointLower();
478 float cv_point_upper = cvar->getPointUpper();
479 float cv_point_left = cvar->getPointLeft();
480 float cv_point_right = cvar->getPointRight();
482 EOS5GridPCType cv_proj_code = cvar->getProjCode();
483 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
486cerr<<
"cv_point_lower is "<<cv_point_lower <<endl;
487cerr<<
"cvar name is "<<cvar->
getName() <<endl;
488for(vector<HDF5CF::Dimension*>::const_iterator it_d = dims.begin(); it_d != dims.end(); ++it_d)
489 cerr<<
"dim name das is "<<(*it_d)->getNewName() <<endl;
493 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
495 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);
497 add_cf_grid_cv_attrs(das,vars,cv_proj_code,dims,cvar->getParams(),g_suffix);
504 BESDEBUG(
"h5",
"Coming to gen_eos5_cf_ignored_obj_info() "<<endl);
505 AttrTable *at = das.get_table(
"Ignored_Object_Info");
507 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
515void gen_dap_oneeos5cvar_dds(DDS &dds,
const HDF5CF::EOS5CVar* cvar,
const hid_t file_id,
const string & filename) {
517 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dds() "<<endl);
518 BaseType *bt =
nullptr;
524#define HANDLE_CASE(tid,type) \
526 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
537 HANDLE_CASE(H5FSTRING,
Str)
538 HANDLE_CASE(H5VSTRING,
Str)
540 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
546 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
547 vector <HDF5CF::Dimension*>:: const_iterator it_d;
548 vector <size_t> dimsizes;
549 dimsizes.resize(cvar->
getRank());
550 for(
int i = 0; i <cvar->
getRank();i++)
551 dimsizes[i] = (dims[i])->getSize();
555 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
562for(vector<HDF5CF::Attribute *>::const_iterator it_ra = cvar->getAttributes().begin();
563 it_ra != cvar->getAttributes().end(); ++it_ra) {
564cerr<<
"cvar attribute name is "<<(*it_ra)->getNewName() <<endl;
565cerr<<
"cvar attribute value type is "<<(*it_ra)->getType() <<endl;
567cerr<<
"cvar new name exist at he s5cfdap.cc is "<<cvar->
getNewName() <<endl;
569 bool is_latlon = cvar->isLatLon();
579 cvar->getTotalElems(),
589 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
592 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
593 if (
""==(*it_d)->getNewName())
594 ar->append_dim((
int)((*it_d)->getSize()));
596 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
612cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
613cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
614cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
622 cvar->getPointLower(),
623 cvar->getPointUpper(),
624 cvar->getPointLeft(),
625 cvar->getPointRight(),
639 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissLLArray.");
642 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
643 if (
""==(*it_d)->getNewName())
644 ar->append_dim((
int)((*it_d)->getSize()));
646 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
655 case CV_NONLATLON_MISS:
660 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
674 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissNonLLCVArray.");
678 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
679 if (
""==(*it_d)->getNewName())
680 ar->append_dim((
int)((*it_d)->getSize()));
682 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
698 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
716 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
720 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
721 if (
""==(*it_d)->getNewName())
722 ar->append_dim((
int)((*it_d)->getSize()));
724 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
734 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
744 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS generation function gen_eos5_cfdas "<<endl);
748 gen_eos5_cf_ignored_obj_info(das, f);
752 const vector<HDF5CF::Var *>& vars = f->
getVars();
753 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
754 const vector<HDF5CF::Group *>& grps = f->
getGroups();
755 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
757 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
758 vector<HDF5CF::Attribute *>::const_iterator it_ra;
762 if (
false == root_attrs.empty()) {
763 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
765 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
767 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); it_ra++) {
768 gen_dap_oneobj_das(at,*it_ra,
nullptr);
772 if (
false == grps.empty()) {
773 for (
auto it_g = grps.begin(); it_g != grps.end(); ++it_g) {
774 AttrTable *at = das.get_table((*it_g)->getNewName());
776 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
778 for (it_ra = (*it_g)->getAttributes().begin();
779 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
784 if((*it_ra)->getNewName()==
"Conventions" &&((*it_g)->getNewName() ==
"HDFEOS_ADDITIONAL_FILE_ATTRIBUTES")
785 && (
true==HDF5RequestHandler::get_eos5_rm_convention_attr_path())) {
786 AttrTable *at_das = das.get_table(FILE_ATTR_TABLE_NAME);
787 if (
nullptr == at_das)
788 at_das = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
789 gen_dap_oneobj_das(at_das,*it_ra,
nullptr);
792 gen_dap_oneobj_das(at,*it_ra,
nullptr);
797 for (
auto it_v = vars.begin(); it_v != vars.end(); ++it_v) {
798 if (
false == ((*it_v)->getAttributes().empty())) {
801 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
805 AttrTable *at = das.get_table((*it_v)->getNewName());
807 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
809 for (it_ra = (*it_v)->getAttributes().begin();
810 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
811 gen_dap_oneobj_das(at,*it_ra,*it_v);
816 for (it_cv = cvars.begin(); it_cv !=cvars.end();it_cv++) {
818 if (
false == ((*it_cv)->getAttributes().empty())) {
821 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
825 AttrTable *at = das.get_table((*it_cv)->getNewName());
827 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
829 for (it_ra = (*it_cv)->getAttributes().begin();
830 it_ra != (*it_cv)->getAttributes().end(); ++it_ra) {
831 gen_dap_oneobj_das(at,*it_ra,*it_cv);
837 unsigned short cv_lat_miss_index = 1;
839 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
840 if((*it_cv)->getCVType() == CV_LAT_MISS) {
841 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
842 gen_dap_oneeos5cf_das(das,vars,*it_cv,cv_lat_miss_index);
848 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
849 if((*it_cv)->getProjCode() == HE5_GCTP_LAMAZ) {
850 if((*it_cv)->getCVType() == CV_LAT_MISS || (*it_cv)->getCVType() == CV_LON_MISS) {
851 AttrTable *at = das.get_table((*it_cv)->getNewName());
853 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
854 if((*it_cv)->getCVType() == CV_LAT_MISS)
855 add_ll_valid_range(at,
true);
857 add_ll_valid_range(at,
false);
863 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
865 if(disable_ecsmetadata ==
false) {
874 string subset_str=
"";
875 string product_str=
"";
876 string other_str =
"";
877 bool st_only =
false;
879 read_ecs_metadata(file_id, st_str, core_str, arch_str, xml_str,
880 subset_str, product_str, other_str, st_only);
883if(st_str!=
"")
"h5",
"Final structmetadata "<<st_str <<endl;
884if(core_str!=
"")
"h5",
"Final coremetadata "<<core_str <<endl;
885if(arch_str!=
"")
"h5",
"Final archivedmetadata "<<arch_str <<endl;
886if(xml_str!=
"")
"h5",
"Final xmlmetadata "<<xml_str <<endl;
887if(subset_str!=
"")
"h5",
"Final subsetmetadata "<<subset_str <<endl;
888if(product_str!=
"")
"h5",
"Final productmetadata "<<product_str <<endl;
889if(other_str!=
"")
"h5",
"Final othermetadata "<<other_str <<endl;
895 string check_disable_smetadata_key =
"H5.DisableStructMetaAttr";
896 bool is_check_disable_smetadata =
false;
898 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
900 if (
false == is_check_disable_smetadata) {
902 AttrTable *at = das.get_table(
"StructMetadata");
904 at = das.add_table(
"StructMetadata",
new AttrTable);
908 if (he5dasparse(&arg) != 0
909 ||
false == arg.status()){
911 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
912 <<
"StructMetadata " <<
" HDFEOS attribute" << endl);
921 AttrTable *at = das.get_table(
"CoreMetadata");
923 at = das.add_table(
"CoreMetadata",
new AttrTable);
926 if (he5dasparse(&arg) != 0
927 ||
false == arg.status()){
929 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
930 <<
"CoreMetadata " <<
" HDFEOS attribute" << endl);
936 AttrTable *at = das.get_table(
"ArchiveMetadata");
938 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
941 if (he5dasparse(&arg) != 0
942 ||
false == arg.status()){
944 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
945 <<
"ArchiveMetadata " <<
" HDFEOS attribute" << endl);
954 AttrTable *at = das.get_table(
"XMLMetadata");
956 at = das.add_table(
"XMLMetadata",
new AttrTable);
957 HDF5CFDAPUtil::replace_double_quote(xml_str);
958 at->append_attr(
"Contents",
"String",xml_str);
964 if(subset_str !=
""){
965 AttrTable *at = das.get_table(
"SubsetMetadata");
967 at = das.add_table(
"SubsetMetadata",
new AttrTable);
970 if (he5dasparse(&arg) != 0
971 ||
false == arg.status()) {
973 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
974 <<
"SubsetMetadata " <<
" HDFEOS attribute" << endl);
978 if(product_str !=
""){
979 AttrTable *at = das.get_table(
"ProductMetadata");
981 at = das.add_table(
"ProductMetadata",
new AttrTable);
984 if (he5dasparse(&arg) != 0
985 ||
false == arg.status()){
986 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
987 <<
"ProductMetadata " <<
" HDFEOS attribute" << endl);
995 if (other_str !=
""){
996 AttrTable *at = das.get_table(
"OtherMetadata");
998 at = das.add_table(
"OtherMetadata",
new AttrTable);
999 at->append_attr(
"Contents",
"String",other_str);
1006 AttrTable *at = das.get_table(
"DODS_EXTRA");
1008 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
1009 string unlimited_names;
1011 for (it_cv = cvars.begin();
1012 it_cv != cvars.end(); it_cv++) {
1014 bool has_unlimited_dim =
false;
1017 for (
auto ird = (*it_cv)->getDimensions().begin();
1018 ird != (*it_cv)->getDimensions().end(); ++ird) {
1023 if((*ird)->HaveUnlimitedDim() ==
true) {
1025 if(unlimited_names==
"") {
1026 unlimited_names = (*ird)->getNewName();
1027 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
1030 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
1031 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
1032 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
1053void read_ecs_metadata(hid_t s_file_id,
1054 string &total_strmeta_value,
1055 string &total_coremeta_value,
1056 string &total_archmeta_value,
1057 string &total_xmlmeta_value,
1058 string &total_submeta_value,
1059 string &total_prometa_value,
1060 string &total_othermeta_value,
1063 BESDEBUG(
"h5",
"Coming to read_ecs_metadata() "<<endl);
1064 string ecs_group =
"/HDFEOS INFORMATION";
1065 hid_t ecs_grp_id = -1;
1066 if ((ecs_grp_id = H5Gopen(s_file_id, ecs_group.c_str(),H5P_DEFAULT))<0) {
1068 "h5_ecs_meta: unable to open the HDF5 group ";
1070 throw InternalErr(__FILE__, __LINE__, msg);
1076 if (H5Gget_info(ecs_grp_id,&g_info) <0) {
1078 "h5_ecs_meta: unable to obtain the HDF5 group info. for ";
1080 H5Gclose(ecs_grp_id);
1081 throw InternalErr(__FILE__, __LINE__, msg);
1084 nelems = g_info.nlinks;
1086 ssize_t oname_size = 0;
1088 int cur_archmeta_suffix = 0;
1089 int cur_coremeta_suffix = 0;
1090 int cur_strmeta_suffix = 0;
1091 int cur_xmlmeta_suffix = 0;
1094 int archmeta_num = -1;
1095 int coremeta_num = -1;
1096 int xmlmeta_num = -1;
1097 int strmeta_num = -1;
1098 int submeta_num = -1;
1099 int prometa_num = -1;
1102 int archmeta_num_total = 0;
1103 int coremeta_num_total = 0;
1104 int xmlmeta_num_total = 0;
1105 int strmeta_num_total = 0;
1106 int submeta_num_total = 0;
1107 int prometa_num_total = 0;
1108 int othermeta_num_total = 0;
1110 bool archmeta_no_suffix =
true;
1111 bool coremeta_no_suffix =
true;
1112 bool strmeta_no_suffix =
true;
1113 bool xmlmeta_no_suffix =
true;
1114 bool submeta_no_suffix =
true;
1115 bool prometa_no_suffix =
true;
1118 vector<string> s_oname(nelems);
1122 EOS5Metadata metatype[nelems];
1124 for (
unsigned int i =0; i<nelems; i++)
1125 metatype[i] = OtherMeta;
1127 for (hsize_t i = 0; i < nelems; i++) {
1131 H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
nullptr,
1133 if (oname_size <= 0) {
1134 string msg =
"hdf5 object name error from: ";
1136 H5Gclose(ecs_grp_id);
1137 throw InternalErr(__FILE__, __LINE__, msg);
1141 vector<char> oname(oname_size + 1);
1142 if (H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,oname.data(),
1143 (
size_t)(oname_size+1), H5P_DEFAULT)<0){
1144 string msg =
"hdf5 object name error from: ";
1146 H5Gclose(ecs_grp_id);
1147 throw InternalErr(__FILE__, __LINE__, msg);
1153 if (H5Lget_info(ecs_grp_id,oname.data(),&linfo,H5P_DEFAULT)<0) {
1154 string msg =
"hdf5 link name error from: ";
1156 H5Gclose(ecs_grp_id);
1157 throw InternalErr(__FILE__, __LINE__, msg);
1161 if (linfo.type == H5L_TYPE_SOFT){
1162 string msg =
"hdf5 link name error from: ";
1164 H5Gclose(ecs_grp_id);
1165 throw InternalErr(__FILE__, __LINE__, msg);
1170 if (H5OGET_INFO_BY_IDX(ecs_grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
1171 i, &oinfo, H5P_DEFAULT)<0) {
1172 string msg =
"Cannot obtain the object info ";
1174 H5Gclose(ecs_grp_id);
1175 throw InternalErr(__FILE__, __LINE__, msg);
1178 if(oinfo.type != H5O_TYPE_DATASET) {
1179 string msg =
"hdf5 link name error from: ";
1181 H5Gclose(ecs_grp_id);
1182 throw InternalErr(__FILE__, __LINE__, msg);
1186 string s_one_oname(oname.begin(),oname.end()-1);
1187 s_oname[i] = s_one_oname;
1190 if (((s_one_oname.find(
"StructMetadata"))==0) ||
1191 ((s_one_oname.find(
"structmetadata"))==0)){
1193 metatype[i] = StructMeta;
1200 if (
false == strmeta_no_suffix) {
1201 string msg =
"StructMetadata/structmetadata without suffix should only appear once. ";
1202 H5Gclose(ecs_grp_id);
1203 throw InternalErr(__FILE__, __LINE__, msg);
1206 else if(strmeta_num_total >0)
1207 strmeta_num_total++;
1209 if ((0 == s_one_oname.compare(
"StructMetadata"))||
1210 (0 == s_one_oname.compare(
"structmetadata")))
1211 strmeta_no_suffix =
false;
1212 else strmeta_num_total++;
1215"h5",
"strmeta_num_total= "<<strmeta_num_total <<endl;
1216if(strmeta_no_suffix)
"h5",
"structmeta data has the suffix" <<endl;
1217else "h5",
"structmeta data doesn't have the suffix" <<endl;
1221 if(
false == s_st_only) {
1223 if ((0 == (s_one_oname.find(
"CoreMetadata"))) ||
1224 (0 == (s_one_oname.find(
"coremetadata")))){
1226 metatype[i] = CoreMeta;
1232 if (
false == coremeta_no_suffix) {
1233 string msg =
"CoreMetadata/coremetadata without suffix should only appear once. ";
1234 H5Gclose(ecs_grp_id);
1235 throw InternalErr(__FILE__, __LINE__, msg);
1238 else if(coremeta_num_total >0)
1239 coremeta_num_total++;
1244 if ((0 == s_one_oname.compare(
"CoreMetadata")) ||
1245 (0 == s_one_oname.compare(
"coremetadata")))
1246 coremeta_no_suffix =
false;
1247 else coremeta_num_total++;
1250"h5",
"coremeta_num_total= "<<coremeta_num_total <<endl;
1251if(coremeta_no_suffix)
"h5",
"coreuctmeta data has the suffix" <<endl;
1252else "h5",
"coremeta data doesn't have the suffix" <<endl;
1257 else if ((0 == (s_one_oname.find(
"ArchivedMetadata"))) ||
1258 (0 == (s_one_oname.find(
"archivedmetadata"))) ||
1259 (0 == (s_one_oname.find(
"ArchiveMetadata"))) ||
1260 (0 == (s_one_oname.find(
"archivemetadata")))){
1262 metatype[i] = ArchivedMeta;
1267 if (
false == archmeta_no_suffix) {
1268 string msg =
"archivedmetadata/ArchivedMetadata without suffix should only appear once. ";
1269 H5Gclose(ecs_grp_id);
1270 throw InternalErr(__FILE__, __LINE__, msg);
1273 else if(archmeta_num_total >0)
1274 archmeta_num_total++;
1276 if ((0 == s_one_oname.compare(
"ArchivedMetadata"))||
1277 (0 == s_one_oname.compare(
"archivedmetadata")) ||
1278 (0 == s_one_oname.compare(
"archivemetadata")) ||
1279 (0 == s_one_oname.compare(
"ArchiveMetadata")))
1280 archmeta_no_suffix =
false;
1282 archmeta_num_total++;
1285"h5",
"archmeta_num_total= "<<archmeta_num_total <<endl;
1286if(archmeta_no_suffix)
"h5",
"archuctmeta data has the suffix" <<endl;
1287else "h5",
"archmeta data doesn't have the suffix" <<endl;
1292 else if (((s_one_oname.find(
"SubsetMetadata"))==0) ||
1293 ((s_one_oname.find(
"subsetmetadata"))==0)){
1295 metatype[i] = SubsetMeta;
1300 if (
false == submeta_no_suffix) {
1301 H5Gclose(ecs_grp_id);
1302 string msg =
"submetadata/SubMetadata without suffix should only appear once. ";
1303 throw InternalErr(__FILE__, __LINE__, msg);
1306 else if(submeta_num_total >0)
1307 submeta_num_total++;
1309 if ((0 == s_one_oname.compare(
"SubsetMetadata"))||
1310 (0 == s_one_oname.compare(
"subsetmetadata")))
1311 submeta_no_suffix =
false;
1312 else submeta_num_total++;
1315"h5",
"submeta_num_total= "<<submeta_num_total <<endl;
1316if(submeta_no_suffix)
"h5",
"subuctmeta data has the suffix" <<endl;
1317else "h5",
"submeta data doesn't have the suffix" <<endl;
1322 else if ((0 == (s_one_oname.find(
"XmlMetadata"))) ||
1323 (0 == (s_one_oname.find(
"xmlmetadata")))){
1325 metatype[i] = XMLMeta;
1331 if (
false == xmlmeta_no_suffix) {
1332 H5Gclose(ecs_grp_id);
1333 string msg =
"xmlmetadata/Xmlmetadata without suffix should only appear once. ";
1334 throw InternalErr(__FILE__, __LINE__, msg);
1337 else if(xmlmeta_num_total >0)
1338 xmlmeta_num_total++;
1340 if ((0 == s_one_oname.compare(
"XmlMetadata"))||
1341 (0 == s_one_oname.compare(
"xmlmetadata")))
1342 xmlmeta_no_suffix =
false;
1343 else xmlmeta_num_total++;
1346"h5",
"xmlmeta_num_total= "<<xmlmeta_num_total <<endl;
1347if(xmlmeta_no_suffix)
"h5",
"xmluctmeta data doesn't have the suffix" <<endl;
1348else "h5",
"xmlmeta data has the suffix" <<endl;
1353 else if ((0 == (s_one_oname.find(
"ProductMetadata"))) ||
1354 (0 == (s_one_oname.find(
"productmetadata")))){
1356 metatype[i] = ProductMeta;
1361 if (!prometa_no_suffix) {
1362 H5Gclose(ecs_grp_id);
1363 string msg =
"productmetadata/ProductMetadata without suffix should only appear once. ";
1364 throw InternalErr(__FILE__, __LINE__, msg);
1367 else if(prometa_num_total >0) prometa_num_total++;
1369 if ((0 == s_one_oname.compare(
"ProductMetadata"))||
1370 (0 == s_one_oname.compare(
"productmetadata")))
1371 prometa_no_suffix =
false;
1372 else prometa_num_total++;
1378 else othermeta_num_total++;
1382 s_one_oname.clear();
1387 vector<string> strmeta_value;
1388 if (strmeta_num_total <= 0) {
1389 string msg =
"hdf5 object name error from: ";
1390 H5Gclose(ecs_grp_id);
1391 throw InternalErr(__FILE__, __LINE__, msg);
1394 strmeta_value.resize(strmeta_num_total);
1395 for (
int i = 0; i < strmeta_num_total; i++)
1396 strmeta_value[i]=
"";
1401 vector<string> archmeta_value;
1402 if (archmeta_num_total >0) {
1403 archmeta_value.resize(archmeta_num_total);
1404 for (
int i = 0; i < archmeta_num_total; i++)
1405 archmeta_value[i]=
"";
1409 vector<string> coremeta_value;
1410 if (coremeta_num_total >0) {
1411 coremeta_value.resize(coremeta_num_total);
1412 for (
int i = 0; i < coremeta_num_total; i++)
1413 coremeta_value[i]=
"";
1417 vector<string> xmlmeta_value;
1418 if (xmlmeta_num_total >0) {
1419 xmlmeta_value.resize(xmlmeta_num_total);
1420 for (
int i = 0; i < xmlmeta_num_total; i++)
1421 xmlmeta_value[i]=
"";
1425 vector<string> submeta_value;
1426 if (submeta_num_total >0) {
1427 submeta_value.resize(submeta_num_total);
1428 for (
int i = 0; i < submeta_num_total; i++)
1429 submeta_value[i]=
"";
1433 vector<string> prometa_value;
1434 if (prometa_num_total >0) {
1435 prometa_value.resize(prometa_num_total);
1436 for (
int i = 0; i < prometa_num_total; i++)
1437 prometa_value[i]=
"";
1445 for (hsize_t i = 0; i < nelems; i++) {
1453 if (
true == s_st_only &&
1454 (((s_oname[i].find(
"StructMetadata"))!=0) &&
1455 ((s_oname[i].find(
"structmetadata"))!=0))){
1460 hid_t s_dset_id = -1;
1461 hid_t s_space_id = -1;
1463 hssize_t s_nelms = -1;
1464 size_t dtype_size = -1;
1466 if ((s_dset_id = H5Dopen(ecs_grp_id,s_oname[i].c_str(),H5P_DEFAULT))<0){
1467 string msg =
"Cannot open HDF5 dataset ";
1469 H5Gclose(ecs_grp_id);
1470 throw InternalErr(__FILE__, __LINE__, msg);
1473 if ((s_space_id = H5Dget_space(s_dset_id))<0) {
1474 string msg =
"Cannot open the data space of HDF5 dataset ";
1476 H5Dclose(s_dset_id);
1477 H5Gclose(ecs_grp_id);
1478 throw InternalErr(__FILE__, __LINE__, msg);
1481 if ((s_ty_id = H5Dget_type(s_dset_id)) < 0) {
1482 string msg =
"Cannot get the data type of HDF5 dataset ";
1484 H5Sclose(s_space_id);
1485 H5Dclose(s_dset_id);
1486 H5Gclose(ecs_grp_id);
1487 throw InternalErr(__FILE__, __LINE__, msg);
1489 if ((s_nelms = H5Sget_simple_extent_npoints(s_space_id))<0) {
1490 string msg =
"Cannot get the number of points of HDF5 dataset ";
1493 H5Sclose(s_space_id);
1494 H5Dclose(s_dset_id);
1495 H5Gclose(ecs_grp_id);
1496 throw InternalErr(__FILE__, __LINE__, msg);
1498 if ((dtype_size = H5Tget_size(s_ty_id))==0) {
1500 string msg =
"Cannot get the data type size of HDF5 dataset ";
1503 H5Sclose(s_space_id);
1504 H5Dclose(s_dset_id);
1505 H5Gclose(ecs_grp_id);
1506 throw InternalErr(__FILE__, __LINE__, msg);
1510 vector<char> s_buf(dtype_size*s_nelms +1);
1512 if ((H5Dread(s_dset_id,s_ty_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,s_buf.data()))<0) {
1514 string msg =
"Cannot read HDF5 dataset ";
1517 H5Sclose(s_space_id);
1518 H5Dclose(s_dset_id);
1519 H5Gclose(ecs_grp_id);
1520 throw InternalErr(__FILE__, __LINE__, msg);
1525 H5Sclose(s_space_id);
1526 H5Dclose(s_dset_id);
1530 string tempstr(s_buf.begin(),s_buf.end());
1532 size_t temp_null_pos = tempstr.find_first_of(
'\0');
1537 string finstr = tempstr.substr(0,temp_null_pos);
1540 if (StructMeta == metatype[i]) {
1544 strmeta_num = get_metadata_num(s_oname[i]);
1547 H5Gclose(ecs_grp_id);
1548 throw InternalErr(__FILE__,__LINE__,
"Obtain structmetadata suffix error.");
1555 if (-1 == strmeta_num)
1556 total_strmeta_value = finstr;
1558 else if (strmeta_value[strmeta_num]!=
"") {
1559 string msg =
"The structmeta value array at this index should be empty string ";
1560 H5Gclose(ecs_grp_id);
1561 throw InternalErr(__FILE__, __LINE__, msg);
1565 strmeta_value[strmeta_num] = finstr;
1569 if (
false == s_st_only &&
1570 (metatype[i] != StructMeta)) {
1572 switch (metatype[i]) {
1576 if (coremeta_num_total < 0) {
1577 string msg =
"There may be no coremetadata or coremetadata is not counted ";
1578 H5Gclose(ecs_grp_id);
1579 throw InternalErr(__FILE__, __LINE__, msg);
1584 coremeta_num = get_metadata_num(s_oname[i]);
1587 H5Gclose(ecs_grp_id);
1588 throw InternalErr(__FILE__,__LINE__,
"Obtain coremetadata suffix error.");
1594 if ( -1 == coremeta_num )
1595 total_coremeta_value = finstr;
1596 else if (coremeta_value[coremeta_num]!=
"") {
1597 string msg =
"The coremeta value array at this index should be empty string ";
1598 H5Gclose(ecs_grp_id);
1599 throw InternalErr(__FILE__, __LINE__, msg);
1604 coremeta_value[coremeta_num] = finstr;
1610 if (archmeta_num_total < 0) {
1611 string msg =
"There may be no archivemetadata or archivemetadata is not counted ";
1612 H5Gclose(ecs_grp_id);
1613 throw InternalErr(__FILE__, __LINE__, msg);
1616 archmeta_num = get_metadata_num(s_oname[i]);
1619 H5Gclose(ecs_grp_id);
1620 throw InternalErr(__FILE__,__LINE__,
"Obtain archivemetadata suffix error.");
1622 if (-1 == archmeta_num )
1623 total_archmeta_value = finstr;
1624 else if (archmeta_value[archmeta_num]!=
"") {
1625 string msg =
"The archivemeta value array at this index should be empty string ";
1626 H5Gclose(ecs_grp_id);
1627 throw InternalErr(__FILE__, __LINE__, msg);
1632 archmeta_value[archmeta_num] = finstr;
1637 if (submeta_num_total < 0) {
1638 string msg =
"The subsetemeta value array at this index should be empty string ";
1639 H5Gclose(ecs_grp_id);
1640 throw InternalErr(__FILE__, __LINE__, msg);
1643 submeta_num = get_metadata_num(s_oname[i]);
1646 H5Gclose(ecs_grp_id);
1647 throw InternalErr(__FILE__,__LINE__,
"Obtain subsetmetadata suffix error.");
1649 if (-1 == submeta_num )
1650 total_submeta_value = finstr;
1651 else if (submeta_value[submeta_num]!=
"") {
1652 string msg =
"The submeta value array at this index should be empty string ";
1653 H5Gclose(ecs_grp_id);
1654 throw InternalErr(__FILE__, __LINE__, msg);
1658 submeta_value[submeta_num] = finstr;
1663 if (prometa_num_total < 0) {
1664 string msg =
"There may be no productmetadata or productmetadata is not counted ";
1665 H5Gclose(ecs_grp_id);
1666 throw InternalErr(__FILE__, __LINE__, msg);
1669 prometa_num = get_metadata_num(s_oname[i]);
1672 H5Gclose(ecs_grp_id);
1673 throw InternalErr(__FILE__,__LINE__,
"Obtain productmetadata suffix error.");
1675 if (prometa_num == -1)
1676 total_prometa_value = finstr;
1677 else if (prometa_value[prometa_num]!=
"") {
1678 string msg =
"The productmeta value array at this index should be empty string ";
1679 H5Gclose(ecs_grp_id);
1680 throw InternalErr(__FILE__, __LINE__, msg);
1684 prometa_value[prometa_num] = finstr;
1689 if (xmlmeta_num_total < 0) {
1690 string msg =
"There may be no xmlmetadata or xmlmetadata is not counted ";
1691 H5Gclose(ecs_grp_id);
1692 throw InternalErr(__FILE__, __LINE__, msg);
1695 xmlmeta_num = get_metadata_num(s_oname[i]);
1698 H5Gclose(ecs_grp_id);
1699 throw InternalErr(__FILE__,__LINE__,
"Obtain XMLmetadata suffix error.");
1701 if (-1 == xmlmeta_num )
1702 total_xmlmeta_value = finstr;
1703 else if (xmlmeta_value[xmlmeta_num]!=
"") {
1704 string msg =
"The xmlmeta value array at this index should be empty string ";
1705 H5Gclose(ecs_grp_id);
1706 throw InternalErr(__FILE__, __LINE__, msg);
1710 xmlmeta_value[xmlmeta_num] = finstr;
1715 if (othermeta_num_total < 0) {
1716 string msg =
"There may be no othermetadata or other metadata is not counted ";
1717 H5Gclose(ecs_grp_id);
1718 throw InternalErr(__FILE__, __LINE__, msg);
1720 total_othermeta_value = total_othermeta_value + finstr;
1725 string msg =
"Unsupported metadata type ";
1726 H5Gclose(ecs_grp_id);
1727 throw InternalErr(__FILE__, __LINE__, msg);
1737 if (strmeta_num_total > 0) {
1739 if (strmeta_num != -1) {
1740 for (
int i = 0; i <strmeta_num_total; i++)
1741 total_strmeta_value +=strmeta_value[i];
1746 if (
false == s_st_only) {
1748 if (coremeta_num_total >0) {
1749 if (coremeta_num != -1) {
1750 for(
int i = 0; i <coremeta_num_total; i++)
1751 total_coremeta_value +=coremeta_value[i];
1755 if (archmeta_num_total >0) {
1756 if (archmeta_num != -1) {
1757 for(
int i = 0; i <archmeta_num_total; i++)
1758 total_archmeta_value +=archmeta_value[i];
1762 if (submeta_num_total >0) {
1763 if (submeta_num != -1) {
1764 for(
int i = 0; i <submeta_num_total; i++)
1765 total_submeta_value +=submeta_value[i];
1769 if (xmlmeta_num_total >0) {
1770 if (xmlmeta_num != -1) {
1771 for(
int i = 0; i <xmlmeta_num_total; i++)
1772 total_xmlmeta_value +=xmlmeta_value[i];
1776 if (prometa_num_total >0) {
1777 if (prometa_num != -1) {
1778 for(
int i = 0; i <prometa_num_total; i++)
1779 total_prometa_value +=prometa_value[i];
1783 H5Gclose(ecs_grp_id);
1787int get_metadata_num(
const string & meta_str) {
1792 size_t dot_pos = meta_str.find(
".");
1793 if (dot_pos == string::npos)
1795 else if (meta_str.find_first_of(
".") == meta_str.find_last_of(
".")) {
1796 string num_str = meta_str.substr(dot_pos+1);
1797 stringstream ssnum(num_str);
1801 throw InternalErr(__FILE__,__LINE__,
"Suffix after dots is not a number.");
1805 string str_after_first_dot = meta_str.substr(dot_pos+1);
1806 if (str_after_first_dot.find_first_of(
".") != str_after_first_dot.find_last_of(
"."))
1807 throw InternalErr(__FILE__,__LINE__,
"Currently don't support metadata names containing more than two dots.");
1812 size_t second_dot_pos = str_after_first_dot.find(
".");
1813 string num_str = str_after_first_dot.substr(second_dot_pos+1);
1814 stringstream ssnum(num_str);
1822void map_eos5_cfdmr(D4Group *d4_root, hid_t file_id,
const string &filename) {
1824 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
1830 string subset_str=
"";
1831 string product_str=
"";
1832 string other_str =
"";
1833 bool st_only =
false;
1836 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
1839 "unable to obtain the HDF-EOS5 struct metadata ";
1840 throw InternalErr(__FILE__, __LINE__, msg);
1843 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
1844 if(disable_ecsmetadata ==
false) {
1846 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
1848 if (
false == is_check_disable_smetadata)
1849 add_grp_dap4_attr(d4_root,
"StructMetadata",attr_str_c,st_str);
1852 add_grp_dap4_attr(d4_root,
"CoreMetadata",attr_str_c,core_str);
1855 add_grp_dap4_attr(d4_root,
"ArchiveMetadata",attr_str_c,arch_str);
1858 add_grp_dap4_attr(d4_root,
"XMLMetadata",attr_str_c,xml_str);
1861 add_grp_dap4_attr(d4_root,
"SubsetMetadata",attr_str_c,subset_str);
1863 if(product_str !=
"")
1864 add_grp_dap4_attr(d4_root,
"ProductMetadata",attr_str_c,product_str);
1867 add_grp_dap4_attr(d4_root,
"OtherMetadata",attr_str_c,other_str);
1870 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
1872 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
1877 f =
new EOS5File(filename.c_str(),file_id);
1880 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
1883 bool include_attr =
true;
1894 he5dds_scan_string(st_str.c_str());
1896 he5ddslex_destroy();
1899 p.add_projparams(st_str);
1905 if (c.check_grids_unknown_parameters(&p)) {
1906 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
1909 if (c.check_grids_missing_projcode(&p)) {
1910 throw InternalErr(
"The HDF-EOS5 is missing project code ");
1914 if (c.check_grids_support_projcode(&p)) {
1915 throw InternalErr(
"The current project code is not supported");
1919 c.set_grids_missing_pixreg_orig(&p);
1922 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
1940 throw InternalErr(e.what());
2020 if(
true == is_check_nameclashing)
2028 if(
true == is_check_nameclashing)
2048 throw InternalErr(e.what());
2053 gen_eos5_cfdmr(d4_root,f);
2068 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function "<<endl);
2069 const vector<HDF5CF::Var *>& vars = f->
getVars();
2070 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2071 const string filename = f->
getPath();
2073 const vector<HDF5CF::Group *>& grps = f->
getGroups();
2074 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
2076 vector<HDF5CF::Attribute *>::const_iterator it_ra;
2078 if (
false == root_attrs.empty()) {
2079 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra)
2080 map_cfh5_grp_attr_to_dap4(d4_root,*it_ra);
2084 if (
false == grps.empty()) {
2085 for (
auto it_g = grps.begin(); it_g != grps.end(); ++it_g) {
2086 auto tmp_grp =
new D4Attribute;
2087 tmp_grp->set_name((*it_g)->getNewName());
2088 tmp_grp->set_type(attr_container_c);
2090 for (it_ra = (*it_g)->getAttributes().begin();
2091 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
2092 map_cfh5_attr_container_to_dap4(tmp_grp,(*it_ra));
2094 d4_root->attributes()->add_attribute_nocopy(tmp_grp);
2100 vector<HDF5CF::Var *>::const_iterator it_v;
2101 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
2103 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
2104 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2105 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
2106 gen_dap_oneeos5cvar_dmr(d4_root,*it_cv,file_id,filename);
2109 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
2110 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
2111 gen_dap_onevar_dmr(d4_root,*it_v,file_id,filename);
2115 if (f->Have_EOS5_Grids()==
true)
2116 gen_dap_eos5cf_gm_dmr(d4_root,f);
2120 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
2121 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
2122 gen_dap_onevar_dmr(d4_root,*it_v,file_id,filename);
2126 if (f->Have_EOS5_Grids()==
true)
2127 gen_dap_eos5cf_gm_dmr(d4_root,f);
2129 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2130 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
2131 gen_dap_oneeos5cvar_dmr(d4_root,*it_cv,file_id,filename);
2140 string dods_extra =
"DODS_EXTRA";
2143 if(d4_root->attributes() !=
nullptr) {
2147 string unlimited_dim_names =
"";
2149 for (it_cv = cvars.begin();
2150 it_cv != cvars.end(); it_cv++) {
2153 for (
auto ird = (*it_cv)->getDimensions().begin();
2154 ird != (*it_cv)->getDimensions().end(); ++ird) {
2159 if((*ird)->HaveUnlimitedDim() ==
true) {
2161 if(unlimited_dim_names==
"")
2162 unlimited_dim_names = (*ird)->getNewName();
2164 if(unlimited_dim_names.rfind((*ird)->getNewName()) == string::npos) {
2165 unlimited_dim_names = unlimited_dim_names+
" "+(*ird)->getNewName();
2172 if(unlimited_dim_names !=
"") {
2173 auto dods_extra_attr =
new D4Attribute(dods_extra,attr_container_c);
2174 auto unlimited_dim_attr =
new D4Attribute(
"Unlimited_Dimension",attr_str_c);
2175 unlimited_dim_attr->add_value(unlimited_dim_names);
2176 dods_extra_attr->attributes()->add_attribute_nocopy(unlimited_dim_attr);
2177 d4_root->attributes()->add_attribute_nocopy(dods_extra_attr);
2180 throw InternalErr(__FILE__, __LINE__,
"Unlimited dimension should exist.");
2187 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
2190 vector <string> cvar_name;
2191 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv)
2192 cvar_name.emplace_back((*it_cv)->getNewName());
2194 add_dap4_coverage(d4_root,cvar_name,f->getIsCOARD());
2199void gen_dap_oneeos5cvar_dmr(D4Group* d4_root,
const EOS5CVar* cvar,
const hid_t file_id,
const string & filename){
2201 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dmr() "<<endl);
2202 BaseType *bt =
nullptr;
2205#define HANDLE_CASE(tid,type) \
2207 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
2220 HANDLE_CASE(H5FSTRING,
Str)
2221 HANDLE_CASE(H5VSTRING,
Str)
2223 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
2229 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
2230 vector <HDF5CF::Dimension*>:: const_iterator it_d;
2231 vector <size_t> dimsizes;
2232 dimsizes.resize(cvar->
getRank());
2233 for(
int i = 0; i <cvar->
getRank();i++)
2234 dimsizes[i] = (dims[i])->getSize();
2238 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
2244 bool is_latlon = cvar->isLatLon();
2247 bool is_dap4 =
true;
2255 cvar->getTotalElems(),
2265 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
2268 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
2269 if (
""==(*it_d)->getNewName())
2270 ar->append_dim((
int)((*it_d)->getSize()));
2272 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
2275 ar->set_is_dap4(
true);
2276 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2277 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2278 d4_root->add_var_nocopy(d4_var);
2292cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
2293cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
2294cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
2302 cvar->getPointLower(),
2303 cvar->getPointUpper(),
2304 cvar->getPointLeft(),
2305 cvar->getPointRight(),
2306 cvar->getPixelReg(),
2308 cvar->getProjCode(),
2312 cvar->getXDimSize(),
2313 cvar->getYDimSize(),
2319 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissLLArray.");
2322 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
2323 if (
""==(*it_d)->getNewName())
2324 ar->append_dim((
int)((*it_d)->getSize()));
2326 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
2329 ar->set_is_dap4(
true);
2330 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2331 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2332 add_var_sp_attrs_to_dap4(d4_var,cvar);
2333 d4_root->add_var_nocopy(d4_var);
2340 case CV_NONLATLON_MISS:
2345 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2359 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissNonLLCVArray.");
2363 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
2364 if (
""==(*it_d)->getNewName())
2365 ar->append_dim((
int)((*it_d)->getSize()));
2367 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
2370 ar->set_is_dap4(
true);
2371 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2372 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2373 d4_root->add_var_nocopy(d4_var);
2388 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2406 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
2410 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
2411 if (
""==(*it_d)->getNewName())
2412 ar->append_dim((
int)((*it_d)->getSize()));
2414 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
2417 ar->set_is_dap4(
true);
2418 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2419 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2420 d4_root->add_var_nocopy(d4_var);
2428 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
2441 gen_gm_proj_var_info(d4_root,f);
2444 gen_gm_proj_spvar_info(d4_root,f);
2450void gen_gm_proj_var_info(libdap::D4Group* d4_root,
const HDF5CF::EOS5File* f) {
2452 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function "<<endl);
2453 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2457 unsigned short cv_lat_miss_index = 1;
2458 for (
auto it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2459 if((*it_cv)->getCVType() == CV_LAT_MISS) {
2460 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
2461 gen_gm_oneproj_var(d4_root,*it_cv,cv_lat_miss_index,f);
2462 cv_lat_miss_index++;
2470void gen_gm_oneproj_var(libdap::D4Group*d4_root,
2474 BESDEBUG(
"h5",
"Coming to gen_gm_oneproj_var() "<<endl);
2475 EOS5GridPCType cv_proj_code = cvar->getProjCode();
2476 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
2479 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
2484 if (HE5_GCTP_SNSOID == cv_proj_code || HE5_GCTP_PS == cv_proj_code || HE5_GCTP_LAMAZ== cv_proj_code) {
2489 string cf_projection_base =
"eos_cf_projection";
2490 string cf_projection_name;
2494 if(HE5_GCTP_SNSOID == cv_proj_code) {
2498 cf_projection_name = cf_projection_base;
2500 dummy_proj_cf =
new HDF5CFGeoCFProj(cf_projection_name, cf_projection_name);
2503 stringstream t_suffix_ss;
2504 t_suffix_ss << g_suffix;
2505 cf_projection_name = cf_projection_base +
"_" + t_suffix_ss.str();
2506 dummy_proj_cf =
new HDF5CFGeoCFProj(cf_projection_name, cf_projection_name);
2509 if(dummy_proj_cf !=
nullptr) {
2510 dummy_proj_cf->set_is_dap4(
true);
2511 add_gm_oneproj_var_dap4_attrs(dummy_proj_cf,cv_proj_code,cvar->getParams());
2512 d4_root->add_var_nocopy(dummy_proj_cf);
2516 vector<string> cvar_name;
2517 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
2518 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2519 for (
auto it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv)
2520 cvar_name.emplace_back((*it_cv)->getNewName());
2523 add_cf_grid_cv_dap4_attrs(d4_root,cf_projection_name,dims,cvar_name);
2529void gen_gm_proj_spvar_info(libdap::D4Group* d4_root,
const HDF5CF::EOS5File* f){
2531 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products grid mapping variable generation function "<<endl);
2532 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2534 for (
auto it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2535 if((*it_cv)->getCVType() == CV_LAT_MISS) {
2536 if((*it_cv)->getProjCode() != HE5_GCTP_GEO)
2537 gen_gm_oneproj_spvar(d4_root,*it_cv);
2542void gen_gm_oneproj_spvar(libdap::D4Group *d4_root,
const HDF5CF::EOS5CVar *cvar) {
2544 BESDEBUG(
"h5",
"Coming to gen_gm_oneproj_spvar() "<<endl);
2546 float cv_point_lower = cvar->getPointLower();
2547 float cv_point_upper = cvar->getPointUpper();
2548 float cv_point_left = cvar->getPointLeft();
2549 float cv_point_right = cvar->getPointRight();
2550 EOS5GridPCType cv_proj_code = cvar->getProjCode();
2551 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
2553 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
2554 add_gm_spcvs(d4_root,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
2558void add_var_sp_attrs_to_dap4(BaseType *d4_var,
const EOS5CVar* cvar) {
2560 if(cvar->getProjCode() == HE5_GCTP_LAMAZ) {
2562 add_var_dap4_attr(d4_var,
"valid_min", attr_float64_c,
"-90.0");
2563 add_var_dap4_attr(d4_var,
"valid_max", attr_float64_c,
"90.0");
2566 add_var_dap4_attr(d4_var,
"valid_min", attr_float64_c,
"-180.0");
2567 add_var_dap4_attr(d4_var,
"valid_max", attr_float64_c,
"180.0");
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 64-bit integer to DAP4 Int64 for the CF option.
This class provides a way to map HDF5 int8 to DAP int16 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.
This class provides a way to map HDF5 64-bit unsigned integer to DAP4 UInt64 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.
bool Get_IgnoredInfo_Flag() override
Obtain the flag to see if ignored objects should be generated.
const std::string & Get_Ignored_Msg() override
Obtain the message that contains the ignored object info.
void Adjust_Obj_Name() override
This method is a no-op operation. Leave here since the method in the base class is pure virtual.
void Add_EOS5File_Info(HE5Parser *, bool)
Add HDF-EOS5 dimension and coordinate variable related info. to EOS5Grid,EOS5Swath etc.
void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr) override
Retrieve DDS information from the HDF5 file; a real implementation for HDF-EOS5 products.
void Add_Supplement_Attrs(bool) override
Add the supplemental attributes for HDF-EOS5 products.
void Set_COARDS_Status()
Set COARDS flag.
void Adjust_Var_Dim_NewName_Before_Flattening()
Adjust variable dimension names before the flattening for HDF-EOS5 files.
void Handle_CVar() override
Handle coordinate variable for HDF-EOS5 files.
void Adjust_Attr_Info()
Adjust the attribute info for HDF-EOS5 products.
void Handle_SpVar_Attr() override
Handle special variables for HDF-EOS5 files.
void Handle_Obj_NameClashing(bool)
Handle the object name clashing for HDF-EOS5 products.
void Handle_Unsupported_Dtype(bool) override
Handle unsupported HDF5 datatypes for HDF-EOS5 products.
void Handle_DimNameClashing() override
void Handle_Unsupported_Others(bool) override
Handle other unmapped objects/attributes for HDF-EOS5 products.
void Retrieve_H5_CVar_Supported_Attr_Values() override
Retrieve coordinate variable attributes.
void Handle_SpVar() override
Handle special variables for HDF-EOS5 files.
void Adjust_Var_NewName_After_Parsing()
Adjust variable names for HDF-EOS5 files.
void Retrieve_H5_Supported_Attr_Values() override
Retrieve attribute values for the supported HDF5 datatypes for HDF-EOS5 products.
void Add_Dim_Name(HE5Parser *)
Add the dimension name for HDF-EOS5 files.
void Adjust_Dim_Name() override
Adjust the dimension name for HDF-EOS5 products.
void Handle_SpVar_DMR() override
Handle special variables and attributes for HDF-EOS5 files(for DMR)
void Handle_Unsupported_Dspace(bool) override
Handle unsupported HDF5 dataspaces for HDF-EOS5 products.
void Flatten_Obj_Name(bool include_attr) override
Flatten the object name for HDF-EOS5 files.
void Check_Aura_Product_Status()
Check if the HDF-EOS5 file is an Aura file. Special CF operations need to be used.
const std::vector< EOS5CVar * > & getCVars() const
Obtain coordinate variables for HDF-EOS5 products.
void Adjust_EOS5Dim_Info(HE5Parser *strmeta_info)
Adjust HDF-EOS5 dimension information.
void Handle_Coor_Attr() override
Handle the coordinates attribute for HDF-EOS5 products.
bool HaveUnlimitedDim() const
Has unlimited dimensions.
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< Group * > & getGroups() const
Public interface to obtain all the group info.
const std::string & getPath() const
Obtain the path of the file.
const std::vector< Var * > & getVars() const
Public interface to obtain information of all variables.
float getCompRatio() const
Get the compression ratio of this dataset.
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.
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.