41#include <libdap/parser.h>
59#include "HDF5CFGeoCFProj.h"
61#include "h5apicompatible.h"
65#include "he5das.tab.hh"
67struct yy_buffer_state;
69yy_buffer_state *he5dds_scan_string(
const char *str);
71int he5dasparse(libdap::parser_arg *arg);
72int he5ddslex_destroy();
73int he5daslex_destroy();
78using namespace HDF5CF;
81void map_eos5_cfdds(DDS &dds, hid_t file_id,
const string & filename) {
83 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
96 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
99 "unable to obtain the HDF-EOS5 struct metadata ";
100 throw InternalErr(__FILE__, __LINE__, msg);
103 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
108 f =
new EOS5File(filename.c_str(),file_id);
111 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
114 bool include_attr =
false;
122 he5dds_scan_string(st_str.c_str());
127 p.add_projparams(st_str);
133 if (c.check_grids_unknown_parameters(&p)) {
134 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
137 if (c.check_grids_missing_projcode(&p)) {
138 throw InternalErr(
"The HDF-EOS5 is missing project code ");
142 if (c.check_grids_support_projcode(&p)) {
143 throw InternalErr(
"The current project code is not supported");
147 c.set_grids_missing_pixreg_orig(&p);
150 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
167 throw InternalErr(e.what());
192 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
193 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr)){
220 if((HDF5RequestHandler::get_lrdata_mem_cache() !=
nullptr) ||
221 (HDF5RequestHandler::get_srdata_mem_cache() !=
nullptr))
232 if(
true == is_check_nameclashing)
240 if(
true == is_check_nameclashing)
251 throw InternalErr(e.what());
256 gen_eos5_cfdds(dds,f);
267void map_eos5_cfdas(DAS &das, hid_t file_id,
const string &filename) {
269 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS mapping function map_eos5_cfdas "<<endl);
279 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
282 "unable to obtain the HDF-EOS5 struct metadata ";
283 throw InternalErr(__FILE__, __LINE__, msg);
286 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
288 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
292 f =
new EOS5File(filename.c_str(),file_id);
295 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
297 bool include_attr =
true;
304 he5dds_scan_string(st_str.c_str());
308 p.add_projparams(st_str);
314 if (c.check_grids_unknown_parameters(&p)) {
315 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
318 if (c.check_grids_missing_projcode(&p)) {
319 throw InternalErr(
"The HDF-EOS5 is missing project code ");
321 if (c.check_grids_support_projcode(&p)) {
322 throw InternalErr(
"The current project code is not supported");
324 c.set_grids_missing_pixreg_orig(&p);
326 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
335 throw InternalErr(e.what());
366 if (
true == is_check_nameclashing)
385 throw InternalErr(e.what());
390 gen_eos5_cfdas(das,file_id,f);
404 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function gen_eos5_cfdds "<<endl);
407 const string filename = f->
getPath();
411 for (
const auto &var:vars) {
412 BESDEBUG(
"h5",
"variable full path= "<< var->getFullPath() <<endl);
413 gen_dap_onevar_dds(dds,var,file_id,filename);
416 for (
const auto &cvar:cvars) {
417 BESDEBUG(
"h5",
"variable full path= "<< cvar->getFullPath() <<endl);
418 gen_dap_oneeos5cvar_dds(dds,cvar,file_id,filename);
424 unsigned short cv_lat_miss_index = 1;
425 for (
const auto &cvar:cvars) {
426 if(cvar->getCVType() == CV_LAT_MISS) {
427 if(cvar->getProjCode() != HE5_GCTP_GEO) {
431 gen_dap_oneeos5cf_dds(dds,cvar);
432 add_cf_grid_mapinfo_var(dds,cvar->getProjCode(),cv_lat_miss_index);
441 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_dds() "<<endl);
443 float cv_point_lower = cvar->getPointLower();
444 float cv_point_upper = cvar->getPointUpper();
445 float cv_point_left = cvar->getPointLeft();
446 float cv_point_right = cvar->getPointRight();
447 EOS5GridPCType cv_proj_code = cvar->getProjCode();
450 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
451 add_cf_grid_cvs(dds,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
457 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_das() "<<endl);
459 float cv_point_lower = cvar->getPointLower();
460 float cv_point_upper = cvar->getPointUpper();
461 float cv_point_left = cvar->getPointLeft();
462 float cv_point_right = cvar->getPointRight();
464 EOS5GridPCType cv_proj_code = cvar->getProjCode();
468cerr<<
"cv_point_lower is "<<cv_point_lower <<endl;
469cerr<<
"cvar name is "<<cvar->
getName() <<endl;
471 cerr<<
"dim name das is "<<(*it_d)->getNewName() <<endl;
475 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
477 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);
479 add_cf_grid_cv_attrs(das,vars,cv_proj_code,dims,cvar->getParams(),g_suffix);
486 BESDEBUG(
"h5",
"Coming to gen_eos5_cf_ignored_obj_info() "<<endl);
487 AttrTable *at = das.get_table(
"Ignored_Object_Info");
489 at = das.add_table(
"Ignored_Object_Info", obtain_new_attr_table()) ;
497void gen_dap_oneeos5cvar_dds(DDS &dds,
const HDF5CF::EOS5CVar* cvar,
const hid_t file_id,
const string & filename) {
499 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dds() "<<endl);
500 BaseType *bt =
nullptr;
506#define HANDLE_CASE(tid,type) \
508 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
519 HANDLE_CASE(H5FSTRING,
Str)
520 HANDLE_CASE(H5VSTRING,
Str)
522 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
529 vector <HDF5CF::Dimension*>:: const_iterator it_d;
530 vector <size_t> dimsizes;
531 dimsizes.resize(cvar->
getRank());
532 for(
int i = 0; i <cvar->
getRank();i++)
533 dimsizes[i] = (dims[i])->getSize();
537 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
545 it_ra != cvar->getAttributes().end(); ++it_ra) {
546cerr<<
"cvar attribute name is "<<(*it_ra)->getNewName() <<endl;
547cerr<<
"cvar attribute value type is "<<(*it_ra)->getType() <<endl;
549cerr<<
"cvar new name exist at he s5cfdap.cc is "<<cvar->
getNewName() <<endl;
551 bool is_latlon = cvar->isLatLon();
552 auto ar_unique = make_unique<HDF5CFArray>(cvar->
getRank(),
558 cvar->getTotalElems(),
565 auto ar = ar_unique.get();
568 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
569 if (
""==(*it_d)->getNewName())
570 ar->append_dim((
int)((*it_d)->getSize()));
572 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
583 auto ar_unique = make_unique<HDFEOS5CFMissLLArray>(cvar->
getRank(),
588 cvar->getPointLower(),
589 cvar->getPointUpper(),
590 cvar->getPointLeft(),
591 cvar->getPointRight(),
602 auto ar = ar_unique.get();
605cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
606cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
607cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
609 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
610 if (
""==(*it_d)->getNewName())
611 ar->append_dim((
int)((*it_d)->getSize()));
613 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
620 case CV_NONLATLON_MISS:
625 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
629 auto ar_unique = make_unique<HDFEOS5CFMissNonLLCVArray>(cvar->
getRank(),
633 auto ar = ar_unique.get();
636 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
637 if (
""==(*it_d)->getNewName())
638 ar->append_dim((
int)((*it_d)->getSize()));
640 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
652 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
655 auto ar_unique = make_unique<HDFEOS5CFSpecialCVArray>(
664 auto ar = ar_unique.get();
667 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
668 if (
""==(*it_d)->getNewName())
669 ar->append_dim((
int)((*it_d)->getSize()));
671 ar->append_dim((
int)((*it_d)->getSize()), (*it_d)->getNewName());
679 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
689 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS generation function gen_eos5_cfdas "<<endl);
693 gen_eos5_cf_ignored_obj_info(das, f);
709 if (
false == root_attrs.empty()) {
710 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
712 at = das.add_table(FILE_ATTR_TABLE_NAME, obtain_new_attr_table());
714 for (
const auto &root_attr:root_attrs)
715 gen_dap_oneobj_das(at,root_attr,
nullptr);
719 if (
false == grps.empty()) {
720 for (
const auto &grp:grps) {
721 AttrTable *at = das.get_table(grp->getNewName());
723 at = das.add_table(grp->getNewName(), obtain_new_attr_table());
725 for (
const auto &attr:grp->getAttributes()) {
730 if(attr->getNewName()==
"Conventions" &&(grp->getNewName() ==
"HDFEOS_ADDITIONAL_FILE_ATTRIBUTES")
731 && (
true==HDF5RequestHandler::get_eos5_rm_convention_attr_path())) {
732 AttrTable *at_das = das.get_table(FILE_ATTR_TABLE_NAME);
733 if (
nullptr == at_das)
734 at_das = das.add_table(FILE_ATTR_TABLE_NAME, obtain_new_attr_table());
735 gen_dap_oneobj_das(at_das,attr,
nullptr);
738 gen_dap_oneobj_das(at,attr,
nullptr);
743 for (
const auto &var:vars) {
744 if (
false == (var->getAttributes().empty())) {
747 if(H5INT64 == var->getType() || H5UINT64 == var->getType()){
751 AttrTable *at = das.get_table(var->getNewName());
753 at = das.add_table(var->getNewName(), obtain_new_attr_table());
755 for (
const auto &attr:var->getAttributes())
756 gen_dap_oneobj_das(at,attr,var);
760 for (
const auto &cvar:cvars) {
762 if (
false == (cvar->getAttributes().empty())) {
769 AttrTable *at = das.get_table(cvar->
getNewName());
771 at = das.add_table(cvar->
getNewName(), obtain_new_attr_table());
773 for (
const auto &attr:cvar->getAttributes())
774 gen_dap_oneobj_das(at,attr,cvar);
780 unsigned short cv_lat_miss_index = 1;
782 for (
const auto &cvar:cvars) {
784 if(cvar->getProjCode() != HE5_GCTP_GEO) {
785 gen_dap_oneeos5cf_das(das,vars,cvar,cv_lat_miss_index);
791 for (
const auto &cvar:cvars) {
792 if(cvar->getProjCode() == HE5_GCTP_LAMAZ) {
794 AttrTable *at = das.get_table(cvar->
getNewName());
796 at = das.add_table(cvar->
getNewName(), obtain_new_attr_table());
798 add_ll_valid_range(at,
true);
800 add_ll_valid_range(at,
false);
806 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
808 if(disable_ecsmetadata ==
false) {
820 bool st_only =
false;
822 read_ecs_metadata(file_id, st_str, core_str, arch_str, xml_str,
823 subset_str, product_str, other_str, st_only);
826if(st_str!=
"")
"h5",
"Final structmetadata "<<st_str <<endl;
827if(core_str!=
"")
"h5",
"Final coremetadata "<<core_str <<endl;
828if(arch_str!=
"")
"h5",
"Final archivedmetadata "<<arch_str <<endl;
829if(xml_str!=
"")
"h5",
"Final xmlmetadata "<<xml_str <<endl;
830if(subset_str!=
"")
"h5",
"Final subsetmetadata "<<subset_str <<endl;
831if(product_str!=
"")
"h5",
"Final productmetadata "<<product_str <<endl;
832if(other_str!=
"")
"h5",
"Final othermetadata "<<other_str <<endl;
838 string check_disable_smetadata_key =
"H5.DisableStructMetaAttr";
839 bool is_check_disable_smetadata =
false;
841 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
843 if (
false == is_check_disable_smetadata) {
845 AttrTable *at = das.get_table(
"StructMetadata");
847 at = das.add_table(
"StructMetadata", obtain_new_attr_table());
851 if (he5dasparse(&arg) != 0
852 ||
false == arg.status()){
854 ERROR_LOG(
"HDF-EOS5 parse error while processing a StructMetadata HDFEOS attribute.");
863 AttrTable *at = das.get_table(
"CoreMetadata");
865 at = das.add_table(
"CoreMetadata", obtain_new_attr_table());
868 if (he5dasparse(&arg) != 0
869 ||
false == arg.status()){
871 ERROR_LOG(
"HDF-EOS5 parse error while processing a CoreMetadata HDFEOS attribute.");
877 AttrTable *at = das.get_table(
"ArchiveMetadata");
879 at = das.add_table(
"ArchiveMetadata", obtain_new_attr_table());
882 if (he5dasparse(&arg) != 0 ||
false == arg.status()){
883 ERROR_LOG(
"HDF-EOS5 parse error while processing a ArchiveMetadata HDFEOS attribute.");
892 AttrTable *at = das.get_table(
"XMLMetadata");
894 at = das.add_table(
"XMLMetadata", obtain_new_attr_table());
895 HDF5CFDAPUtil::replace_double_quote(xml_str);
896 at->append_attr(
"Contents",
"String",xml_str);
902 if(subset_str !=
""){
903 AttrTable *at = das.get_table(
"SubsetMetadata");
905 at = das.add_table(
"SubsetMetadata", obtain_new_attr_table());
908 if (he5dasparse(&arg) != 0 ||
false == arg.status()) {
909 ERROR_LOG(
"HDF-EOS5 parse error while processing a SubsetMetadata HDFEOS attribute.");
913 if(product_str !=
""){
914 AttrTable *at = das.get_table(
"ProductMetadata");
916 at = das.add_table(
"ProductMetadata", obtain_new_attr_table());
919 if (he5dasparse(&arg) != 0 ||
false == arg.status()){
920 ERROR_LOG(
"HDF-EOS5 parse error while processing a ProductMetadata HDFEOS attribute.");
928 if (other_str !=
""){
929 AttrTable *at = das.get_table(
"OtherMetadata");
931 at = das.add_table(
"OtherMetadata", obtain_new_attr_table());
932 at->append_attr(
"Contents",
"String",other_str);
939 AttrTable *at = das.get_table(
"DODS_EXTRA");
941 at = das.add_table(
"DODS_EXTRA", obtain_new_attr_table());
942 string unlimited_names;
944 for (
const auto &cvar: cvars) {
946 bool has_unlimited_dim =
false;
954 if(dim->HaveUnlimitedDim() ==
true) {
956 if(unlimited_names==
"") {
957 unlimited_names = dim->getNewName();
958 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
961 if(unlimited_names.rfind(dim->getNewName()) == string::npos) {
962 unlimited_names = unlimited_names+
" "+dim->getNewName();
963 at->append_attr(
"Unlimited_Dimension",
"String",dim->getNewName());
984void read_ecs_metadata(hid_t s_file_id,
985 string &total_strmeta_value,
986 string &total_coremeta_value,
987 string &total_archmeta_value,
988 string &total_xmlmeta_value,
989 string &total_submeta_value,
990 string &total_prometa_value,
991 string &total_othermeta_value,
994 BESDEBUG(
"h5",
"Coming to read_ecs_metadata() "<<endl);
995 string ecs_group =
"/HDFEOS INFORMATION";
996 hid_t ecs_grp_id = -1;
997 if ((ecs_grp_id = H5Gopen(s_file_id, ecs_group.c_str(),H5P_DEFAULT))<0) {
999 "h5_ecs_meta: unable to open the HDF5 group ";
1001 throw InternalErr(__FILE__, __LINE__, msg);
1007 if (H5Gget_info(ecs_grp_id,&g_info) <0) {
1009 "h5_ecs_meta: unable to obtain the HDF5 group info. for ";
1011 H5Gclose(ecs_grp_id);
1012 throw InternalErr(__FILE__, __LINE__, msg);
1015 nelems = g_info.nlinks;
1017 ssize_t oname_size = 0;
1019 int cur_archmeta_suffix = 0;
1020 int cur_coremeta_suffix = 0;
1021 int cur_strmeta_suffix = 0;
1022 int cur_xmlmeta_suffix = 0;
1025 int archmeta_num = -1;
1026 int coremeta_num = -1;
1027 int xmlmeta_num = -1;
1028 int strmeta_num = -1;
1029 int submeta_num = -1;
1030 int prometa_num = -1;
1033 int archmeta_num_total = 0;
1034 int coremeta_num_total = 0;
1035 int xmlmeta_num_total = 0;
1036 int strmeta_num_total = 0;
1037 int submeta_num_total = 0;
1038 int prometa_num_total = 0;
1039 int othermeta_num_total = 0;
1041 bool archmeta_no_suffix =
true;
1042 bool coremeta_no_suffix =
true;
1043 bool strmeta_no_suffix =
true;
1044 bool xmlmeta_no_suffix =
true;
1045 bool submeta_no_suffix =
true;
1046 bool prometa_no_suffix =
true;
1053 EOS5Metadata metatype[nelems];
1055 for (
unsigned int i =0; i<nelems; i++)
1056 metatype[i] = OtherMeta;
1058 for (hsize_t i = 0; i < nelems; i++) {
1062 H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
nullptr,
1064 if (oname_size <= 0) {
1065 string msg =
"hdf5 object name error from: ";
1067 H5Gclose(ecs_grp_id);
1068 throw InternalErr(__FILE__, __LINE__, msg);
1073 if (H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,oname.data(),
1074 (
size_t)(oname_size+1), H5P_DEFAULT)<0){
1075 string msg =
"hdf5 object name error from: ";
1077 H5Gclose(ecs_grp_id);
1078 throw InternalErr(__FILE__, __LINE__, msg);
1084 if (H5Lget_info(ecs_grp_id,oname.data(),&linfo,H5P_DEFAULT)<0) {
1085 string msg =
"hdf5 link name error from: ";
1087 H5Gclose(ecs_grp_id);
1088 throw InternalErr(__FILE__, __LINE__, msg);
1092 if (linfo.type == H5L_TYPE_SOFT){
1093 string msg =
"hdf5 link name error from: ";
1095 H5Gclose(ecs_grp_id);
1096 throw InternalErr(__FILE__, __LINE__, msg);
1101 if (H5OGET_INFO_BY_IDX(ecs_grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
1102 i, &oinfo, H5P_DEFAULT)<0) {
1103 string msg =
"Cannot obtain the object info ";
1105 H5Gclose(ecs_grp_id);
1106 throw InternalErr(__FILE__, __LINE__, msg);
1109 if(oinfo.type != H5O_TYPE_DATASET) {
1110 string msg =
"hdf5 link name error from: ";
1112 H5Gclose(ecs_grp_id);
1113 throw InternalErr(__FILE__, __LINE__, msg);
1117 string s_one_oname(oname.begin(),oname.end()-1);
1118 s_oname[i] = s_one_oname;
1121 if (((s_one_oname.find(
"StructMetadata"))==0) ||
1122 ((s_one_oname.find(
"structmetadata"))==0)){
1124 metatype[i] = StructMeta;
1131 if (
false == strmeta_no_suffix) {
1132 string msg =
"StructMetadata/structmetadata without suffix should only appear once. ";
1133 H5Gclose(ecs_grp_id);
1134 throw InternalErr(__FILE__, __LINE__, msg);
1137 else if(strmeta_num_total >0)
1138 strmeta_num_total++;
1140 if ((0 == s_one_oname.compare(
"StructMetadata"))||
1141 (0 == s_one_oname.compare(
"structmetadata")))
1142 strmeta_no_suffix =
false;
1143 else strmeta_num_total++;
1146"h5",
"strmeta_num_total= "<<strmeta_num_total <<endl;
1147if(strmeta_no_suffix)
"h5",
"structmeta data has the suffix" <<endl;
1148else "h5",
"structmeta data doesn't have the suffix" <<endl;
1152 if(
false == s_st_only) {
1154 if ((0 == (s_one_oname.find(
"CoreMetadata"))) ||
1155 (0 == (s_one_oname.find(
"coremetadata")))){
1157 metatype[i] = CoreMeta;
1163 if (
false == coremeta_no_suffix) {
1164 string msg =
"CoreMetadata/coremetadata without suffix should only appear once. ";
1165 H5Gclose(ecs_grp_id);
1166 throw InternalErr(__FILE__, __LINE__, msg);
1169 else if(coremeta_num_total >0)
1170 coremeta_num_total++;
1175 if ((0 == s_one_oname.compare(
"CoreMetadata")) ||
1176 (0 == s_one_oname.compare(
"coremetadata")))
1177 coremeta_no_suffix =
false;
1178 else coremeta_num_total++;
1181"h5",
"coremeta_num_total= "<<coremeta_num_total <<endl;
1182if(coremeta_no_suffix)
"h5",
"coreuctmeta data has the suffix" <<endl;
1183else "h5",
"coremeta data doesn't have the suffix" <<endl;
1188 else if ((0 == (s_one_oname.find(
"ArchivedMetadata"))) ||
1189 (0 == (s_one_oname.find(
"archivedmetadata"))) ||
1190 (0 == (s_one_oname.find(
"ArchiveMetadata"))) ||
1191 (0 == (s_one_oname.find(
"archivemetadata")))){
1193 metatype[i] = ArchivedMeta;
1198 if (
false == archmeta_no_suffix) {
1199 string msg =
"archivedmetadata/ArchivedMetadata without suffix should only appear once. ";
1200 H5Gclose(ecs_grp_id);
1201 throw InternalErr(__FILE__, __LINE__, msg);
1204 else if(archmeta_num_total >0)
1205 archmeta_num_total++;
1207 if ((0 == s_one_oname.compare(
"ArchivedMetadata"))||
1208 (0 == s_one_oname.compare(
"archivedmetadata")) ||
1209 (0 == s_one_oname.compare(
"archivemetadata")) ||
1210 (0 == s_one_oname.compare(
"ArchiveMetadata")))
1211 archmeta_no_suffix =
false;
1213 archmeta_num_total++;
1216"h5",
"archmeta_num_total= "<<archmeta_num_total <<endl;
1217if(archmeta_no_suffix)
"h5",
"archuctmeta data has the suffix" <<endl;
1218else "h5",
"archmeta data doesn't have the suffix" <<endl;
1223 else if (((s_one_oname.find(
"SubsetMetadata"))==0) ||
1224 ((s_one_oname.find(
"subsetmetadata"))==0)){
1226 metatype[i] = SubsetMeta;
1231 if (
false == submeta_no_suffix) {
1232 H5Gclose(ecs_grp_id);
1233 string msg =
"submetadata/SubMetadata without suffix should only appear once. ";
1234 throw InternalErr(__FILE__, __LINE__, msg);
1237 else if(submeta_num_total >0)
1238 submeta_num_total++;
1240 if ((0 == s_one_oname.compare(
"SubsetMetadata"))||
1241 (0 == s_one_oname.compare(
"subsetmetadata")))
1242 submeta_no_suffix =
false;
1243 else submeta_num_total++;
1246"h5",
"submeta_num_total= "<<submeta_num_total <<endl;
1247if(submeta_no_suffix)
"h5",
"subuctmeta data has the suffix" <<endl;
1248else "h5",
"submeta data doesn't have the suffix" <<endl;
1253 else if ((0 == (s_one_oname.find(
"XmlMetadata"))) ||
1254 (0 == (s_one_oname.find(
"xmlmetadata")))){
1256 metatype[i] = XMLMeta;
1262 if (
false == xmlmeta_no_suffix) {
1263 H5Gclose(ecs_grp_id);
1264 string msg =
"xmlmetadata/Xmlmetadata without suffix should only appear once. ";
1265 throw InternalErr(__FILE__, __LINE__, msg);
1268 else if(xmlmeta_num_total >0)
1269 xmlmeta_num_total++;
1271 if ((0 == s_one_oname.compare(
"XmlMetadata"))||
1272 (0 == s_one_oname.compare(
"xmlmetadata")))
1273 xmlmeta_no_suffix =
false;
1274 else xmlmeta_num_total++;
1277"h5",
"xmlmeta_num_total= "<<xmlmeta_num_total <<endl;
1278if(xmlmeta_no_suffix)
"h5",
"xmluctmeta data doesn't have the suffix" <<endl;
1279else "h5",
"xmlmeta data has the suffix" <<endl;
1284 else if ((0 == (s_one_oname.find(
"ProductMetadata"))) ||
1285 (0 == (s_one_oname.find(
"productmetadata")))){
1287 metatype[i] = ProductMeta;
1292 if (!prometa_no_suffix) {
1293 H5Gclose(ecs_grp_id);
1294 string msg =
"productmetadata/ProductMetadata without suffix should only appear once. ";
1295 throw InternalErr(__FILE__, __LINE__, msg);
1298 else if(prometa_num_total >0) prometa_num_total++;
1300 if ((0 == s_one_oname.compare(
"ProductMetadata"))||
1301 (0 == s_one_oname.compare(
"productmetadata")))
1302 prometa_no_suffix =
false;
1303 else prometa_num_total++;
1309 else othermeta_num_total++;
1313 s_one_oname.clear();
1319 if (strmeta_num_total <= 0) {
1320 string msg =
"hdf5 object name error from: ";
1321 H5Gclose(ecs_grp_id);
1322 throw InternalErr(__FILE__, __LINE__, msg);
1325 strmeta_value.resize(strmeta_num_total);
1326 for (
int i = 0; i < strmeta_num_total; i++)
1327 strmeta_value[i]=
"";
1333 if (archmeta_num_total >0) {
1334 archmeta_value.resize(archmeta_num_total);
1335 for (
int i = 0; i < archmeta_num_total; i++)
1336 archmeta_value[i]=
"";
1341 if (coremeta_num_total >0) {
1342 coremeta_value.resize(coremeta_num_total);
1343 for (
int i = 0; i < coremeta_num_total; i++)
1344 coremeta_value[i]=
"";
1349 if (xmlmeta_num_total >0) {
1350 xmlmeta_value.resize(xmlmeta_num_total);
1351 for (
int i = 0; i < xmlmeta_num_total; i++)
1352 xmlmeta_value[i]=
"";
1357 if (submeta_num_total >0) {
1358 submeta_value.resize(submeta_num_total);
1359 for (
int i = 0; i < submeta_num_total; i++)
1360 submeta_value[i]=
"";
1365 if (prometa_num_total >0) {
1366 prometa_value.resize(prometa_num_total);
1367 for (
int i = 0; i < prometa_num_total; i++)
1368 prometa_value[i]=
"";
1376 for (hsize_t i = 0; i < nelems; i++) {
1384 if (
true == s_st_only &&
1385 (((s_oname[i].find(
"StructMetadata"))!=0) &&
1386 ((s_oname[i].find(
"structmetadata"))!=0))){
1391 hid_t s_dset_id = -1;
1392 hid_t s_space_id = -1;
1394 hssize_t s_nelms = -1;
1395 size_t dtype_size = -1;
1397 if ((s_dset_id = H5Dopen(ecs_grp_id,s_oname[i].c_str(),H5P_DEFAULT))<0){
1398 string msg =
"Cannot open HDF5 dataset ";
1400 H5Gclose(ecs_grp_id);
1401 throw InternalErr(__FILE__, __LINE__, msg);
1404 if ((s_space_id = H5Dget_space(s_dset_id))<0) {
1405 string msg =
"Cannot open the data space of HDF5 dataset ";
1407 H5Dclose(s_dset_id);
1408 H5Gclose(ecs_grp_id);
1409 throw InternalErr(__FILE__, __LINE__, msg);
1412 if ((s_ty_id = H5Dget_type(s_dset_id)) < 0) {
1413 string msg =
"Cannot get the data type of HDF5 dataset ";
1415 H5Sclose(s_space_id);
1416 H5Dclose(s_dset_id);
1417 H5Gclose(ecs_grp_id);
1418 throw InternalErr(__FILE__, __LINE__, msg);
1420 if ((s_nelms = H5Sget_simple_extent_npoints(s_space_id))<0) {
1421 string msg =
"Cannot get the number of points of HDF5 dataset ";
1424 H5Sclose(s_space_id);
1425 H5Dclose(s_dset_id);
1426 H5Gclose(ecs_grp_id);
1427 throw InternalErr(__FILE__, __LINE__, msg);
1429 if ((dtype_size = H5Tget_size(s_ty_id))==0) {
1431 string msg =
"Cannot get the data type size of HDF5 dataset ";
1434 H5Sclose(s_space_id);
1435 H5Dclose(s_dset_id);
1436 H5Gclose(ecs_grp_id);
1437 throw InternalErr(__FILE__, __LINE__, msg);
1443 if ((H5Dread(s_dset_id,s_ty_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,s_buf.data()))<0) {
1445 string msg =
"Cannot read HDF5 dataset ";
1448 H5Sclose(s_space_id);
1449 H5Dclose(s_dset_id);
1450 H5Gclose(ecs_grp_id);
1451 throw InternalErr(__FILE__, __LINE__, msg);
1456 H5Sclose(s_space_id);
1457 H5Dclose(s_dset_id);
1461 string tempstr(s_buf.begin(),s_buf.end());
1463 size_t temp_null_pos = tempstr.find_first_of(
'\0');
1468 string finstr = tempstr.substr(0,temp_null_pos);
1471 if (StructMeta == metatype[i]) {
1475 strmeta_num = get_metadata_num(s_oname[i]);
1478 H5Gclose(ecs_grp_id);
1479 throw InternalErr(__FILE__,__LINE__,
"Obtain structmetadata suffix error.");
1486 if (-1 == strmeta_num)
1487 total_strmeta_value = finstr;
1489 else if (strmeta_value[strmeta_num]!=
"") {
1490 string msg =
"The structmeta value array at this index should be empty string ";
1491 H5Gclose(ecs_grp_id);
1492 throw InternalErr(__FILE__, __LINE__, msg);
1496 strmeta_value[strmeta_num] = finstr;
1500 if (
false == s_st_only &&
1501 (metatype[i] != StructMeta)) {
1503 switch (metatype[i]) {
1507 if (coremeta_num_total < 0) {
1508 string msg =
"There may be no coremetadata or coremetadata is not counted ";
1509 H5Gclose(ecs_grp_id);
1510 throw InternalErr(__FILE__, __LINE__, msg);
1515 coremeta_num = get_metadata_num(s_oname[i]);
1518 H5Gclose(ecs_grp_id);
1519 throw InternalErr(__FILE__,__LINE__,
"Obtain coremetadata suffix error.");
1525 if ( -1 == coremeta_num )
1526 total_coremeta_value = finstr;
1527 else if (coremeta_value[coremeta_num]!=
"") {
1528 string msg =
"The coremeta value array at this index should be empty string ";
1529 H5Gclose(ecs_grp_id);
1530 throw InternalErr(__FILE__, __LINE__, msg);
1535 coremeta_value[coremeta_num] = finstr;
1541 if (archmeta_num_total < 0) {
1542 string msg =
"There may be no archivemetadata or archivemetadata is not counted ";
1543 H5Gclose(ecs_grp_id);
1544 throw InternalErr(__FILE__, __LINE__, msg);
1547 archmeta_num = get_metadata_num(s_oname[i]);
1550 H5Gclose(ecs_grp_id);
1551 throw InternalErr(__FILE__,__LINE__,
"Obtain archivemetadata suffix error.");
1553 if (-1 == archmeta_num )
1554 total_archmeta_value = finstr;
1555 else if (archmeta_value[archmeta_num]!=
"") {
1556 string msg =
"The archivemeta value array at this index should be empty string ";
1557 H5Gclose(ecs_grp_id);
1558 throw InternalErr(__FILE__, __LINE__, msg);
1563 archmeta_value[archmeta_num] = finstr;
1568 if (submeta_num_total < 0) {
1569 string msg =
"The subsetemeta value array at this index should be empty string ";
1570 H5Gclose(ecs_grp_id);
1571 throw InternalErr(__FILE__, __LINE__, msg);
1574 submeta_num = get_metadata_num(s_oname[i]);
1577 H5Gclose(ecs_grp_id);
1578 throw InternalErr(__FILE__,__LINE__,
"Obtain subsetmetadata suffix error.");
1580 if (-1 == submeta_num )
1581 total_submeta_value = finstr;
1582 else if (submeta_value[submeta_num]!=
"") {
1583 string msg =
"The submeta value array at this index should be empty string ";
1584 H5Gclose(ecs_grp_id);
1585 throw InternalErr(__FILE__, __LINE__, msg);
1589 submeta_value[submeta_num] = finstr;
1594 if (prometa_num_total < 0) {
1595 string msg =
"There may be no productmetadata or productmetadata is not counted ";
1596 H5Gclose(ecs_grp_id);
1597 throw InternalErr(__FILE__, __LINE__, msg);
1600 prometa_num = get_metadata_num(s_oname[i]);
1603 H5Gclose(ecs_grp_id);
1604 throw InternalErr(__FILE__,__LINE__,
"Obtain productmetadata suffix error.");
1606 if (prometa_num == -1)
1607 total_prometa_value = finstr;
1608 else if (prometa_value[prometa_num]!=
"") {
1609 string msg =
"The productmeta value array at this index should be empty string ";
1610 H5Gclose(ecs_grp_id);
1611 throw InternalErr(__FILE__, __LINE__, msg);
1615 prometa_value[prometa_num] = finstr;
1620 if (xmlmeta_num_total < 0) {
1621 string msg =
"There may be no xmlmetadata or xmlmetadata is not counted ";
1622 H5Gclose(ecs_grp_id);
1623 throw InternalErr(__FILE__, __LINE__, msg);
1626 xmlmeta_num = get_metadata_num(s_oname[i]);
1629 H5Gclose(ecs_grp_id);
1630 throw InternalErr(__FILE__,__LINE__,
"Obtain XMLmetadata suffix error.");
1632 if (-1 == xmlmeta_num )
1633 total_xmlmeta_value = finstr;
1634 else if (xmlmeta_value[xmlmeta_num]!=
"") {
1635 string msg =
"The xmlmeta value array at this index should be empty string ";
1636 H5Gclose(ecs_grp_id);
1637 throw InternalErr(__FILE__, __LINE__, msg);
1641 xmlmeta_value[xmlmeta_num] = finstr;
1646 if (othermeta_num_total < 0) {
1647 string msg =
"There may be no othermetadata or other metadata is not counted ";
1648 H5Gclose(ecs_grp_id);
1649 throw InternalErr(__FILE__, __LINE__, msg);
1651 total_othermeta_value = total_othermeta_value + finstr;
1656 string msg =
"Unsupported metadata type ";
1657 H5Gclose(ecs_grp_id);
1658 throw InternalErr(__FILE__, __LINE__, msg);
1668 if (strmeta_num_total > 0) {
1670 if (strmeta_num != -1) {
1671 for (
int i = 0; i <strmeta_num_total; i++)
1672 total_strmeta_value +=strmeta_value[i];
1677 if (
false == s_st_only) {
1679 if (coremeta_num_total >0) {
1680 if (coremeta_num != -1) {
1681 for(
int i = 0; i <coremeta_num_total; i++)
1682 total_coremeta_value +=coremeta_value[i];
1686 if (archmeta_num_total >0) {
1687 if (archmeta_num != -1) {
1688 for(
int i = 0; i <archmeta_num_total; i++)
1689 total_archmeta_value +=archmeta_value[i];
1693 if (submeta_num_total >0) {
1694 if (submeta_num != -1) {
1695 for(
int i = 0; i <submeta_num_total; i++)
1696 total_submeta_value +=submeta_value[i];
1700 if (xmlmeta_num_total >0) {
1701 if (xmlmeta_num != -1) {
1702 for(
int i = 0; i <xmlmeta_num_total; i++)
1703 total_xmlmeta_value +=xmlmeta_value[i];
1707 if (prometa_num_total >0) {
1708 if (prometa_num != -1) {
1709 for(
int i = 0; i <prometa_num_total; i++)
1710 total_prometa_value +=prometa_value[i];
1714 H5Gclose(ecs_grp_id);
1718int get_metadata_num(
const string & meta_str) {
1723 size_t dot_pos = meta_str.find(
".");
1724 if (dot_pos == string::npos)
1726 else if (meta_str.find_first_of(
".") == meta_str.find_last_of(
".")) {
1727 string num_str = meta_str.substr(dot_pos+1);
1732 throw InternalErr(__FILE__,__LINE__,
"Suffix after dots is not a number.");
1736 string str_after_first_dot = meta_str.substr(dot_pos+1);
1737 if (str_after_first_dot.find_first_of(
".") != str_after_first_dot.find_last_of(
"."))
1738 throw InternalErr(__FILE__,__LINE__,
"Currently don't support metadata names containing more than two dots.");
1743 size_t second_dot_pos = str_after_first_dot.find(
".");
1744 string num_str = str_after_first_dot.substr(second_dot_pos+1);
1753void map_eos5_cfdmr(D4Group *d4_root, hid_t file_id,
const string &filename) {
1755 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
1764 bool st_only =
false;
1767 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
1770 "unable to obtain the HDF-EOS5 struct metadata ";
1771 throw InternalErr(__FILE__, __LINE__, msg);
1774 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
1775 if(disable_ecsmetadata ==
false) {
1777 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
1779 if (
false == is_check_disable_smetadata)
1780 add_grp_dap4_attr(d4_root,
"StructMetadata",attr_str_c,st_str);
1783 add_grp_dap4_attr(d4_root,
"CoreMetadata",attr_str_c,core_str);
1786 add_grp_dap4_attr(d4_root,
"ArchiveMetadata",attr_str_c,arch_str);
1789 add_grp_dap4_attr(d4_root,
"XMLMetadata",attr_str_c,xml_str);
1792 add_grp_dap4_attr(d4_root,
"SubsetMetadata",attr_str_c,subset_str);
1794 if(product_str !=
"")
1795 add_grp_dap4_attr(d4_root,
"ProductMetadata",attr_str_c,product_str);
1798 add_grp_dap4_attr(d4_root,
"OtherMetadata",attr_str_c,other_str);
1801 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
1803 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
1808 f =
new EOS5File(filename.c_str(),file_id);
1811 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
1814 bool include_attr =
true;
1825 he5dds_scan_string(st_str.c_str());
1827 he5ddslex_destroy();
1830 p.add_projparams(st_str);
1836 if (c.check_grids_unknown_parameters(&p)) {
1837 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
1840 if (c.check_grids_missing_projcode(&p)) {
1841 throw InternalErr(
"The HDF-EOS5 is missing project code ");
1845 if (c.check_grids_support_projcode(&p)) {
1846 throw InternalErr(
"The current project code is not supported");
1850 c.set_grids_missing_pixreg_orig(&p);
1853 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
1870 throw InternalErr(e.what());
1949 if(
true == is_check_nameclashing)
1957 if(
true == is_check_nameclashing)
1976 throw InternalErr(e.what());
1981 gen_eos5_cfdmr(d4_root,f);
1994 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function "<<endl);
1997 const string filename = f->
getPath();
2003 if (
false == root_attrs.empty()) {
2004 for (
const auto &root_attr:root_attrs)
2005 map_cfh5_grp_attr_to_dap4(d4_root,root_attr);
2009 if (
false == grps.empty()) {
2010 for (
const auto &grp:grps) {
2011 auto tmp_grp_unique = make_unique<D4Attribute>();
2012 auto tmp_grp = tmp_grp_unique.release();
2013 tmp_grp->set_name(grp->getNewName());
2014 tmp_grp->set_type(attr_container_c);
2016 for (
const auto &attr:grp->getAttributes())
2017 map_cfh5_attr_container_to_dap4(tmp_grp,attr);
2018 d4_root->attributes()->add_attribute_nocopy(tmp_grp);
2025 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
2026 for (
const auto &cvar:cvars) {
2027 BESDEBUG(
"h5",
"variable full path= "<< cvar->
getFullPath() <<endl);
2028 gen_dap_oneeos5cvar_dmr(d4_root,cvar,file_id,filename);
2031 for (
const auto &var:vars) {
2032 BESDEBUG(
"h5",
"variable full path= "<< var->getFullPath() <<endl);
2033 gen_dap_onevar_dmr(d4_root,var,file_id,filename);
2037 if (f->Have_EOS5_Grids()==
true)
2038 gen_dap_eos5cf_gm_dmr(d4_root,f);
2042 for (
const auto &var:vars) {
2043 BESDEBUG(
"h5",
"variable full path= "<< var->getFullPath() <<endl);
2044 gen_dap_onevar_dmr(d4_root,var,file_id,filename);
2048 if (f->Have_EOS5_Grids()==
true)
2049 gen_dap_eos5cf_gm_dmr(d4_root,f);
2051 for (
const auto &cvar:cvars) {
2052 BESDEBUG(
"h5",
"variable full path= "<< cvar->
getFullPath() <<endl);
2053 gen_dap_oneeos5cvar_dmr(d4_root,cvar,file_id,filename);
2061 string dods_extra =
"DODS_EXTRA";
2064 if(d4_root->attributes() !=
nullptr) {
2068 string unlimited_dim_names;
2070 for (
const auto &cvar:cvars) {
2078 if(dim->HaveUnlimitedDim() ==
true) {
2080 if(unlimited_dim_names==
"")
2081 unlimited_dim_names = dim->getNewName();
2083 if(unlimited_dim_names.rfind(dim->getNewName()) == string::npos) {
2084 unlimited_dim_names = unlimited_dim_names+
" "+dim->getNewName();
2091 if (unlimited_dim_names !=
"") {
2092 auto unlimited_dim_attr_unique = make_unique<D4Attribute>(
"Unlimited_Dimension",attr_str_c);
2093 auto unlimited_dim_attr = unlimited_dim_attr_unique.release();
2094 unlimited_dim_attr->add_value(unlimited_dim_names);
2095 auto dods_extra_attr_unique = make_unique<D4Attribute>(dods_extra,attr_container_c);
2096 auto dods_extra_attr = dods_extra_attr_unique.release();
2097 dods_extra_attr->attributes()->add_attribute_nocopy(unlimited_dim_attr);
2098 d4_root->attributes()->add_attribute_nocopy(dods_extra_attr);
2101 throw InternalErr(__FILE__, __LINE__,
"Unlimited dimension should exist.");
2108 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
2111 vector <string> cvar_name;
2112 for (
const auto &cvar:cvars)
2115 add_dap4_coverage(d4_root,cvar_name,f->getIsCOARD());
2120void gen_dap_oneeos5cvar_dmr(D4Group* d4_root,
const EOS5CVar* cvar,
const hid_t file_id,
const string & filename){
2122 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dmr() "<<endl);
2123 BaseType *bt =
nullptr;
2126#define HANDLE_CASE(tid,type) \
2128 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
2141 HANDLE_CASE(H5FSTRING,
Str)
2142 HANDLE_CASE(H5VSTRING,
Str)
2144 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
2151 vector <HDF5CF::Dimension*>:: const_iterator it_d;
2152 vector <size_t> dimsizes;
2153 dimsizes.resize(cvar->
getRank());
2154 for (
int i = 0; i <cvar->
getRank();i++)
2155 dimsizes[i] = (dims[i])->getSize();
2158 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
2164 bool is_latlon = cvar->isLatLon();
2165 bool is_dap4 =
true;
2166 auto ar_unique = make_unique<HDF5CFArray>(
2173 cvar->getTotalElems(),
2180 auto ar = ar_unique.get();
2185 for (it_d = dims.begin(); it_d != dims.end(); ++it_d) {
2186 if (
""==(*it_d)->getNewName())
2187 ar->append_dim_ll((*it_d)->getSize());
2189 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
2192 ar->set_is_dap4(
true);
2193 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2194 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2195 d4_root->add_var_nocopy(d4_var);
2203 auto ar_unique = make_unique<HDFEOS5CFMissLLArray> (
2209 cvar->getPointLower(),
2210 cvar->getPointUpper(),
2211 cvar->getPointLeft(),
2212 cvar->getPointRight(),
2213 cvar->getPixelReg(),
2215 cvar->getProjCode(),
2219 cvar->getXDimSize(),
2220 cvar->getYDimSize(),
2223 auto ar = ar_unique.get();
2226 for (it_d = dims.begin(); it_d != dims.end(); ++it_d) {
2227 if (
""==(*it_d)->getNewName())
2228 ar->append_dim_ll((*it_d)->getSize());
2230 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
2233 ar->set_is_dap4(
true);
2234 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2235 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2236 add_var_sp_attrs_to_dap4(d4_var,cvar);
2237 d4_root->add_var_nocopy(d4_var);
2242 case CV_NONLATLON_MISS:
2247 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2251 auto ar_unique = make_unique<HDFEOS5CFMissNonLLCVArray>(
2256 auto ar = ar_unique.get();
2259 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
2260 if (
""==(*it_d)->getNewName())
2261 ar->append_dim_ll((*it_d)->getSize());
2263 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
2266 ar->set_is_dap4(
true);
2267 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2268 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2269 d4_root->add_var_nocopy(d4_var);
2280 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2283 auto ar_unique = make_unique<HDFEOS5CFSpecialCVArray> (
2292 auto ar = ar_unique.get();
2295 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
2296 if (
""==(*it_d)->getNewName())
2297 ar->append_dim_ll((*it_d)->getSize());
2299 ar->append_dim_ll((*it_d)->getSize(), (*it_d)->getNewName());
2302 ar->set_is_dap4(
true);
2303 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2304 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2305 d4_root->add_var_nocopy(d4_var);
2312 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
2321void gen_dap_eos5cf_gm_dmr(libdap::D4Group* d4_root,
const HDF5CF::EOS5File*f) {
2325 gen_gm_proj_var_info(d4_root,f);
2328 gen_gm_proj_spvar_info(d4_root,f);
2334void gen_gm_proj_var_info(libdap::D4Group* d4_root,
const HDF5CF::EOS5File* f) {
2336 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function "<<endl);
2341 unsigned short cv_lat_miss_index = 1;
2342 for (
const auto &cvar:cvars) {
2344 if(cvar->getProjCode() != HE5_GCTP_GEO) {
2345 gen_gm_oneproj_var(d4_root,cvar,cv_lat_miss_index,f);
2346 cv_lat_miss_index++;
2354void gen_gm_oneproj_var(libdap::D4Group*d4_root,
2358 BESDEBUG(
"h5",
"Coming to gen_gm_oneproj_var() "<<endl);
2359 EOS5GridPCType cv_proj_code = cvar->getProjCode();
2363 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
2368 if (HE5_GCTP_SNSOID == cv_proj_code || HE5_GCTP_PS == cv_proj_code || HE5_GCTP_LAMAZ== cv_proj_code) {
2373 string cf_projection_base =
"eos_cf_projection";
2374 string cf_projection_name;
2378 if(HE5_GCTP_SNSOID == cv_proj_code) {
2382 cf_projection_name = cf_projection_base;
2383 if (g_suffix == 1) {
2384 auto dummy_proj_cf_unique = make_unique<HDF5CFGeoCFProj>(cf_projection_name, cf_projection_name);
2385 dummy_proj_cf = dummy_proj_cf_unique.release();
2390 t_suffix_ss << g_suffix;
2391 cf_projection_name = cf_projection_base +
"_" + t_suffix_ss.str();
2392 auto dummy_proj_cf_unique = make_unique<HDF5CFGeoCFProj>(cf_projection_name, cf_projection_name);
2393 dummy_proj_cf = dummy_proj_cf_unique.release();
2396 if (dummy_proj_cf !=
nullptr) {
2397 dummy_proj_cf->set_is_dap4(
true);
2398 add_gm_oneproj_var_dap4_attrs(dummy_proj_cf,cv_proj_code,cvar->getParams());
2399 d4_root->add_var_nocopy(dummy_proj_cf);
2404 if (HDF5RequestHandler::get_add_dap4_coverage() ==
true) {
2406 for (
const auto &gm_cvar:cvars)
2407 cvar_name.emplace_back(gm_cvar->getNewName());
2410 add_cf_grid_cv_dap4_attrs(d4_root,cf_projection_name,dims,cvar_name);
2416void gen_gm_proj_spvar_info(libdap::D4Group* d4_root,
const HDF5CF::EOS5File* f){
2418 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products grid mapping variable generation function "<<endl);
2421 for (
const auto &cvar:cvars) {
2423 if(cvar->getProjCode() != HE5_GCTP_GEO)
2424 gen_gm_oneproj_spvar(d4_root,cvar);
2429void gen_gm_oneproj_spvar(libdap::D4Group *d4_root,
const HDF5CF::EOS5CVar *cvar) {
2431 BESDEBUG(
"h5",
"Coming to gen_gm_oneproj_spvar() "<<endl);
2433 float cv_point_lower = cvar->getPointLower();
2434 float cv_point_upper = cvar->getPointUpper();
2435 float cv_point_left = cvar->getPointLeft();
2436 float cv_point_right = cvar->getPointRight();
2437 EOS5GridPCType cv_proj_code = cvar->getProjCode();
2440 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
2441 add_gm_spcvs(d4_root,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
2445void add_var_sp_attrs_to_dap4(BaseType *d4_var,
const EOS5CVar* cvar) {
2447 if(cvar->getProjCode() == HE5_GCTP_LAMAZ) {
2449 add_var_dap4_attr(d4_var,
"valid_min", attr_float64_c,
"-90.0");
2450 add_var_dap4_attr(d4_var,
"valid_max", attr_float64_c,
"90.0");
2453 add_var_dap4_attr(d4_var,
"valid_min", attr_float64_c,
"-180.0");
2454 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 Adjust_Var_NewName_After_Parsing() const
Adjust variable names for HDF-EOS5 files.
void Add_Supplement_Attrs(bool) override
Add the supplemental attributes for HDF-EOS5 products.
void Set_COARDS_Status()
Set COARDS flag.
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 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 Adjust_Var_Dim_NewName_Before_Flattening() const
Adjust variable dimension names before the flattening for HDF-EOS5 files.
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.