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() != NULL) ||
200 (HDF5RequestHandler::get_srdata_mem_cache() != NULL)){
227 if((HDF5RequestHandler::get_lrdata_mem_cache() != NULL) ||
228 (HDF5RequestHandler::get_srdata_mem_cache() != NULL))
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::Var *>::const_iterator it_v;
427 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
429 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
430 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
431 gen_dap_onevar_dds(dds,*it_v,file_id,filename);
434 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
435 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
436 gen_dap_oneeos5cvar_dds(dds,*it_cv,file_id,filename);
443 unsigned short cv_lat_miss_index = 1;
444 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
445 if((*it_cv)->getCVType() == CV_LAT_MISS) {
446 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
450 gen_dap_oneeos5cf_dds(dds,*it_cv);
451 add_cf_grid_mapinfo_var(dds,(*it_cv)->getProjCode(),cv_lat_miss_index);
460 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_dds() "<<endl);
462 float cv_point_lower = cvar->getPointLower();
463 float cv_point_upper = cvar->getPointUpper();
464 float cv_point_left = cvar->getPointLeft();
465 float cv_point_right = cvar->getPointRight();
466 EOS5GridPCType cv_proj_code = cvar->getProjCode();
467 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
469 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
470 add_cf_grid_cvs(dds,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
474void gen_dap_oneeos5cf_das(DAS &das,
const vector<HDF5CF::Var*>& vars,
const HDF5CF::EOS5CVar* cvar,
const unsigned short g_suffix) {
476 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cf_das() "<<endl);
478 float cv_point_lower = cvar->getPointLower();
479 float cv_point_upper = cvar->getPointUpper();
480 float cv_point_left = cvar->getPointLeft();
481 float cv_point_right = cvar->getPointRight();
483 EOS5GridPCType cv_proj_code = cvar->getProjCode();
484 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
487cerr<<
"cv_point_lower is "<<cv_point_lower <<endl;
488cerr<<
"cvar name is "<<cvar->
getName() <<endl;
489for(vector<HDF5CF::Dimension*>::const_iterator it_d = dims.begin(); it_d != dims.end(); ++it_d)
490 cerr<<
"dim name das is "<<(*it_d)->getNewName() <<endl;
494 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
496 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);
498 add_cf_grid_cv_attrs(das,vars,cv_proj_code,dims,cvar->getParams(),g_suffix);
505 BESDEBUG(
"h5",
"Coming to gen_eos5_cf_ignored_obj_info() "<<endl);
506 AttrTable *at = das.get_table(
"Ignored_Object_Info");
508 at = das.add_table(
"Ignored_Object_Info",
new AttrTable);
516void gen_dap_oneeos5cvar_dds(DDS &dds,
const HDF5CF::EOS5CVar* cvar,
const hid_t file_id,
const string & filename) {
518 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dds() "<<endl);
525#define HANDLE_CASE(tid,type) \
527 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
538 HANDLE_CASE(H5FSTRING,
Str);
539 HANDLE_CASE(H5VSTRING,
Str);
541 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
547 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
548 vector <HDF5CF::Dimension*>:: const_iterator it_d;
549 vector <size_t> dimsizes;
550 dimsizes.resize(cvar->
getRank());
551 for(
int i = 0; i <cvar->
getRank();i++)
552 dimsizes[i] = (dims[i])->getSize();
556 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
563for(vector<HDF5CF::Attribute *>::const_iterator it_ra = cvar->getAttributes().begin();
564 it_ra != cvar->getAttributes().end(); ++it_ra) {
565cerr<<
"cvar attribute name is "<<(*it_ra)->getNewName() <<endl;
566cerr<<
"cvar attribute value type is "<<(*it_ra)->getType() <<endl;
568cerr<<
"cvar new name exist at he s5cfdap.cc is "<<cvar->
getNewName() <<endl;
570 bool is_latlon = cvar->isLatLon();
580 cvar->getTotalElems(),
590 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
593 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
594 if (
""==(*it_d)->getNewName())
595 ar->append_dim((*it_d)->getSize());
597 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
613cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
614cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
615cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
623 cvar->getPointLower(),
624 cvar->getPointUpper(),
625 cvar->getPointLeft(),
626 cvar->getPointRight(),
640 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissLLArray.");
643 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
644 if (
""==(*it_d)->getNewName())
645 ar->append_dim((*it_d)->getSize());
647 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
656 case CV_NONLATLON_MISS:
661 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
675 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissNonLLCVArray.");
679 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
680 if (
""==(*it_d)->getNewName())
681 ar->append_dim((*it_d)->getSize());
683 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
699 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
717 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
721 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
722 if (
""==(*it_d)->getNewName())
723 ar->append_dim((*it_d)->getSize());
725 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
735 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
745 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DAS generation function gen_eos5_cfdas "<<endl);
749 gen_eos5_cf_ignored_obj_info(das, f);
753 const vector<HDF5CF::Var *>& vars = f->
getVars();
754 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
755 const vector<HDF5CF::Group *>& grps = f->
getGroups();
756 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
758 vector<HDF5CF::Var *>::const_iterator it_v;
759 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
760 vector<HDF5CF::Group *>::const_iterator it_g;
761 vector<HDF5CF::Attribute *>::const_iterator it_ra;
765 if (
false == root_attrs.empty()) {
766 AttrTable *at = das.get_table(FILE_ATTR_TABLE_NAME);
768 at = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
770 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); it_ra++) {
771 gen_dap_oneobj_das(at,*it_ra,NULL);
775 if (
false == grps.empty()) {
776 for (it_g = grps.begin();
777 it_g != grps.end(); ++it_g) {
778 AttrTable *at = das.get_table((*it_g)->getNewName());
780 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
782 for (it_ra = (*it_g)->getAttributes().begin();
783 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
786 if((*it_ra)->getNewName()==
"Conventions" &&((*it_g)->getNewName() ==
"HDFEOS_ADDITIONAL_FILE_ATTRIBUTES")
787 && (
true==HDF5RequestHandler::get_eos5_rm_convention_attr_path())) {
788 AttrTable *at_das = das.get_table(FILE_ATTR_TABLE_NAME);
790 at_das = das.add_table(FILE_ATTR_TABLE_NAME,
new AttrTable);
791 gen_dap_oneobj_das(at_das,*it_ra,NULL);
794 gen_dap_oneobj_das(at,*it_ra,NULL);
799 for (it_v = vars.begin();
800 it_v != vars.end(); ++it_v) {
801 if (
false == ((*it_v)->getAttributes().empty())) {
804 if(H5INT64 == (*it_v)->getType() || H5UINT64 == (*it_v)->getType()){
808 AttrTable *at = das.get_table((*it_v)->getNewName());
810 at = das.add_table((*it_v)->getNewName(),
new AttrTable);
812 for (it_ra = (*it_v)->getAttributes().begin();
813 it_ra != (*it_v)->getAttributes().end(); ++it_ra) {
814 gen_dap_oneobj_das(at,*it_ra,*it_v);
819 for (it_cv = cvars.begin(); it_cv !=cvars.end();it_cv++) {
821 if (
false == ((*it_cv)->getAttributes().empty())) {
824 if(H5INT64 == (*it_cv)->getType() || H5UINT64 == (*it_cv)->getType()){
828 AttrTable *at = das.get_table((*it_cv)->getNewName());
830 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
832 for (it_ra = (*it_cv)->getAttributes().begin();
833 it_ra != (*it_cv)->getAttributes().end(); ++it_ra) {
834 gen_dap_oneobj_das(at,*it_ra,*it_cv);
840 unsigned short cv_lat_miss_index = 1;
842 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
843 if((*it_cv)->getCVType() == CV_LAT_MISS) {
844 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
845 gen_dap_oneeos5cf_das(das,vars,*it_cv,cv_lat_miss_index);
851 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
852 if((*it_cv)->getProjCode() == HE5_GCTP_LAMAZ) {
853 if((*it_cv)->getCVType() == CV_LAT_MISS || (*it_cv)->getCVType() == CV_LON_MISS) {
854 AttrTable *at = das.get_table((*it_cv)->getNewName());
856 at = das.add_table((*it_cv)->getNewName(),
new AttrTable);
857 if((*it_cv)->getCVType() == CV_LAT_MISS)
858 add_ll_valid_range(at,
true);
860 add_ll_valid_range(at,
false);
866 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
868 if(disable_ecsmetadata ==
false) {
877 string subset_str=
"";
878 string product_str=
"";
879 string other_str =
"";
880 bool st_only =
false;
882 read_ecs_metadata(file_id, st_str, core_str, arch_str, xml_str,
883 subset_str, product_str, other_str, st_only);
886if(st_str!=
"")
"h5",
"Final structmetadata "<<st_str <<endl;
887if(core_str!=
"")
"h5",
"Final coremetadata "<<core_str <<endl;
888if(arch_str!=
"")
"h5",
"Final archivedmetadata "<<arch_str <<endl;
889if(xml_str!=
"")
"h5",
"Final xmlmetadata "<<xml_str <<endl;
890if(subset_str!=
"")
"h5",
"Final subsetmetadata "<<subset_str <<endl;
891if(product_str!=
"")
"h5",
"Final productmetadata "<<product_str <<endl;
892if(other_str!=
"")
"h5",
"Final othermetadata "<<other_str <<endl;
898 string check_disable_smetadata_key =
"H5.DisableStructMetaAttr";
899 bool is_check_disable_smetadata =
false;
901 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
903 if (
false == is_check_disable_smetadata) {
905 AttrTable *at = das.get_table(
"StructMetadata");
907 at = das.add_table(
"StructMetadata",
new AttrTable);
911 if (he5dasparse(&arg) != 0
912 ||
false == arg.status()){
914 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
915 <<
"StructMetadata " <<
" HDFEOS attribute" << endl);
924 AttrTable *at = das.get_table(
"CoreMetadata");
926 at = das.add_table(
"CoreMetadata",
new AttrTable);
929 if (he5dasparse(&arg) != 0
930 ||
false == arg.status()){
932 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
933 <<
"CoreMetadata " <<
" HDFEOS attribute" << endl);
939 AttrTable *at = das.get_table(
"ArchiveMetadata");
941 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
944 if (he5dasparse(&arg) != 0
945 ||
false == arg.status()){
947 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
948 <<
"ArchiveMetadata " <<
" HDFEOS attribute" << endl);
957 AttrTable *at = das.get_table(
"XMLMetadata");
959 at = das.add_table(
"XMLMetadata",
new AttrTable);
960 HDF5CFDAPUtil::replace_double_quote(xml_str);
961 at->append_attr(
"Contents",
"String",xml_str);
967 if(subset_str !=
""){
968 AttrTable *at = das.get_table(
"SubsetMetadata");
970 at = das.add_table(
"SubsetMetadata",
new AttrTable);
973 if (he5dasparse(&arg) != 0
974 ||
false == arg.status()) {
976 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
977 <<
"SubsetMetadata " <<
" HDFEOS attribute" << endl);
981 if(product_str !=
""){
982 AttrTable *at = das.get_table(
"ProductMetadata");
984 at = das.add_table(
"ProductMetadata",
new AttrTable);
987 if (he5dasparse(&arg) != 0
988 ||
false == arg.status()){
989 ERROR_LOG(
"HDF-EOS5 parse error while processing a "
990 <<
"ProductMetadata " <<
" HDFEOS attribute" << endl);
998 if (other_str !=
""){
999 AttrTable *at = das.get_table(
"OtherMetadata");
1001 at = das.add_table(
"OtherMetadata",
new AttrTable);
1002 at->append_attr(
"Contents",
"String",other_str);
1009 AttrTable *at = das.get_table(
"DODS_EXTRA");
1011 at = das.add_table(
"DODS_EXTRA",
new AttrTable);
1012 string unlimited_names;
1014 for (it_cv = cvars.begin();
1015 it_cv != cvars.end(); it_cv++) {
1017 bool has_unlimited_dim =
false;
1020 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
1021 ird != (*it_cv)->getDimensions().end(); ++ird) {
1026 if((*ird)->HaveUnlimitedDim() ==
true) {
1028 if(unlimited_names==
"") {
1029 unlimited_names = (*ird)->getNewName();
1030 at->append_attr(
"Unlimited_Dimension",
"String",unlimited_names);
1033 if(unlimited_names.rfind((*ird)->getNewName()) == string::npos) {
1034 unlimited_names = unlimited_names+
" "+(*ird)->getNewName();
1035 at->append_attr(
"Unlimited_Dimension",
"String",(*ird)->getNewName());
1056void read_ecs_metadata(hid_t s_file_id,
1057 string &total_strmeta_value,
1058 string &total_coremeta_value,
1059 string &total_archmeta_value,
1060 string &total_xmlmeta_value,
1061 string &total_submeta_value,
1062 string &total_prometa_value,
1063 string &total_othermeta_value,
1066 BESDEBUG(
"h5",
"Coming to read_ecs_metadata() "<<endl);
1067 string ecs_group =
"/HDFEOS INFORMATION";
1068 hid_t ecs_grp_id = -1;
1069 if ((ecs_grp_id = H5Gopen(s_file_id, ecs_group.c_str(),H5P_DEFAULT))<0) {
1071 "h5_ecs_meta: unable to open the HDF5 group ";
1073 throw InternalErr(__FILE__, __LINE__, msg);
1079 if (H5Gget_info(ecs_grp_id,&g_info) <0) {
1081 "h5_ecs_meta: unable to obtain the HDF5 group info. for ";
1083 H5Gclose(ecs_grp_id);
1084 throw InternalErr(__FILE__, __LINE__, msg);
1087 nelems = g_info.nlinks;
1089 ssize_t oname_size = 0;
1091 int cur_archmeta_suffix = 0;
1092 int cur_coremeta_suffix = 0;
1093 int cur_strmeta_suffix = 0;
1094 int cur_xmlmeta_suffix = 0;
1097 int archmeta_num = -1;
1098 int coremeta_num = -1;
1099 int xmlmeta_num = -1;
1100 int strmeta_num = -1;
1101 int submeta_num = -1;
1102 int prometa_num = -1;
1105 int archmeta_num_total = 0;
1106 int coremeta_num_total = 0;
1107 int xmlmeta_num_total = 0;
1108 int strmeta_num_total = 0;
1109 int submeta_num_total = 0;
1110 int prometa_num_total = 0;
1111 int othermeta_num_total = 0;
1113 bool archmeta_no_suffix =
true;
1114 bool coremeta_no_suffix =
true;
1115 bool strmeta_no_suffix =
true;
1116 bool xmlmeta_no_suffix =
true;
1117 bool submeta_no_suffix =
true;
1118 bool prometa_no_suffix =
true;
1121 vector<string> s_oname(nelems);
1125 EOS5Metadata metatype[nelems];
1127 for (
unsigned int i =0; i<nelems; i++)
1128 metatype[i] = OtherMeta;
1130 for (hsize_t i = 0; i < nelems; i++) {
1134 H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
1136 if (oname_size <= 0) {
1137 string msg =
"hdf5 object name error from: ";
1139 H5Gclose(ecs_grp_id);
1140 throw InternalErr(__FILE__, __LINE__, msg);
1144 vector<char> oname(oname_size + 1);
1145 if (H5Lget_name_by_idx(ecs_grp_id,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
1146 (
size_t)(oname_size+1), H5P_DEFAULT)<0){
1147 string msg =
"hdf5 object name error from: ";
1149 H5Gclose(ecs_grp_id);
1150 throw InternalErr(__FILE__, __LINE__, msg);
1156 if (H5Lget_info(ecs_grp_id,&oname[0],&linfo,H5P_DEFAULT)<0) {
1157 string msg =
"hdf5 link name error from: ";
1159 H5Gclose(ecs_grp_id);
1160 throw InternalErr(__FILE__, __LINE__, msg);
1164 if (linfo.type == H5L_TYPE_SOFT){
1165 string msg =
"hdf5 link name error from: ";
1167 H5Gclose(ecs_grp_id);
1168 throw InternalErr(__FILE__, __LINE__, msg);
1173 if (H5OGET_INFO_BY_IDX(ecs_grp_id,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
1174 i, &oinfo, H5P_DEFAULT)<0) {
1175 string msg =
"Cannot obtain the object info ";
1177 H5Gclose(ecs_grp_id);
1178 throw InternalErr(__FILE__, __LINE__, msg);
1181 if(oinfo.type != H5O_TYPE_DATASET) {
1182 string msg =
"hdf5 link name error from: ";
1184 H5Gclose(ecs_grp_id);
1185 throw InternalErr(__FILE__, __LINE__, msg);
1189 string s_one_oname(oname.begin(),oname.end()-1);
1190 s_oname[i] = s_one_oname;
1193 if (((s_one_oname.find(
"StructMetadata"))==0) ||
1194 ((s_one_oname.find(
"structmetadata"))==0)){
1196 metatype[i] = StructMeta;
1203 if (
false == strmeta_no_suffix) {
1204 string msg =
"StructMetadata/structmetadata without suffix should only appear once. ";
1205 H5Gclose(ecs_grp_id);
1206 throw InternalErr(__FILE__, __LINE__, msg);
1209 else if(strmeta_num_total >0)
1210 strmeta_num_total++;
1212 if ((0 == s_one_oname.compare(
"StructMetadata"))||
1213 (0 == s_one_oname.compare(
"structmetadata")))
1214 strmeta_no_suffix =
false;
1215 else strmeta_num_total++;
1218"h5",
"strmeta_num_total= "<<strmeta_num_total <<endl;
1219if(strmeta_no_suffix)
"h5",
"structmeta data has the suffix" <<endl;
1220else "h5",
"structmeta data doesn't have the suffix" <<endl;
1224 if(
false == s_st_only) {
1226 if ((0 == (s_one_oname.find(
"CoreMetadata"))) ||
1227 (0 == (s_one_oname.find(
"coremetadata")))){
1229 metatype[i] = CoreMeta;
1235 if (
false == coremeta_no_suffix) {
1236 string msg =
"CoreMetadata/coremetadata without suffix should only appear once. ";
1237 H5Gclose(ecs_grp_id);
1238 throw InternalErr(__FILE__, __LINE__, msg);
1241 else if(coremeta_num_total >0)
1242 coremeta_num_total++;
1247 if ((0 == s_one_oname.compare(
"CoreMetadata")) ||
1248 (0 == s_one_oname.compare(
"coremetadata")))
1249 coremeta_no_suffix =
false;
1250 else coremeta_num_total++;
1253"h5",
"coremeta_num_total= "<<coremeta_num_total <<endl;
1254if(coremeta_no_suffix)
"h5",
"coreuctmeta data has the suffix" <<endl;
1255else "h5",
"coremeta data doesn't have the suffix" <<endl;
1260 else if ((0 == (s_one_oname.find(
"ArchivedMetadata"))) ||
1261 (0 == (s_one_oname.find(
"archivedmetadata"))) ||
1262 (0 == (s_one_oname.find(
"ArchiveMetadata"))) ||
1263 (0 == (s_one_oname.find(
"archivemetadata")))){
1265 metatype[i] = ArchivedMeta;
1270 if (
false == archmeta_no_suffix) {
1271 string msg =
"archivedmetadata/ArchivedMetadata without suffix should only appear once. ";
1272 H5Gclose(ecs_grp_id);
1273 throw InternalErr(__FILE__, __LINE__, msg);
1276 else if(archmeta_num_total >0)
1277 archmeta_num_total++;
1279 if ((0 == s_one_oname.compare(
"ArchivedMetadata"))||
1280 (0 == s_one_oname.compare(
"archivedmetadata")) ||
1281 (0 == s_one_oname.compare(
"archivemetadata")) ||
1282 (0 == s_one_oname.compare(
"ArchiveMetadata")))
1283 archmeta_no_suffix =
false;
1285 archmeta_num_total++;
1288"h5",
"archmeta_num_total= "<<archmeta_num_total <<endl;
1289if(archmeta_no_suffix)
"h5",
"archuctmeta data has the suffix" <<endl;
1290else "h5",
"archmeta data doesn't have the suffix" <<endl;
1295 else if (((s_one_oname.find(
"SubsetMetadata"))==0) ||
1296 ((s_one_oname.find(
"subsetmetadata"))==0)){
1298 metatype[i] = SubsetMeta;
1303 if (
false == submeta_no_suffix) {
1304 H5Gclose(ecs_grp_id);
1305 string msg =
"submetadata/SubMetadata without suffix should only appear once. ";
1306 throw InternalErr(__FILE__, __LINE__, msg);
1309 else if(submeta_num_total >0)
1310 submeta_num_total++;
1312 if ((0 == s_one_oname.compare(
"SubsetMetadata"))||
1313 (0 == s_one_oname.compare(
"subsetmetadata")))
1314 submeta_no_suffix =
false;
1315 else submeta_num_total++;
1318"h5",
"submeta_num_total= "<<submeta_num_total <<endl;
1319if(submeta_no_suffix)
"h5",
"subuctmeta data has the suffix" <<endl;
1320else "h5",
"submeta data doesn't have the suffix" <<endl;
1325 else if ((0 == (s_one_oname.find(
"XmlMetadata"))) ||
1326 (0 == (s_one_oname.find(
"xmlmetadata")))){
1328 metatype[i] = XMLMeta;
1334 if (
false == xmlmeta_no_suffix) {
1335 H5Gclose(ecs_grp_id);
1336 string msg =
"xmlmetadata/Xmlmetadata without suffix should only appear once. ";
1337 throw InternalErr(__FILE__, __LINE__, msg);
1340 else if(xmlmeta_num_total >0)
1341 xmlmeta_num_total++;
1343 if ((0 == s_one_oname.compare(
"XmlMetadata"))||
1344 (0 == s_one_oname.compare(
"xmlmetadata")))
1345 xmlmeta_no_suffix =
false;
1346 else xmlmeta_num_total++;
1349"h5",
"xmlmeta_num_total= "<<xmlmeta_num_total <<endl;
1350if(xmlmeta_no_suffix)
"h5",
"xmluctmeta data doesn't have the suffix" <<endl;
1351else "h5",
"xmlmeta data has the suffix" <<endl;
1356 else if ((0 == (s_one_oname.find(
"ProductMetadata"))) ||
1357 (0 == (s_one_oname.find(
"productmetadata")))){
1359 metatype[i] = ProductMeta;
1364 if (!prometa_no_suffix) {
1365 H5Gclose(ecs_grp_id);
1366 string msg =
"productmetadata/ProductMetadata without suffix should only appear once. ";
1367 throw InternalErr(__FILE__, __LINE__, msg);
1370 else if(prometa_num_total >0) prometa_num_total++;
1372 if ((0 == s_one_oname.compare(
"ProductMetadata"))||
1373 (0 == s_one_oname.compare(
"productmetadata")))
1374 prometa_no_suffix =
false;
1375 else prometa_num_total++;
1381 else othermeta_num_total++;
1385 s_one_oname.clear();
1390 vector<string> strmeta_value;
1391 if (strmeta_num_total <= 0) {
1392 string msg =
"hdf5 object name error from: ";
1393 H5Gclose(ecs_grp_id);
1394 throw InternalErr(__FILE__, __LINE__, msg);
1397 strmeta_value.resize(strmeta_num_total);
1398 for (
int i = 0; i < strmeta_num_total; i++)
1399 strmeta_value[i]=
"";
1404 vector<string> archmeta_value;
1405 if (archmeta_num_total >0) {
1406 archmeta_value.resize(archmeta_num_total);
1407 for (
int i = 0; i < archmeta_num_total; i++)
1408 archmeta_value[i]=
"";
1412 vector<string> coremeta_value;
1413 if (coremeta_num_total >0) {
1414 coremeta_value.resize(coremeta_num_total);
1415 for (
int i = 0; i < coremeta_num_total; i++)
1416 coremeta_value[i]=
"";
1420 vector<string> xmlmeta_value;
1421 if (xmlmeta_num_total >0) {
1422 xmlmeta_value.resize(xmlmeta_num_total);
1423 for (
int i = 0; i < xmlmeta_num_total; i++)
1424 xmlmeta_value[i]=
"";
1428 vector<string> submeta_value;
1429 if (submeta_num_total >0) {
1430 submeta_value.resize(submeta_num_total);
1431 for (
int i = 0; i < submeta_num_total; i++)
1432 submeta_value[i]=
"";
1436 vector<string> prometa_value;
1437 if (prometa_num_total >0) {
1438 prometa_value.resize(prometa_num_total);
1439 for (
int i = 0; i < prometa_num_total; i++)
1440 prometa_value[i]=
"";
1448 for (hsize_t i = 0; i < nelems; i++) {
1456 if (
true == s_st_only &&
1457 (((s_oname[i].find(
"StructMetadata"))!=0) &&
1458 ((s_oname[i].find(
"structmetadata"))!=0))){
1463 hid_t s_dset_id = -1;
1464 hid_t s_space_id = -1;
1466 hssize_t s_nelms = -1;
1467 size_t dtype_size = -1;
1469 if ((s_dset_id = H5Dopen(ecs_grp_id,s_oname[i].c_str(),H5P_DEFAULT))<0){
1470 string msg =
"Cannot open HDF5 dataset ";
1472 H5Gclose(ecs_grp_id);
1473 throw InternalErr(__FILE__, __LINE__, msg);
1476 if ((s_space_id = H5Dget_space(s_dset_id))<0) {
1477 string msg =
"Cannot open the data space of HDF5 dataset ";
1479 H5Dclose(s_dset_id);
1480 H5Gclose(ecs_grp_id);
1481 throw InternalErr(__FILE__, __LINE__, msg);
1484 if ((s_ty_id = H5Dget_type(s_dset_id)) < 0) {
1485 string msg =
"Cannot get the data type of HDF5 dataset ";
1487 H5Sclose(s_space_id);
1488 H5Dclose(s_dset_id);
1489 H5Gclose(ecs_grp_id);
1490 throw InternalErr(__FILE__, __LINE__, msg);
1492 if ((s_nelms = H5Sget_simple_extent_npoints(s_space_id))<0) {
1493 string msg =
"Cannot get the number of points of HDF5 dataset ";
1496 H5Sclose(s_space_id);
1497 H5Dclose(s_dset_id);
1498 H5Gclose(ecs_grp_id);
1499 throw InternalErr(__FILE__, __LINE__, msg);
1501 if ((dtype_size = H5Tget_size(s_ty_id))==0) {
1503 string msg =
"Cannot get the data type size of HDF5 dataset ";
1506 H5Sclose(s_space_id);
1507 H5Dclose(s_dset_id);
1508 H5Gclose(ecs_grp_id);
1509 throw InternalErr(__FILE__, __LINE__, msg);
1513 vector<char> s_buf(dtype_size*s_nelms +1);
1515 if ((H5Dread(s_dset_id,s_ty_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,&s_buf[0]))<0) {
1517 string msg =
"Cannot read HDF5 dataset ";
1520 H5Sclose(s_space_id);
1521 H5Dclose(s_dset_id);
1522 H5Gclose(ecs_grp_id);
1523 throw InternalErr(__FILE__, __LINE__, msg);
1528 H5Sclose(s_space_id);
1529 H5Dclose(s_dset_id);
1533 string tempstr(s_buf.begin(),s_buf.end());
1535 size_t temp_null_pos = tempstr.find_first_of(
'\0');
1540 string finstr = tempstr.substr(0,temp_null_pos);
1543 if (StructMeta == metatype[i]) {
1547 strmeta_num = get_metadata_num(s_oname[i]);
1550 H5Gclose(ecs_grp_id);
1551 throw InternalErr(__FILE__,__LINE__,
"Obtain structmetadata suffix error.");
1558 if (-1 == strmeta_num)
1559 total_strmeta_value = finstr;
1561 else if (strmeta_value[strmeta_num]!=
"") {
1562 string msg =
"The structmeta value array at this index should be empty string ";
1563 H5Gclose(ecs_grp_id);
1564 throw InternalErr(__FILE__, __LINE__, msg);
1568 strmeta_value[strmeta_num] = finstr;
1572 if (
false == s_st_only &&
1573 (metatype[i] != StructMeta)) {
1575 switch (metatype[i]) {
1579 if (coremeta_num_total < 0) {
1580 string msg =
"There may be no coremetadata or coremetadata is not counted ";
1581 H5Gclose(ecs_grp_id);
1582 throw InternalErr(__FILE__, __LINE__, msg);
1587 coremeta_num = get_metadata_num(s_oname[i]);
1590 H5Gclose(ecs_grp_id);
1591 throw InternalErr(__FILE__,__LINE__,
"Obtain coremetadata suffix error.");
1597 if ( -1 == coremeta_num )
1598 total_coremeta_value = finstr;
1599 else if (coremeta_value[coremeta_num]!=
"") {
1600 string msg =
"The coremeta value array at this index should be empty string ";
1601 H5Gclose(ecs_grp_id);
1602 throw InternalErr(__FILE__, __LINE__, msg);
1607 coremeta_value[coremeta_num] = finstr;
1613 if (archmeta_num_total < 0) {
1614 string msg =
"There may be no archivemetadata or archivemetadata is not counted ";
1615 H5Gclose(ecs_grp_id);
1616 throw InternalErr(__FILE__, __LINE__, msg);
1619 archmeta_num = get_metadata_num(s_oname[i]);
1622 H5Gclose(ecs_grp_id);
1623 throw InternalErr(__FILE__,__LINE__,
"Obtain archivemetadata suffix error.");
1625 if (-1 == archmeta_num )
1626 total_archmeta_value = finstr;
1627 else if (archmeta_value[archmeta_num]!=
"") {
1628 string msg =
"The archivemeta value array at this index should be empty string ";
1629 H5Gclose(ecs_grp_id);
1630 throw InternalErr(__FILE__, __LINE__, msg);
1635 archmeta_value[archmeta_num] = finstr;
1640 if (submeta_num_total < 0) {
1641 string msg =
"The subsetemeta value array at this index should be empty string ";
1642 H5Gclose(ecs_grp_id);
1643 throw InternalErr(__FILE__, __LINE__, msg);
1646 submeta_num = get_metadata_num(s_oname[i]);
1649 H5Gclose(ecs_grp_id);
1650 throw InternalErr(__FILE__,__LINE__,
"Obtain subsetmetadata suffix error.");
1652 if (-1 == submeta_num )
1653 total_submeta_value = finstr;
1654 else if (submeta_value[submeta_num]!=
"") {
1655 string msg =
"The submeta value array at this index should be empty string ";
1656 H5Gclose(ecs_grp_id);
1657 throw InternalErr(__FILE__, __LINE__, msg);
1661 submeta_value[submeta_num] = finstr;
1666 if (prometa_num_total < 0) {
1667 string msg =
"There may be no productmetadata or productmetadata is not counted ";
1668 H5Gclose(ecs_grp_id);
1669 throw InternalErr(__FILE__, __LINE__, msg);
1672 prometa_num = get_metadata_num(s_oname[i]);
1675 H5Gclose(ecs_grp_id);
1676 throw InternalErr(__FILE__,__LINE__,
"Obtain productmetadata suffix error.");
1678 if (prometa_num == -1)
1679 total_prometa_value = finstr;
1680 else if (prometa_value[prometa_num]!=
"") {
1681 string msg =
"The productmeta value array at this index should be empty string ";
1682 H5Gclose(ecs_grp_id);
1683 throw InternalErr(__FILE__, __LINE__, msg);
1687 prometa_value[prometa_num] = finstr;
1692 if (xmlmeta_num_total < 0) {
1693 string msg =
"There may be no xmlmetadata or xmlmetadata is not counted ";
1694 H5Gclose(ecs_grp_id);
1695 throw InternalErr(__FILE__, __LINE__, msg);
1698 xmlmeta_num = get_metadata_num(s_oname[i]);
1701 H5Gclose(ecs_grp_id);
1702 throw InternalErr(__FILE__,__LINE__,
"Obtain XMLmetadata suffix error.");
1704 if (-1 == xmlmeta_num )
1705 total_xmlmeta_value = finstr;
1706 else if (xmlmeta_value[xmlmeta_num]!=
"") {
1707 string msg =
"The xmlmeta value array at this index should be empty string ";
1708 H5Gclose(ecs_grp_id);
1709 throw InternalErr(__FILE__, __LINE__, msg);
1713 xmlmeta_value[xmlmeta_num] = finstr;
1718 if (othermeta_num_total < 0) {
1719 string msg =
"There may be no othermetadata or other metadata is not counted ";
1720 H5Gclose(ecs_grp_id);
1721 throw InternalErr(__FILE__, __LINE__, msg);
1723 total_othermeta_value = total_othermeta_value + finstr;
1728 string msg =
"Unsupported metadata type ";
1729 H5Gclose(ecs_grp_id);
1730 throw InternalErr(__FILE__, __LINE__, msg);
1740 if (strmeta_num_total > 0) {
1742 if (strmeta_num != -1) {
1743 for (
int i = 0; i <strmeta_num_total; i++)
1744 total_strmeta_value +=strmeta_value[i];
1749 if (
false == s_st_only) {
1751 if (coremeta_num_total >0) {
1752 if (coremeta_num != -1) {
1753 for(
int i = 0; i <coremeta_num_total; i++)
1754 total_coremeta_value +=coremeta_value[i];
1758 if (archmeta_num_total >0) {
1759 if (archmeta_num != -1) {
1760 for(
int i = 0; i <archmeta_num_total; i++)
1761 total_archmeta_value +=archmeta_value[i];
1765 if (submeta_num_total >0) {
1766 if (submeta_num != -1) {
1767 for(
int i = 0; i <submeta_num_total; i++)
1768 total_submeta_value +=submeta_value[i];
1772 if (xmlmeta_num_total >0) {
1773 if (xmlmeta_num != -1) {
1774 for(
int i = 0; i <xmlmeta_num_total; i++)
1775 total_xmlmeta_value +=xmlmeta_value[i];
1779 if (prometa_num_total >0) {
1780 if (prometa_num != -1) {
1781 for(
int i = 0; i <prometa_num_total; i++)
1782 total_prometa_value +=prometa_value[i];
1786 H5Gclose(ecs_grp_id);
1790int get_metadata_num(
const string & meta_str) {
1795 size_t dot_pos = meta_str.find(
".");
1796 if (dot_pos == string::npos)
1798 else if (meta_str.find_first_of(
".") == meta_str.find_last_of(
".")) {
1799 string num_str = meta_str.substr(dot_pos+1);
1800 stringstream ssnum(num_str);
1804 throw InternalErr(__FILE__,__LINE__,
"Suffix after dots is not a number.");
1808 string str_after_first_dot = meta_str.substr(dot_pos+1);
1809 if (str_after_first_dot.find_first_of(
".") != str_after_first_dot.find_last_of(
"."))
1810 throw InternalErr(__FILE__,__LINE__,
"Currently don't support metadata names containing more than two dots.");
1815 size_t second_dot_pos = str_after_first_dot.find(
".");
1816 string num_str = str_after_first_dot.substr(second_dot_pos+1);
1817 stringstream ssnum(num_str);
1825void map_eos5_cfdmr(D4Group *d4_root, hid_t file_id,
const string &filename) {
1827 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS mapping function map_eos5_cfdds "<<endl);
1833 string subset_str=
"";
1834 string product_str=
"";
1835 string other_str =
"";
1836 bool st_only =
false;
1839 read_ecs_metadata(file_id,st_str,core_str,arch_str,xml_str, subset_str,product_str,other_str,st_only);
1842 "unable to obtain the HDF-EOS5 struct metadata ";
1843 throw InternalErr(__FILE__, __LINE__, msg);
1846 bool disable_ecsmetadata = HDF5RequestHandler::get_disable_ecsmeta();
1847 if(disable_ecsmetadata ==
false) {
1849 bool is_check_disable_smetadata = HDF5RequestHandler::get_disable_structmeta();
1851 if (
false == is_check_disable_smetadata)
1852 add_grp_dap4_attr(d4_root,
"StructMetadata",attr_str_c,st_str);
1855 add_grp_dap4_attr(d4_root,
"CoreMetadata",attr_str_c,core_str);
1858 add_grp_dap4_attr(d4_root,
"ArchiveMetadata",attr_str_c,arch_str);
1861 add_grp_dap4_attr(d4_root,
"XMLMetadata",attr_str_c,xml_str);
1864 add_grp_dap4_attr(d4_root,
"SubsetMetadata",attr_str_c,subset_str);
1866 if(product_str !=
"")
1867 add_grp_dap4_attr(d4_root,
"ProductMetadata",attr_str_c,product_str);
1870 add_grp_dap4_attr(d4_root,
"OtherMetadata",attr_str_c,other_str);
1873 bool is_check_nameclashing = HDF5RequestHandler::get_check_name_clashing();
1875 bool is_add_path_attrs = HDF5RequestHandler::get_add_path_attrs();
1880 f =
new EOS5File(filename.c_str(),file_id);
1883 throw InternalErr(__FILE__,__LINE__,
"Cannot allocate the file object.");
1886 bool include_attr =
true;
1897 he5dds_scan_string(st_str.c_str());
1899 he5ddslex_destroy();
1902 p.add_projparams(st_str);
1908 if (c.check_grids_unknown_parameters(&p)) {
1909 throw InternalErr(
"Unknown HDF-EOS5 grid paramters found in the file");
1912 if (c.check_grids_missing_projcode(&p)) {
1913 throw InternalErr(
"The HDF-EOS5 is missing project code ");
1917 if (c.check_grids_support_projcode(&p)) {
1918 throw InternalErr(
"The current project code is not supported");
1922 c.set_grids_missing_pixreg_orig(&p);
1925 bool grids_mllcv = c.check_grids_multi_latlon_coord_vars(&p);
1943 throw InternalErr(e.what());
2019 if(
true == is_check_nameclashing)
2027 if(
true == is_check_nameclashing)
2045 throw InternalErr(e.what());
2050 gen_eos5_cfdmr(d4_root,f);
2065 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function "<<endl);
2066 const vector<HDF5CF::Var *>& vars = f->
getVars();
2067 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2068 const string filename = f->
getPath();
2070 const vector<HDF5CF::Group *>& grps = f->
getGroups();
2071 const vector<HDF5CF::Attribute *>& root_attrs = f->
getAttributes();
2073 vector<HDF5CF::Group *>::const_iterator it_g;
2074 vector<HDF5CF::Attribute *>::const_iterator it_ra;
2076 if (
false == root_attrs.empty()) {
2077 for (it_ra = root_attrs.begin(); it_ra != root_attrs.end(); ++it_ra)
2078 map_cfh5_grp_attr_to_dap4(d4_root,*it_ra);
2082 if (
false == grps.empty()) {
2083 for (it_g = grps.begin();
2084 it_g != grps.end(); ++it_g) {
2085 D4Attribute *tmp_grp =
new D4Attribute;
2086 tmp_grp->set_name((*it_g)->getNewName());
2087 tmp_grp->set_type(attr_container_c);
2089 for (it_ra = (*it_g)->getAttributes().begin();
2090 it_ra != (*it_g)->getAttributes().end(); ++it_ra) {
2091 map_cfh5_attr_container_to_dap4(tmp_grp,(*it_ra));
2093 d4_root->attributes()->add_attribute_nocopy(tmp_grp);
2098 vector<HDF5CF::Var *>::const_iterator it_v;
2099 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
2101 for (it_v = vars.begin(); it_v !=vars.end();++it_v) {
2102 BESDEBUG(
"h5",
"variable full path= "<< (*it_v)->getFullPath() <<endl);
2103 gen_dap_onevar_dmr(d4_root,*it_v,file_id,filename);
2107 if (f->Have_EOS5_Grids()==
true)
2108 gen_dap_eos5cf_gm_dmr(d4_root,f);
2110 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2111 BESDEBUG(
"h5",
"variable full path= "<< (*it_cv)->getFullPath() <<endl);
2112 gen_dap_oneeos5cvar_dmr(d4_root,*it_cv,file_id,filename);
2119 string dods_extra =
"DODS_EXTRA";
2122 if(d4_root->attributes() != NULL) {
2125 string unlimited_dim_names =
"";
2127 for (it_cv = cvars.begin();
2128 it_cv != cvars.end(); it_cv++) {
2131 for (vector<Dimension*>::const_iterator ird = (*it_cv)->getDimensions().begin();
2132 ird != (*it_cv)->getDimensions().end(); ++ird) {
2137 if((*ird)->HaveUnlimitedDim() ==
true) {
2139 if(unlimited_dim_names==
"")
2140 unlimited_dim_names = (*ird)->getNewName();
2142 if(unlimited_dim_names.rfind((*ird)->getNewName()) == string::npos) {
2143 unlimited_dim_names = unlimited_dim_names+
" "+(*ird)->getNewName();
2150 if(unlimited_dim_names !=
"") {
2151 D4Attribute *dods_extra_attr =
new D4Attribute(dods_extra,attr_container_c);
2152 D4Attribute *unlimited_dim_attr =
new D4Attribute(
"Unlimited_Dimension",attr_str_c);
2153 unlimited_dim_attr->add_value(unlimited_dim_names);
2154 dods_extra_attr->attributes()->add_attribute_nocopy(unlimited_dim_attr);
2155 d4_root->attributes()->add_attribute_nocopy(dods_extra_attr);
2159 throw InternalErr(__FILE__, __LINE__,
"Unlimited dimension should exist.");
2168void gen_dap_oneeos5cvar_dmr(D4Group* d4_root,
const EOS5CVar* cvar,
const hid_t file_id,
const string & filename){
2170 BESDEBUG(
"h5",
"Coming to gen_dap_oneeos5cvar_dmr() "<<endl);
2171 BaseType *bt = NULL;
2174#define HANDLE_CASE(tid,type) \
2176 bt = new (type)(cvar->getNewName(),cvar->getFullPath()); \
2189 HANDLE_CASE(H5FSTRING,
Str);
2190 HANDLE_CASE(H5VSTRING,
Str);
2192 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
2198 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
2199 vector <HDF5CF::Dimension*>:: const_iterator it_d;
2200 vector <size_t> dimsizes;
2201 dimsizes.resize(cvar->
getRank());
2202 for(
int i = 0; i <cvar->
getRank();i++)
2203 dimsizes[i] = (dims[i])->getSize();
2207 throw InternalErr(__FILE__,__LINE__,
"the coordinate variables cannot be scalar.");
2213 bool is_latlon = cvar->isLatLon();
2216 bool is_dap4 =
true;
2224 cvar->getTotalElems(),
2234 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
2237 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
2238 if (
""==(*it_d)->getNewName())
2239 ar->append_dim((*it_d)->getSize());
2241 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
2244 ar->set_is_dap4(
true);
2245 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2246 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2247 d4_root->add_var_nocopy(d4_var);
2261cerr<<
"cvar zone here is "<<cvar->getZone() <<endl;
2262cerr<<
"cvar Sphere here is "<<cvar->getSphere() <<endl;
2263cerr<<
"cvar getParams here 1 is "<<cvar->getParams()[0]<<endl;
2271 cvar->getPointLower(),
2272 cvar->getPointUpper(),
2273 cvar->getPointLeft(),
2274 cvar->getPointRight(),
2275 cvar->getPixelReg(),
2277 cvar->getProjCode(),
2281 cvar->getXDimSize(),
2282 cvar->getYDimSize(),
2288 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissLLArray.");
2291 for(it_d = dims.begin(); it_d != dims.end(); ++it_d) {
2292 if (
""==(*it_d)->getNewName())
2293 ar->append_dim((*it_d)->getSize());
2295 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
2298 ar->set_is_dap4(
true);
2299 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2300 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2301 add_var_sp_attrs_to_dap4(d4_var,cvar);
2302 d4_root->add_var_nocopy(d4_var);
2309 case CV_NONLATLON_MISS:
2314 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2328 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDFEOS5CFMissNonLLCVArray.");
2332 for(it_d = dims.begin(); it_d != dims.end(); it_d++) {
2333 if (
""==(*it_d)->getNewName())
2334 ar->append_dim((*it_d)->getSize());
2336 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
2339 ar->set_is_dap4(
true);
2340 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2341 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2342 d4_root->add_var_nocopy(d4_var);
2357 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2375 throw InternalErr(__FILE__,__LINE__,
"unable to allocate memory for HDF5CFArray.");
2379 for(it_d = dims.begin(); it_d != dims.end(); ++it_d){
2380 if (
""==(*it_d)->getNewName())
2381 ar->append_dim((*it_d)->getSize());
2383 ar->append_dim((*it_d)->getSize(), (*it_d)->getNewName());
2386 ar->set_is_dap4(
true);
2387 BaseType* d4_var=ar->h5cfdims_transform_to_dap4(d4_root);
2388 map_cfh5_var_attrs_to_dap4(cvar,d4_var);
2389 d4_root->add_var_nocopy(d4_var);
2397 throw InternalErr(__FILE__,__LINE__,
"Unsupported coordinate variable type.");
2410 gen_gm_proj_var_info(d4_root,f);
2413 gen_gm_proj_spvar_info(d4_root,f);
2421 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products DDS generation function "<<endl);
2422 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2423 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
2427 unsigned short cv_lat_miss_index = 1;
2428 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2429 if((*it_cv)->getCVType() == CV_LAT_MISS) {
2430 if((*it_cv)->getProjCode() != HE5_GCTP_GEO) {
2431 gen_gm_oneproj_var(d4_root,*it_cv,cv_lat_miss_index);
2432 cv_lat_miss_index++;
2440void gen_gm_oneproj_var(libdap::D4Group*d4_root,
2442 const unsigned short g_suffix) {
2444 BESDEBUG(
"h5",
"Coming to gen_gm_oneproj_var() "<<endl);
2445 EOS5GridPCType cv_proj_code = cvar->getProjCode();
2446 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
2449 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
2454 if (HE5_GCTP_SNSOID == cv_proj_code || HE5_GCTP_PS == cv_proj_code || HE5_GCTP_LAMAZ== cv_proj_code) {
2459 string cf_projection_base =
"eos_cf_projection";
2460 string cf_projection_name;
2464 if(HE5_GCTP_SNSOID == cv_proj_code) {
2468 cf_projection_name = cf_projection_base;
2470 dummy_proj_cf =
new HDF5CFGeoCFProj(cf_projection_name, cf_projection_name);
2473 stringstream t_suffix_ss;
2474 t_suffix_ss << g_suffix;
2475 cf_projection_name = cf_projection_base +
"_" + t_suffix_ss.str();
2476 dummy_proj_cf =
new HDF5CFGeoCFProj(cf_projection_name, cf_projection_name);
2479 if(dummy_proj_cf != NULL) {
2480 dummy_proj_cf->set_is_dap4(
true);
2481 add_gm_oneproj_var_dap4_attrs(dummy_proj_cf,cv_proj_code,cvar->getParams());
2482 d4_root->add_var_nocopy(dummy_proj_cf);
2486 add_cf_grid_cv_dap4_attrs(d4_root,cf_projection_name,dims);
2494 BESDEBUG(
"h5",
"Coming to HDF-EOS5 products grid mapping variable generation function "<<endl);
2495 const vector<HDF5CF::EOS5CVar *>& cvars = f->
getCVars();
2496 vector<HDF5CF::EOS5CVar *>::const_iterator it_cv;
2498 for (it_cv = cvars.begin(); it_cv !=cvars.end();++it_cv) {
2499 if((*it_cv)->getCVType() == CV_LAT_MISS) {
2500 if((*it_cv)->getProjCode() != HE5_GCTP_GEO)
2501 gen_gm_oneproj_spvar(d4_root,*it_cv);
2506void gen_gm_oneproj_spvar(libdap::D4Group *d4_root,
const HDF5CF::EOS5CVar *cvar) {
2508 BESDEBUG(
"h5",
"Coming to gen_gm_oneproj_spvar() "<<endl);
2510 float cv_point_lower = cvar->getPointLower();
2511 float cv_point_upper = cvar->getPointUpper();
2512 float cv_point_left = cvar->getPointLeft();
2513 float cv_point_right = cvar->getPointRight();
2514 EOS5GridPCType cv_proj_code = cvar->getProjCode();
2515 const vector<HDF5CF::Dimension *>& dims = cvar->
getDimensions();
2517 throw InternalErr(__FILE__,__LINE__,
"Currently we only support the 2-D CF coordinate projection system.");
2518 add_gm_spcvs(d4_root,cv_proj_code,cv_point_lower,cv_point_upper,cv_point_left,cv_point_right,dims);
2522void add_var_sp_attrs_to_dap4(BaseType *d4_var,
const EOS5CVar* cvar) {
2524 if(cvar->getProjCode() == HE5_GCTP_LAMAZ) {
2526 add_var_dap4_attr(d4_var,
"valid_min", attr_float64_c,
"-90.0");
2527 add_var_dap4_attr(d4_var,
"valid_max", attr_float64_c,
"90.0");
2530 add_var_dap4_attr(d4_var,
"valid_min", attr_float64_c,
"-180.0");
2531 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.
void Add_EOS5File_Info(HE5Parser *, bool)
Add HDF-EOS5 dimension and coordinate variable related info. to EOS5Grid,EOS5Swath etc.
void Set_COARDS_Status()
Set COARDS flag.
virtual void Handle_Unsupported_Dtype(bool)
Handle unsupported HDF5 datatypes for HDF-EOS5 products.
void Adjust_Var_Dim_NewName_Before_Flattening()
Adjust variable dimension names before the flattening for HDF-EOS5 files.
void Adjust_Attr_Info()
Adjust the attribute info for HDF-EOS5 products.
virtual const std::string & Get_Ignored_Msg()
Obtain the message that contains the ignored object info.
virtual void Handle_SpVar_DMR()
Handle special variables and attributes for HDF-EOS5 files(for DMR)
void Handle_Obj_NameClashing(bool)
Handle the object name clashing for HDF-EOS5 products.
virtual void Retrieve_H5_CVar_Supported_Attr_Values()
Retrieve coordinate variable attributes.
virtual void Adjust_Obj_Name()
This method is a no-op operation. Leave here since the method in the base class is pure virtual.
virtual void Handle_SpVar()
Handle special variables for HDF-EOS5 files.
virtual void Retrieve_H5_Info(const char *path, hid_t file_id, bool include_attr)
Retrieve DDS information from the HDF5 file; a real implementation for HDF-EOS5 products.
virtual void Handle_DimNameClashing()
virtual void Handle_CVar()
Handle coordinate variable for HDF-EOS5 files.
virtual void Handle_SpVar_Attr()
Handle special variables for HDF-EOS5 files.
virtual void Retrieve_H5_Supported_Attr_Values()
Retrieve attribute values for the supported HDF5 datatypes for HDF-EOS5 products.
virtual void Handle_Coor_Attr()
Handle the coordinates attribute for HDF-EOS5 products.
void Adjust_Var_NewName_After_Parsing()
Adjust variable names for HDF-EOS5 files.
virtual void Add_Supplement_Attrs(bool)
Add the supplemental attributes for HDF-EOS5 products.
void Add_Dim_Name(HE5Parser *)
Add the dimension name for HDF-EOS5 files.
virtual void Handle_Unsupported_Others(bool)
Handle other unmapped objects/attributes for HDF-EOS5 products.
virtual void Flatten_Obj_Name(bool include_attr)
Flatten the object name for HDF-EOS5 files.
virtual void Adjust_Dim_Name()
Adjust the dimension name for HDF-EOS5 products.
virtual void Handle_Unsupported_Dspace(bool)
Handle unsupported HDF5 dataspaces for HDF-EOS5 products.
void Check_Aura_Product_Status()
Check if the HDF-EOS5 file is an Aura file. Special CF operations need to be used.
virtual bool Get_IgnoredInfo_Flag()
Obtain the flag to see if ignored objects should be generated.
const std::vector< EOS5CVar * > & getCVars() const
Obtain coordinate variables for HDF-EOS5 products.
virtual void Adjust_EOS5Dim_Info(HE5Parser *strmeta_info)
Adjust HDF-EOS5 dimension information.
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.
int getRank() const
Get the dimension rank of this variable.
const std::string & getFullPath() const
Get the full path of this variable.
const std::string & getName() const
Get the original name of this variable.
H5DataType getType() const
Get the data type of this variable(Not HDF5 datatype id)
const std::vector< Dimension * > & getDimensions() const
Get the list of the dimensions.
int getCompRatio() const
Get the compression ratio of this dataset.
const std::string & getNewName() const
Get the new name of this variable.
Helper functions for generating DAS attributes and a function to check BES Key.
yy_buffer_state * he5das_scan_string(const char *str)
Buffer state for NASA EOS metadata scanner.
Map and generate DDS and DAS for the CF option for HDF-EOS5 products.