50#include "config_hdf.h"
65#include <unordered_set>
71#ifdef HAVE_SYS_PARAM_H
86#include <libdap/DMR.h>
87#include <libdap/D4Group.h>
88#include <libdap/D4Attributes.h>
90#include <libdap/DDS.h>
91#include <libdap/DAS.h>
92#include <libdap/escaping.h>
93#include <libdap/parser.h>
94#include <libdap/InternalErr.h>
95#include <libdap/debug.h>
97#include <libdap/Array.h>
102#include "HDF4RequestHandler.h"
109#include "HDFSequence.h"
110#include "HDFTypeFactory.h"
116#define SIGNED_BYTE_TO_INT32 1
122#include "HDFUInt16.h"
124#include "HDFUInt32.h"
125#include "HDFFloat32.h"
126#include "HDFFloat64.h"
134#include "HDFSPArray_RealField.h"
135#include "HDFSPArrayGeoField.h"
136#include "HDFSPArrayMissField.h"
137#include "HDFSPArrayAddCVField.h"
138#include "HDFSPArray_VDField.h"
139#include "HDFCFStrField.h"
141#include "HDFCFUtil.h"
144#include "HDFDMRArray_VD.h"
145#include "HDFDMRArray_SDS.h"
146#include "HDFDMRArray_EOS2LL.h"
147#include "HDFDMRArray_SPLL.h"
150#ifdef USE_HDFEOS2_LIB
152#include "HDFEOS2GeoCFProj.h"
153#include "HDFEOS2GeoCF1D.h"
154#include "HDFEOS2Array_RealField.h"
155#include "HDFEOS2ArrayGridGeoField.h"
156#include "HDFEOS2ArraySwathGeoField.h"
157#include "HDFEOS2ArrayMissField.h"
158#include "HDFEOS2ArraySwathDimMapField.h"
159#include "HDFEOS2ArraySwathGeoMultiDimMapField.h"
160#include "HDFEOS2ArraySwathGeoDimMapExtraField.h"
163#include "HDFEOS2HandleType.h"
171#define ATTR_STRING_QUOTE_FIX
173template <
class T >
string num2string(T n)
181void hdfeos_switch_to_buffer(
void *new_buffer);
182void hdfeos_delete_buffer(
void * buffer);
183void *hdfeos_string(
const char *yy_str);
185struct yy_buffer_state;
186yy_buffer_state *hdfeos_scan_string(
const char *str);
187extern int hdfeosparse(libdap::parser_arg *arg);
189typedef struct eos2_grid {
197typedef struct eos2_grid_info {
208void AddHDFAttr(DAS & das,
const string & varname,
209 const vector < hdf_attr > &hav);
210void AddHDFAttr(DAS & das,
const string & varname,
211 const vector < string > &anv);
213static void build_descriptions(DDS & dds, DAS & das,
214 const string & filename);
215static void SDS_descriptions(sds_map & map, DAS & das,
216 const string & filename);
217static void Vdata_descriptions(vd_map & map, DAS & das,
218 const string & filename);
219static void Vgroup_descriptions(DDS & dds, DAS & das,
220 const string & filename, sds_map & sdmap,
221 vd_map & vdmap, gr_map & grmap);
222static void GR_descriptions(gr_map & map, DAS & das,
223 const string & filename);
224static void FileAnnot_descriptions(DAS & das,
const string & filename);
225static vector < hdf_attr > Pals2Attrs(
const vector < hdf_palette > palv);
226static vector < hdf_attr > Dims2Attrs(
const hdf_dim dim);
230void read_dmr(DMR *dmr,
const string &filename);
231void read_sd_attrs(D4Group *root_grp, int32 fileid, int32 sdfd);
232void handle_sds_dims(D4Group *root_grp, int32 fileid, int32 sdfd);
233void read_lone_sds(D4Group *root_grp, int32 file_id, int32 sdfd,
const string &filename);
234void read_lone_vdata(D4Group *root_grp, int32 file_id, int32 sdfd,
const string &filename);
235void read_dmr_vlone_groups(D4Group *root_grp, int32 file_id, int32 sdfd,
const string &filename);
238void convert_vgroup_objects(int32 vgroup_id,int32 file_id, int32 sdfd, D4Group* d4g, D4Group *root_grp,
const string &vgroupname,
const string & filename,
bool is_eos2_grid,
bool is_eos2_grid_cf_mapping);
239void convert_vgroup_attrs(int32 vgroup_id,D4Group* d4g,
const string &vgroupname);
240void map_vgroup_attr(D4Group *d4g,
const string &dap4_attrname,int32 attr_type, int32 attr_count, vector<char> & attr_value);
241bool reserved_vgroups(
const vector<char> &vgroup_class);
245void vgroup_convert_sds_objects(int32 vgroup_id,int32 file_id,int32 sdfd,D4Group* d4g,
const string& filename);
247void convert_sds(int32 file_id, int32 sdfd,int32 vgroup_id, int32 obj_ref, D4Group* d4g,D4Group *root_grp,
const string &filename,
bool is_eos2_grid,
bool is_eos2_grid_cf_mapping);
248void obtain_all_sds_refs(int32 file_id, int32 sdfd, unordered_set<int32>& sds_ref);
249void exclude_all_sds_refs_in_vgroups(int32 file_id, int32 sdfd, unordered_set<int32>&sds_ref);
250void exclude_sds_refs_in_vgroup(int32 file_id, int32 sdfd, int32 vgroup_id, unordered_set<int32>&sds_ref);
251void map_sds_var_dap4_attrs(
HDFDMRArray_SDS *ar, int32 sds_id, int32 obj_ref, int32 n_sds_attrs);
252void map_sds_vdata_attr(BaseType *d4b,
const string &attr_name,int32 attr_type, int32 attr_count, vector<char> & attr_value);
255void convert_vdata(int32 fileid, int32 sdfd, int32 vgroup_id,int32 obj_ref ,D4Group* d4g,
const string& filename);
256void map_vdata_to_dap4_structure_array(int32 vdata_id, int32 num_elms, int32 nflds, int32 obj_ref, D4Group *d4g,
const string &filename);
257void map_vdata_to_dap4_atomic_array(int32 vdata_id, int32 num_elms, int32 obj_ref, D4Group *d4g,
const string &filename);
258void map_vdata_to_dap4_attrs(
HDFDMRArray_VD *ar, int32 vdata_id, int32 obj_ref);
261int is_group_eos2_grid(
const string& vgroup_name, vector<eos2_grid_t>& eos2_grid_lls);
262void add_eos2_latlon_info(D4Group *d4_grp, D4Group *root_grp,
const eos2_grid_t &eos2_grid,
const eos2_grid_info_t &eos2_grid_info,
const string&filename);
263void add_dummy_grid_cv(D4Group *d4_grp,
const eos2_grid_t &eos2_grid,
const eos2_grid_info_t &eos2_grid_info);
264void add_ps_cf_grid_mapping_attrs(libdap::BaseType *var,
const eos2_grid_info_t & eg_info);
265void add_lamaz_cf_grid_mapping_attrs(libdap::BaseType *var,
const eos2_grid_info_t & eg_info);
266void add_CF_1D_cvs(D4Group *d4_grp, D4Group *root_grp,
const eos2_grid_t &eos2_grid,
const eos2_grid_info_t &eos2_grid_info,
const string& xdim_path,
const string &ydim_path);
267void add_CF_1D_cv_attrs(libdap::BaseType *var,
bool is_ydim);
271bool add_sp_hdf4_info(D4Group *d4_grp,
const string &filename,
string & err_msg);
272bool add_sp_hdf4_trmm_info(D4Group *d4_grp,
const string &filename,
const D4Attribute *d4_attr,
string &err_msg);
273void add_sp_hdf4_additional_info(D4Group *d4_grp);
276void add_obj_ref_attr(BaseType * d4b,
bool is_sds, int32 obj_ref);
277void add_sds_fvalue_attr(BaseType *d4b, int32 sds_id);
278BaseType * gen_dap_var(int32 h4_type,
const string & h4_str,
const string & filename);
279D4AttributeType h4type_to_dap4_attrtype(int32 h4_type);
280string print_dap4_attr(int32 type,
int loc,
void *vals);
281void close_vgroup_fileids(int32 fileid, int32 sdfd, int32 vgroup_id);
282void add_var_dap4_attr(BaseType *d4_var,
const string& attr_name, D4AttributeType attr_type,
const string& attr_value);
283void dims_transform_to_dap4(Array *ar,D4Group *root_grp,
bool missing_vars);
288void read_das(DAS & das,
const string & filename);
289void read_dds(DDS & dds,
const string & filename);
293bool read_dds_hdfsp(DDS & dds,
const string & filename,int32 sdfd, int32 fileid,
const HDFSP::File*h4file);
294bool read_das_hdfsp(DAS & das,
const string & filename,int32 sdfd, int32 fileid,
HDFSP::File**h4filepptr);
297bool read_dds_hdfhybrid(DDS & dds,
const string & filename,int32 sdfd, int32 fileid,
const HDFSP::File*h4file);
298bool read_das_hdfhybrid(DAS & das,
const string & filename,int32 sdfd, int32 fileid,
HDFSP::File**h4filepptr);
301bool read_dds_special_1d_grid(DDS &dds,
const HDFSP::File *spf,
const string & filename,int32 sdfd,
bool can_cache);
302bool read_das_special_eos2(DAS &das,
const string & filename,int32 sdid, int32 fileid,
bool ecs_metadata,
HDFSP::File**h4filepptr);
303bool read_das_special_eos2_core(DAS &das,
const HDFSP::File *spf,
const string & filename,
bool ecs_metadata);
305void read_das_sds(DAS & das,
const string & filename,int32 sdfd,
bool ecs_metadata,
HDFSP::File**h4fileptr);
306void read_dds_sds(DDS &dds,
const string & filename,int32 sdfd,
HDFSP::File*h4file,
bool dds_set_cache);
308void read_das_simple_cf(DAS &das, int32 sdfd, int32 fileid);
309void read_dds_simple_cf(DDS &dds,
const string & filename, int32 sdfd, int32 fileid,
short cf_simple_type);
310void obtain_cf_simple_lat_lon(int32 sdfd,
string &lat_name,
string &lon_name,
int &lat_size,
int &lon_size);
312void change_das_mod08_scale_offset(DAS & das,
const HDFSP::File *spf);
315void read_dds_spfields(DDS &dds,
const string& filename,
const int sdfd,
const HDFSP::SDField *spsds, SPType sptype);
318void read_dds_spvdfields(DDS &dds,
const string& filename,
const int fileid,int32 vdref, int32 numrec,
HDFSP::VDField *spvd);
321int check_special_eosfile(
const string&filename,
string&grid_name,int32 sdfd);
324#ifdef USE_HDFEOS2_LIB
326bool obtain_eos2_gd_ll_info(
const string & fname,
const string &grid_name, int32 &ydim, int32 &xdim,
bool & oned_ll, eos2_grid_info_t &eos2_grid_info);
327bool check_eos2_grids(
const string &filename, int32 sdfd,vector<eos2_grid_t>& eos2_grid_lls, vector<eos2_grid_info_t>& eos2_grids_info);
330void parse_ecs_metadata(DAS &das,
const string & metaname,
const string &metadata);
347int read_dds_hdfeos2(DDS & dds,
const string & filename,int32 sdfd, int32 gridfd, int32 swathfd,
const HDFSP::File*h4file,HDFEOS2::File*eosfile);
350int read_das_hdfeos2(DAS & das,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
bool ecs_metadata,
HDFSP::File**h4filepptr,HDFEOS2::File**eosfilepptr);
353void read_dds_hdfeos2_grid_swath(DDS &dds,
const string&filename, HDFEOS2::Dataset *dataset,
int grid_or_swath,
354 bool ownll, SOType sotype,
bool multi_dmap,int32 sdfd, int32 gridfd,int32 swathfd)
357 BESDEBUG(
"h4",
"Coming to read_dds_hdfeos2_grid_swath "<<endl);
360 if (grid_or_swath < 0 || grid_or_swath > 1)
361 throw InternalErr(__FILE__, __LINE__,
"The current type should be either grid or swath");
366 vector<struct dimmap_entry> dimmaps;
369 string modis_geofilename=
"";
370 bool geofile_has_dimmap =
false;
374 if (grid_or_swath == 1)
375 HDFCFUtil::obtain_dimmap_info(filename,dataset,dimmaps,modis_geofilename,geofile_has_dimmap);
381 const vector<HDFEOS2::Field*>& fields = dataset->getDataFields();
382 vector<HDFEOS2::Field*> all_fields = fields;
385 if (1 == grid_or_swath) {
386 auto sw =
static_cast<HDFEOS2::SwathDataset *
>(dataset);
387 const vector<HDFEOS2::Field*>geofields = sw->getGeoFields();
388 for (it_f = geofields.begin(); it_f != geofields.end(); it_f++)
389 all_fields.push_back(*it_f);
394 for(it_f = all_fields.begin(); it_f != all_fields.end(); it_f++)
396 BESDEBUG(
"h4",
"New field Name " <<(*it_f)->getNewName()<<endl);
398 BaseType *bt=
nullptr;
401 int fieldtype = (*it_f)->getFieldType();
405 bool changedtype =
false;
406 for (
auto const &cf:ctype_field_namelist){
407 if (cf == (*it_f)->getNewName()){
413 switch((*it_f)->getType())
416#define HANDLE_CASE2(tid, type) \
418 if(true == changedtype && fieldtype==0) \
419 bt = new (HDFFloat32) ((*it_f)->getNewName(), (dataset)->getName()); \
421 bt = new (type)((*it_f)->getNewName(), (dataset)->getName()); \
424#define HANDLE_CASE(tid, type)\
426 bt = new (type)((*it_f)->getNewName(), (dataset)->getName()); \
430 HANDLE_CASE(DFNT_CHAR8,
HDFStr)
431#ifndef SIGNED_BYTE_TO_INT32
432 HANDLE_CASE2(DFNT_INT8,
HDFByte)
436 HANDLE_CASE2(DFNT_UINT8,
HDFByte)
441 HANDLE_CASE2(DFNT_UCHAR8,
HDFByte)
443 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
450 const vector<HDFEOS2::Dimension*>& dims= (*it_f)->getCorrectedDimensions();
454 if(DFNT_CHAR == (*it_f)->getType()) {
456 if((*it_f)->getRank() >1) {
458 HDFEOS2CFStrField * ar =
nullptr;
462 ar =
new HDFEOS2CFStrField(
463 (*it_f)->getRank() -1,
464 (grid_or_swath ==0)?gridfd:swathfd,
469 (*it_f)->getNewName(),
474 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
476 for(it_d = dims.begin(); it_d != dims.begin()+dims.size()-1; it_d++){
477 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
488 HDFEOS2CFStr * sca_str =
nullptr;
491 sca_str =
new HDFEOS2CFStr(
492 (grid_or_swath ==0)?gridfd:swathfd,
496 (*it_f)->getNewName(),
501 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
503 dds.add_var(sca_str);
511 else if(fieldtype == 0 || fieldtype == 3 || fieldtype == 5) {
514 if(grid_or_swath==0){
515 HDFEOS2Array_RealField *ar =
nullptr;
516 ar =
new HDFEOS2Array_RealField(
518 filename,
false,sdfd,gridfd,
519 dataset->getName(),
"", (*it_f)->getName(),
521 (*it_f)->getNewName(), bt);
522 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
523 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
529 else if(grid_or_swath==1){
531 string tempfieldname = (*it_f)->getName();
534 if((*it_f)->UseDimMap() &&
false == multi_dmap) {
537 if (!modis_geofilename.empty()) {
540 if (
true == HDFCFUtil::is_modis_dimmap_nonll_field(tempfieldname)) {
542 if(
false == geofile_has_dimmap) {
549 HDFEOS2Array_RealField *ar =
nullptr;
550 ar =
new HDFEOS2Array_RealField(
557 "MODIS_Swath_Type_GEO",
560 (*it_f)->getNewName(),
563 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
564 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
571 HDFEOS2ArraySwathDimMapField * ar =
nullptr;
578 ar =
new HDFEOS2ArraySwathDimMapField(
585 "MODIS_Swath_Type_GEO",
589 (*it_f)->getNewName(),
591 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
592 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
600 HDFEOS2ArraySwathDimMapField * ar =
nullptr;
606 ar =
new HDFEOS2ArraySwathDimMapField(
617 (*it_f)->getNewName(),
620 for (it_d = dims.begin(); it_d != dims.end(); it_d++)
621 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
629 HDFEOS2ArraySwathDimMapField * ar =
nullptr;
630 ar =
new HDFEOS2ArraySwathDimMapField(
641 (*it_f)->getNewName(),
643 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
644 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
652 HDFEOS2Array_RealField * ar =
nullptr;
653 ar =
new HDFEOS2Array_RealField(
663 (*it_f)->getNewName(),
665 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
666 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
674 throw InternalErr(__FILE__, __LINE__,
"The current type should be either grid or swath");
679 else if(fieldtype == 1 || fieldtype == 2) {
682 if (grid_or_swath==0) {
684 HDFEOS2ArrayGridGeoField *ar =
nullptr;
685 bool ydimmajor = (*it_f)->getYDimMajor();
686 bool condenseddim = (*it_f)->getCondensedDim();
687 bool speciallon = (*it_f)->getSpecialLon();
688 int specialformat = (*it_f)->getSpecialLLFormat();
690 ar =
new HDFEOS2ArrayGridGeoField(
703 (*it_f)->getNewName(),
706 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
707 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
720 else if(grid_or_swath ==1) {
722 if (
true == multi_dmap) {
723 if ((*it_f)->getRank() !=2)
724 throw InternalErr(__FILE__, __LINE__,
"For the multi-dimmap case, the field rank must be 2.");
725 int dim0size = (dims[0])->getSize();
726 int dim1size = (dims[1])->getSize();
727 int dim0offset = (*it_f)->getLLDim0Offset();
728 int dim1offset = (*it_f)->getLLDim1Offset();
729 int dim0inc = (*it_f)->getLLDim0Inc();
730 int dim1inc = (*it_f)->getLLDim1Inc();
733 fieldname =
"Latitude";
735 fieldname =
"Longitude";
737cerr<<
"hdfdesc: newfieldname is "<<(*it_f)->getNewName() <<endl;
738cerr<<
"hdfdesc: dim0size "<<dim0size <<endl;
739cerr<<
"hdfdesc: dim1size "<<dim1size <<endl;
740cerr<<
"hdfdesc: dim0offset "<<dim0offset <<endl;
741cerr<<
"hdfdesc: dim1offset "<<dim1offset <<endl;
742cerr<<
"hdfdesc: dim0inc "<<dim0inc <<endl;
743cerr<<
"hdfdesc: dim1inc "<<dim1inc <<endl;
746 HDFEOS2ArraySwathGeoMultiDimMapField * ar =
nullptr;
748 ar =
new HDFEOS2ArraySwathGeoMultiDimMapField(
760 (*it_f)->getNewName(),
763 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
764 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
773 if((*it_f)->UseDimMap()) {
776 if(!modis_geofilename.empty()) {
778 if (
false == geofile_has_dimmap) {
779 HDFEOS2ArraySwathGeoDimMapExtraField *ar =
nullptr;
780 ar =
new HDFEOS2ArraySwathGeoDimMapExtraField(
784 (*it_f)->getNewName(),
786 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
787 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
794 HDFEOS2ArraySwathDimMapField * ar =
nullptr;
800 ar =
new HDFEOS2ArraySwathDimMapField(
807 "MODIS_Swath_Type_GEO",
811 (*it_f)->getNewName(),
813 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
814 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
824 HDFEOS2ArraySwathDimMapField * ar =
nullptr;
825 ar =
new HDFEOS2ArraySwathDimMapField(
836 (*it_f)->getNewName(),
838 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
839 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
848 HDFEOS2ArraySwathGeoField * ar =
nullptr;
849 ar =
new HDFEOS2ArraySwathGeoField(
855 (*it_f)->getNewName(),
858 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
859 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
868 throw InternalErr(__FILE__, __LINE__,
"The current type should be either grid or swath");
874 else if(fieldtype == 4) {
876 if((*it_f)->getRank()!=1){
878 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
881 int nelem = ((*it_f)->getCorrectedDimensions()[0])->getSize();
882 HDFEOS2ArrayMissGeoField *ar =
nullptr;
883 ar =
new HDFEOS2ArrayMissGeoField(
886 (*it_f)->getNewName(),
889 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
890 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
898 throw InternalErr(__FILE__, __LINE__,
"Encounter unsupported datatype or The field type should be between 0 and 5. ");
907int read_dds_hdfeos2(DDS & dds,
const string & filename,int32 sdfd, int32 gridfd, int32 swathfd,
const HDFSP::File*spf,HDFEOS2::File*f)
910 BESDEBUG(
"h4",
"Coming to read_dds_hdfeos2 "<<endl);
913 dds.set_dataset_name(basename(filename));
921 if ((basename(filename).size() >=5) && ((basename(filename)).compare(0,5,
"MERRA")==0))
924 if (
true == HDF4RequestHandler::get_enable_special_eos()) {
927 int ret_val = check_special_eosfile(filename,grid_name,sdfd);
938 if (2 == ret_val || 3 == ret_val) {
941 read_dds_special_1d_grid(dds,spf,filename,sdfd,
false);
959 const vector<HDFEOS2::GridDataset *>& grids = f->getGrids();
961 bool onelatlon = f->getOneLatLon();
964 SOType sotype = SOType::DEFAULT_CF_EQU;
967 for (
const auto &gd:grids){
970 ownll = onelatlon?onelatlon:gd->getLatLonFlag();
973 sotype = gd->getScaleType();
975 read_dds_hdfeos2_grid_swath(
976 dds, filename,
static_cast<HDFEOS2::Dataset*
>(gd), 0,ownll,sotype,
false,sdfd,gridfd,swathfd);
979 HDFCFUtil::add_cf_grid_cvs(dds,gd);
987 bool multi_dmap = f->getMultiDimMaps();
991 const vector<HDFEOS2::SwathDataset *>& swaths= f->getSwaths();
992 for (
const auto &swath:swaths) {
995 sotype = swath->getScaleType();
998 read_dds_hdfeos2_grid_swath(
999 dds, filename,
static_cast<HDFEOS2::Dataset*
>(swath), 1,
false,sotype,multi_dmap,sdfd,gridfd,swathfd);
1010 ctype_field_namelist.clear();
1018bool read_dds_hdfhybrid(DDS & dds,
const string & filename,int32 sdfd, int32 fileid,
const HDFSP::File*f)
1022 BESDEBUG(
"h4",
"Coming to read_dds_hdfhybrid "<<endl);
1025 dds.set_dataset_name(basename(filename));
1031 for(
const auto &sdfield:spsds){
1033 read_dds_spfields(dds,filename,sdfd,sdfield,f->
getSPType());
1047 if (
true == HDF4RequestHandler::get_enable_hybrid_vdata()) {
1050 if (
false == vd->getTreatAsAttrFlag()){
1051 for (
const auto &vdf:vd->getFields()) {
1053 read_dds_spvdfields(dds,filename,fileid, vd->getObjRef(),vdf->getNumRec(),vdf);
1068bool read_das_hdfhybrid(DAS & das,
const string & filename,int32 sdfd, int32 fileid,
HDFSP::File**fpptr)
1071 BESDEBUG(
"h4",
"Coming to read_das_hdfhybrid "<<endl);
1082 throw InternalErr(e.
what());
1091 for (
const auto &spfield:spsds) {
1094 AttrTable *at = das.get_table(spfield->getNewName());
1096 at = das.add_table(spfield->getNewName(),
new AttrTable);
1099 bool long_name_flag =
false;
1101 for (
const auto &attr:spfield->getAttributes()) {
1103 if(attr->getName() ==
"long_name") {
1104 long_name_flag =
true;
1109 if(
false == long_name_flag)
1110 at->append_attr(
"long_name",
"String", spfield->getName());
1113 for (
const auto& attr:spfield->getAttributes()) {
1116 if(attr->getType()==DFNT_UCHAR || attr->getType() == DFNT_CHAR){
1119 string tempstring2(attr->getValue().begin(),attr->getValue().end());
1120 auto tempfinalstr= string(tempstring2.c_str());
1128 at->append_attr(attr->getNewName(),
"String" , (attr->getNewName()==
"fullpath")?tempfinalstr:HDFCFUtil::escattr(tempfinalstr));
1130 at->append_attr(attr->getNewName(),
"String" , tempfinalstr);
1133 for (
int loc=0; loc < attr->getCount() ; loc++) {
1143 int32 var_type = spfield->getType();
1157 if (
true == HDF4RequestHandler::get_enable_check_scale_offset_type() && at !=
nullptr)
1164 HDFCFUtil::handle_vdata_attrs_with_desc_key(f,das);
1176void read_dds_use_eos2lib(DDS & dds,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
1180 BESDEBUG(
"h4",
"Coming to read_dds_use_eos2lib" <<endl);
1181 if((basename(filename).size() >=7) && ((basename(filename)).compare(0,7,
"MCD43GF")==0)) {
1182 short cf_simple_type = 1;
1183 read_dds_simple_cf(dds, filename, sdfd, fileid,cf_simple_type);
1187 int ret_value = read_dds_hdfeos2(dds,filename,sdfd,gridfd,swathfd,h4file,eosfile);
1189 BESDEBUG(
"h4",
"ret_value of read_dds_hdfeos2 is "<<ret_value<<endl);
1207 if (0 == ret_value || 5 == ret_value || 4 == ret_value ) {
1208 if (
true == read_dds_hdfsp(dds, filename,sdfd,fileid,h4file))
1212 else if ( 1 == ret_value ) {
1215 if (
true ==read_dds_hdfhybrid(dds,filename,sdfd,fileid,h4file))
1225 if(
true == read_dds_hdfeos2(dds, filename)){
1228 if(
true == read_dds_hdfhybrid(dds,filename))
1233 if(read_dds_hdfsp(dds, filename)){
1240 read_dds(dds, filename);
1245void write_non_ecsmetadata_attrs(
HE2CF& cf) {
1247 cf.set_non_ecsmetadata_attrs();
1252void write_ecsmetadata(DAS& das,
HE2CF& cf,
const string& _meta)
1271 bool suffix_is_number =
true;
1272 vector<string> meta_nonum_names;
1273 vector<string> meta_nonum_data;
1275 string meta = cf.
get_metadata(_meta,suffix_is_number,meta_nonum_names, meta_nonum_data);
1277 if(
""==meta &&
true == suffix_is_number){
1281 BESDEBUG(
"h4",meta << endl);
1283 if (
false == suffix_is_number) {
1287 for (
unsigned int i = 0; i <meta_nonum_names.size(); i++)
1288 parse_ecs_metadata(das,meta_nonum_names[i],meta_nonum_data[i]);
1291 parse_ecs_metadata(das,_meta,meta);
1295void parse_ecs_metadata(DAS &das,
const string & metaname,
const string &metadata) {
1297 AttrTable *at = das.get_table(metaname);
1299 at = das.add_table(metaname,
new AttrTable);
1302 void *buf = hdfeos_string(metadata.c_str());
1305 if (hdfeosparse(&arg) != 0) {
1306 hdfeos_delete_buffer(buf);
1307 throw Error(
"HDF-EOS parse error while processing a " + metadata +
" HDFEOS attribute.");
1310 if (arg.status() ==
false) {
1311 INFO_LOG(
"HDF-EOS parse error while processing a " + metadata +
" HDFEOS attribute. (2)");
1314 << arg.error()->get_error_message() << endl;
1318 hdfeos_delete_buffer(buf);
1322int read_das_hdfeos2(DAS & das,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
1323 bool ecs_metadata,
HDFSP::File**spfpptr,HDFEOS2::File **fpptr)
1326 BESDEBUG(
"h4",
"Coming to read_das_hdfeos2 " << endl);
1338 if((basename(filename).size() >=5) && ((basename(filename)).compare(0,5,
"MERRA")==0)) {
1343 if (
true == HDF4RequestHandler::get_enable_special_eos()) {
1346 int ret_val = check_special_eosfile(filename,grid_name,sdfd);
1352 bool airs_l2_l3_v6 =
false;
1353 bool special_1d_grid =
false;
1356 if (2 == ret_val || 3 == ret_val) {
1366 throw InternalErr(e.
what());
1373 if (spf->Check_update_special(grid_name)==
true){
1375 special_1d_grid =
true;
1378 read_das_special_eos2_core(das,spf,filename,ecs_metadata);
1381 if (grid_name ==
"mod08") {
1382 change_das_mod08_scale_offset(das,spf);
1388 airs_l2_l3_v6 =
true;
1389 spf->Handle_AIRS_L23();
1390 read_das_special_eos2_core(das,spf,filename,ecs_metadata);
1401 if (
true == special_1d_grid ||
true == airs_l2_l3_v6) {
1409 HDFEOS2::File *f =
nullptr;
1413 f= HDFEOS2::File::Read(filename.c_str(),gridfd,swathfd);
1415 catch (HDFEOS2::Exception &e){
1421 if (!e.getFileType()){
1426 throw InternalErr(e.what());
1433 f->Prepare(filename.c_str());
1436 catch (HDFEOS2:: Exception &e) {
1439 throw InternalErr(e.what());
1448 cf.
open(filename,sdfd,fileid);
1455 SOType sotype = SOType::DEFAULT_CF_EQU;
1460 bool tempstrflag =
false;
1465 if (f->getSwaths().empty() ==
false) {
1466 string temp_fname = basename(filename);
1467 string temp_prod_prefix =
"AMSR_E";
1468 if ((temp_fname.size() > temp_prod_prefix.size()) &&
1469 (0 == (temp_fname.compare(0,temp_prod_prefix.size(),temp_prod_prefix)))) {
1476 bool gridname_change_valid_range =
false;
1477 if (1 == f->getGrids().size()) {
1478 string gridname = f->getGrids()[0]->getName();
1479 if (
"VIP_CMG_GRID" == gridname)
1480 gridname_change_valid_range =
true;
1484 bool is_modis_l1b =
false;
1487 for (
int i = 0; i<(
int) f->getSwaths().size(); i++) {
1488 const HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
1489 string sname = swath->getName();
1490 if (
"MODIS_SWATH_Type_L1B" == sname){
1491 is_modis_l1b =
true;
1499 for (
int i = 0; i < (
int) f->getGrids().size(); i++) {
1501 const HDFEOS2::GridDataset* grid = f->getGrids()[i];
1502 string gname = grid->getName();
1503 sotype = grid->getScaleType();
1505 const vector<HDFEOS2::Field*>gfields = grid->getDataFields();
1507 for (
const auto &gf:gfields) {
1509 bool change_fvtype =
false;
1512 string fname = gf->getName();
1515 string newfname = gf->getNewName();
1517 BESDEBUG(
"h4",
"Original field name: " << fname << endl);
1518 BESDEBUG(
"h4",
"Corrected field name: " << newfname << endl);
1521 int fieldtype = gf->getFieldType();
1524 if (fieldtype == 0){
1527 if (gf->haveAddedFillValue()) {
1528 BESDEBUG(
"h4",
"Has an added fill value." << endl);
1529 float addedfillvalue =
1530 gf->getAddedFillValue();
1533 BESDEBUG(
"h4",
"Added fill value = "<<addedfillvalue);
1535 type, addedfillvalue);
1537 string coordinate = gf->getCoordinate();
1538 BESDEBUG(
"h4",
"Coordinate attribute: " << coordinate <<endl);
1539 if (coordinate !=
"")
1545 (
int)(f->getGrids().size()), fieldtype);
1557 if (fieldtype == 1 && (gf->getSpecialLLFormat())==3)
1562 if (fieldtype !=3) {
1563 string tempunits = gf->getUnits();
1565 "fieldtype " << fieldtype
1566 <<
" units" << tempunits
1573 AttrTable *at = das.get_table(newfname);
1576 if (sotype!=SOType::DEFAULT_CF_EQU && at!=
nullptr)
1578 bool has_Key_attr =
false;
1579 AttrTable::Attr_iter it = at->attr_begin();
1580 while (it!=at->attr_end())
1582 if (at->get_name(it)==
"Key")
1584 has_Key_attr =
true;
1590 if ((
false == is_modis_l1b) && (
false == gridname_change_valid_range)&&(
false == has_Key_attr) &&
1591 (
true == HDF4RequestHandler::get_disable_scaleoffset_comp()))
1592 HDFCFUtil::handle_modis_special_attrs_disable_scale_comp(at,basename(filename),
true, newfname,sotype);
1596 bool changedtype = HDFCFUtil::change_data_type(das,sotype,newfname);
1599 if (
true == changedtype)
1600 ctype_field_namelist.push_back(newfname);
1602 HDFCFUtil::handle_modis_special_attrs(at,basename(filename),
true, newfname,sotype,gridname_change_valid_range,changedtype,change_fvtype);
1608 HDFCFUtil::handle_amsr_attrs(at);
1612 if ((
false == change_fvtype) && at !=
nullptr) {
1613 int32 var_type = gf->getType();
1622 if (
true == HDF4RequestHandler::get_enable_check_scale_offset_type() && at!=
nullptr)
1629 HDFCFUtil::add_cf_grid_cv_attrs(das,grid);
1640 for (
int i = 0; i < (
int) f->getSwaths().size(); i++) {
1642 const HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
1646 const vector<HDFEOS2::Field*> geofields = swath->getGeoFields();
1647 vector<HDFEOS2::Field*> all_fields = geofields;
1649 const vector<HDFEOS2::Field*> datafields = swath->getDataFields();
1650 for (
const auto &df:datafields)
1651 all_fields.push_back(df);
1653 auto total_geofields = (
int)(geofields.size());
1655 string gname = swath->getName();
1656 BESDEBUG(
"h4",
"Swath name: " << gname << endl);
1658 sotype = swath->getScaleType();
1661 int field_counter = 0;
1663 for (
const auto &af:all_fields)
1665 bool change_fvtype =
false;
1666 string fname = af->getName();
1667 string newfname = af->getNewName();
1668 BESDEBUG(
"h4",
"Original Field name: " << fname << endl);
1669 BESDEBUG(
"h4",
"Corrected Field name: " << newfname << endl);
1671 int fieldtype = af->getFieldType();
1672 if (fieldtype == 0){
1673 string coordinate = af->getCoordinate();
1674 BESDEBUG(
"h4",
"Coordinate attribute: " << coordinate <<endl);
1675 if (coordinate !=
"")
1682 if(fieldtype >0 && fieldtype !=3){
1683 string tempunits = af->getUnits();
1685 "fieldtype " << fieldtype
1686 <<
" units" << tempunits << endl);
1690 BESDEBUG(
"h4",
"Field Name: " << fname << endl);
1694 if (field_counter >=total_geofields) {
1695 if(af->haveAddedFillValue()){
1696 float addedfillvalue =
1697 af->getAddedFillValue();
1700 BESDEBUG(
"h4",
"Added fill value = "<<addedfillvalue);
1705 (
int)(f->getSwaths().size()), fieldtype);
1707 AttrTable *at = das.get_table(newfname);
1710 if (sotype!=SOType::DEFAULT_CF_EQU && at!=
nullptr)
1713 bool has_Key_attr =
false;
1714 AttrTable::Attr_iter it = at->attr_begin();
1715 while (it!=at->attr_end())
1717 if (at->get_name(it)==
"Key")
1719 has_Key_attr =
true;
1725 if ((
false == is_modis_l1b) && (
false == gridname_change_valid_range) &&(
false == has_Key_attr) &&
1726 (
true == HDF4RequestHandler::get_disable_scaleoffset_comp()))
1727 HDFCFUtil::handle_modis_special_attrs_disable_scale_comp(at,basename(filename),
false,newfname,sotype);
1731 bool changedtype = HDFCFUtil::change_data_type(das,sotype,newfname);
1734 if (
true == changedtype)
1736 ctype_field_namelist.push_back(newfname);
1741 HDFCFUtil::handle_modis_special_attrs(at,basename(filename),
false,newfname,sotype,gridname_change_valid_range,changedtype,change_fvtype);
1747 HDFCFUtil::handle_amsr_attrs(at);
1751 if ((
false == change_fvtype) && at !=
nullptr) {
1752 int32 var_type = af->getType();
1761 if (
true == HDF4RequestHandler::get_enable_check_scale_offset_type() && at !=
nullptr)
1775 if(ecs_metadata ==
true) {
1778 write_ecsmetadata(das,cf,
"CoreMetadata");
1780 write_ecsmetadata(das,cf,
"coremetadata");
1782 write_ecsmetadata(das,cf,
"ArchiveMetadata");
1784 write_ecsmetadata(das,cf,
"archivemetadata");
1786 write_ecsmetadata(das,cf,
"ProductMetadata");
1788 write_ecsmetadata(das,cf,
"productmetadata");
1792 if (
false == tempstrflag) {
1794 if (
false == HDF4RequestHandler::get_disable_structmeta() ) {
1795 write_ecsmetadata(das, cf,
"StructMetadata");
1800 write_non_ecsmetadata_attrs(cf);
1811 if (
true == HDF4RequestHandler::get_enable_swath_grid_attr()) {
1814 for (
int i = 0; i < (
int) f->getGrids().size(); i++) {
1816 HDFEOS2::GridDataset* grid = f->getGrids()[i];
1820 AttrTable*at =
nullptr;
1823 if (grid->getAttributes().empty() ==
false){
1824 at = das.get_table(gname);
1826 at = das.add_table(gname,
new AttrTable);
1831 const vector<HDFEOS2::Attribute *> grid_attrs = grid->getAttributes();
1832 for (
const auto &attr:grid_attrs) {
1834 int attr_type = attr->getType();
1837 if(attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
1838 string tempstring2(attr->getValue().begin(),attr->getValue().end());
1839 auto tempfinalstr= string(tempstring2.c_str());
1840 at->append_attr(attr->getNewName(),
"String" , tempfinalstr);
1845 for (
int loc=0; loc < attr->getCount() ; loc++) {
1856 for (
int i = 0; i < (
int) f->getSwaths().size(); i++) {
1858 const HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
1859 string sname = swath->getName();
1860 AttrTable*at =
nullptr;
1863 if(swath->getAttributes().empty() ==
false) {
1864 at = das.get_table(sname);
1866 at = das.add_table(sname,
new AttrTable);
1870 const vector<HDFEOS2::Attribute *> swath_attrs = swath->getAttributes();
1871 for (
const auto &attr:swath_attrs) {
1873 int attr_type = attr->getType();
1876 if(attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
1877 string tempstring2(attr->getValue().begin(),attr->getValue().end());
1878 auto tempfinalstr= string(tempstring2.c_str());
1879 at->append_attr(attr->getNewName(),
"String" , tempfinalstr);
1882 for (
int loc=0; loc < attr->getCount() ; loc++) {
1901void read_das_use_eos2lib(DAS & das,
const string & filename,
1902 int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
bool ecs_metadata,
1903 HDFSP::File**h4filepptr,HDFEOS2::File**eosfilepptr)
1906 BESDEBUG(
"h4",
"Coming to read_das_use_eos2lib" << endl);
1908 if((basename(filename).size() >=7) && ((basename(filename)).compare(0,7,
"MCD43GF")==0)) {
1909 read_das_simple_cf(das, sdfd, fileid);
1912 int ret_value = read_das_hdfeos2(das,filename,sdfd,fileid, gridfd, swathfd,ecs_metadata,h4filepptr,eosfilepptr);
1914 BESDEBUG(
"h4",
"ret_value of read_das_hdfeos2 is "<<ret_value <<endl);
1930 if (ret_value == 4) {
1931 if(
true == read_das_special_eos2(das, filename,sdfd,fileid,ecs_metadata,h4filepptr))
1935 else if (ret_value == 2 || ret_value == 3) {
1938 else if (ret_value == 1) {
1941 if(
true == read_das_hdfhybrid(das,filename,sdfd,fileid,h4filepptr))
1945 if(
true == read_das_hdfsp(das, filename,sdfd, fileid,h4filepptr))
1953 if(
true == read_das_hdfeos2(das, filename)){
1956 if (
true == read_das_hdfhybrid(das,filename))
1961 if(
true == read_das_hdfsp(das, filename)){
1968 read_das(das, filename);
1975bool read_dds_hdfsp(DDS & dds,
const string & filename,int32 sdfd, int32 fileid,
const HDFSP::File*f)
1978 BESDEBUG(
"h4",
"Coming to read_dds_sp "<<endl);
1979 dds.set_dataset_name(basename(filename));
1985 for (
const auto& spf:spsds){
1990 if (
false == f->
Has_Dim_NoScale_Field() || (0 == spf->getFieldType()) || (
true == spf->IsDimScale())){
1992 read_dds_spfields(dds,filename,sdfd,spf,f->
getSPType());
2003 bool output_vdata_flag =
true;
2004 if (
false == HDF4RequestHandler::get_enable_ceres_vdata() &&
2009 output_vdata_flag =
false;
2011 if(
true == output_vdata_flag) {
2013 if(!vd->getTreatAsAttrFlag()){
2014 for(
const auto &vdf:vd->getFields()) {
2016 read_dds_spvdfields(dds,filename,fileid,vd->getObjRef(),vdf->getNumRec(),vdf);
2031bool read_das_hdfsp(DAS & das,
const string & filename, int32 sdfd, int32 fileid,
HDFSP::File**fpptr)
2034 BESDEBUG(
"h4",
"Coming to read_das_sp "<<endl);
2046 throw InternalErr(e.
what());
2056 throw InternalErr(e.
what());
2063 if (
true == HDF4RequestHandler::get_enable_vgroup_attr()) {
2066 vector<HDFSP::AttrContainer *>vg_container = f->
getVgattrs();
2068 AttrTable *vgattr_at = das.get_table(vgattr_c->getName());
2070 vgattr_at = das.add_table(vgattr_c->getName(),
new AttrTable);
2072 for (
const auto &attr:vgattr_c->getAttributes()) {
2075 if(attr->getType()==DFNT_UCHAR || attr->getType() == DFNT_CHAR){
2076 string tempstring2(attr->getValue().begin(),attr->getValue().end());
2077 string tempfinalstr= string(tempstring2.c_str());
2078 vgattr_at->append_attr(attr->getNewName(),
"String" , tempfinalstr);
2081 for (
int loc=0; loc < attr->getCount() ; loc++) {
2092 string core_metadata =
"";
2093 string archive_metadata =
"";
2094 string struct_metadata =
"";
2105 if((sp_attr->getName().compare(0, 12,
"CoreMetadata" )== 0) ||
2106 (sp_attr->getName().compare(0, 12,
"coremetadata" )== 0)){
2111 string tempstring(sp_attr->getValue().begin(),sp_attr->getValue().end());
2118 core_metadata.append(tempstring);
2120 else if((sp_attr->getName().compare(0, 15,
"ArchiveMetadata" )== 0) ||
2121 (sp_attr->getName().compare(0, 16,
"ArchivedMetadata")==0) ||
2122 (sp_attr->getName().compare(0, 15,
"archivemetadata" )== 0)){
2124 string tempstring(sp_attr->getValue().begin(),sp_attr->getValue().end());
2129 archive_metadata.append(tempstring);
2131 else if((sp_attr->getName().compare(0, 14,
"StructMetadata" )== 0) ||
2132 (sp_attr->getName().compare(0, 14,
"structmetadata" )== 0)){
2134 if (
false == HDF4RequestHandler::get_disable_structmeta()) {
2136 string tempstring(sp_attr->getValue().begin(),sp_attr->getValue().end());
2144 struct_metadata.append(tempstring);
2150 AttrTable *at = das.get_table(
"HDF_GLOBAL");
2152 at = das.add_table(
"HDF_GLOBAL",
new AttrTable);
2155 if (sp_attr->getType()==DFNT_UCHAR || sp_attr->getType() == DFNT_CHAR){
2157 string tempstring2(sp_attr->getValue().begin(),sp_attr->getValue().end());
2158 auto tempfinalstr= string(tempstring2.c_str());
2159 at->append_attr(sp_attr->getNewName(),
"String" , tempfinalstr);
2163 for (
int loc=0; loc < sp_attr->getCount() ; loc++) {
2164 string print_rep =
HDFCFUtil::print_attr(sp_attr->getType(), loc, (
void*) &(sp_attr->getValue()[0]));
2175 if(core_metadata.size() > 0){
2176 AttrTable *at = das.get_table(
"CoreMetadata");
2178 at = das.add_table(
"CoreMetadata",
new AttrTable);
2180 void *buf = hdfeos_string(core_metadata.c_str());
2183 if (hdfeosparse(&arg) != 0) {
2184 hdfeos_delete_buffer(buf);
2185 throw Error(
"Parse error while processing a CoreMetadata attribute.");
2189 if (arg.status() ==
false) {
2190 ERROR_LOG(
"Parse error while processing a CoreMetadata attribute. (2)");
2196 hdfeos_delete_buffer(buf);
2200 if(archive_metadata.size() > 0){
2201 AttrTable *at = das.get_table(
"ArchiveMetadata");
2203 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
2205 void *buf = hdfeos_string(archive_metadata.c_str());
2207 if (hdfeosparse(&arg) != 0){
2208 hdfeos_delete_buffer(buf);
2209 throw Error(
"Parse error while processing an ArchiveMetadata attribute.");
2213 if (arg.status() ==
false) {
2214 ERROR_LOG(
"Parse error while processing an ArchiveMetadata attribute. (2) ");
2220 hdfeos_delete_buffer(buf);
2224 if(struct_metadata.size() > 0){
2225 AttrTable *at = das.get_table(
"StructMetadata");
2227 at = das.add_table(
"StructMetadata",
new AttrTable);
2229 void *buf = hdfeos_string(struct_metadata.c_str());
2231 if (hdfeosparse(&arg) != 0){
2232 hdfeos_delete_buffer(buf);
2233 throw Error(
"Parse error while processing a StructMetadata attribute.");
2236 if (arg.status() ==
false) {
2237 ERROR_LOG(
"Parse error while processing a StructMetadata attribute. (2)");
2242 if (arg.status() ==
false) {
2243 (*BESLog::TheLog())<<
"Parse error while processing a StructMetadata attribute. (2)" << endl
2244 << arg.error()->get_error_message() << endl;
2248 hdfeos_delete_buffer(buf);
2257 bool global_slope_flag =
false;
2258 float intercept = 0.;
2259 bool global_intercept_flag =
false;
2263 HDFCFUtil::check_obpg_global_attrs(f,scaling,slope,global_slope_flag,intercept,global_intercept_flag);
2268 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
2275 ((*it_g)->getFieldType() !=0)&&
2276 ((*it_g)->IsDimScale() ==
false))
2280 if (OTHERHDF == f->
getSPType() &&
true == (*it_g)->IsDimNoScale())
2283 AttrTable *at = das.get_table((*it_g)->getNewName());
2285 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
2288 bool long_name_flag =
false;
2290 for (
const auto& attr:(*it_g)->getAttributes()) {
2291 if(attr->getName() ==
"long_name") {
2292 long_name_flag =
true;
2297 if(
false == long_name_flag) {
2299 if((*it_g)->getFieldType() == 1)
2300 at->append_attr(
"standard_name",
"String",
"latitude");
2301 else if ((*it_g)->getFieldType() == 2) {
2302 at->append_attr(
"standard_name",
"String",
"longitude");
2308 if((*it_g)->getFieldType() == 1) {
2309 at->append_attr(
"long_name",
"String",
"latitude");
2310 at->append_attr(
"standard_name",
"String",
"latitude");
2313 else if ((*it_g)->getFieldType() == 2) {
2314 at->append_attr(
"long_name",
"String",
"longitude");
2315 at->append_attr(
"standard_name",
"String",
"longitude");
2320 at->append_attr(
"long_name",
"String", (*it_g)->getName());
2326 HDFCFUtil::add_obpg_special_attrs(f,das,*it_g,scaling,slope,global_slope_flag,intercept,global_intercept_flag);
2329 for (
const auto &attr:(*it_g)->getAttributes()) {
2332 if(attr->getType()==DFNT_UCHAR || attr->getType() == DFNT_CHAR){
2333 string tempstring2(attr->getValue().begin(),attr->getValue().end());
2334 string tempfinalstr= string(tempstring2.c_str());
2335 at->append_attr(attr->getNewName(),
"String" ,tempfinalstr);
2338 for (
int loc=0; loc < attr->getCount() ; loc++) {
2352 bool has_dim_info =
true;
2354 if ((*it_g)->getType() == DFNT_CHAR) {
2355 if ((*it_g)->getRank() >1 && (*it_g)->getDimInfo().size() >1)
2356 it_end = (*it_g)->getDimInfo().begin()+(*it_g)->getDimInfo().size() -1;
2358 has_dim_info =
false;
2361 if(
true == has_dim_info) {
2367 string attr_container_name = (*it_g)->getNewName() + (*i)->getName();
2368 AttrTable *dim_at = das.get_table(attr_container_name);
2370 dim_at = das.add_table(attr_container_name,
new AttrTable);
2372 for (
const auto &attr:(*i)->getAttributes()) {
2375 if (attr->getType()==DFNT_UCHAR || attr->getType() == DFNT_CHAR){
2376 string tempstring2(attr->getValue().begin(),attr->getValue().end());
2377 string tempfinalstr= string(tempstring2.c_str());
2378 dim_at->append_attr(attr->getNewName(),
"String" , tempfinalstr);
2381 for (
int loc=0; loc < attr->getCount() ; loc++) {
2393 if ((*it_g)->getFieldType() == 1){
2395 at->del_attr(
"units");
2396 at->append_attr(
"units",
"String",(*it_g)->getUnits());
2398 at->del_attr(
"valid_range");
2402 if ((*it_g)->getFieldType() == 2){
2403 at->del_attr(
"units");
2404 at->append_attr(
"units",
"String",(*it_g)->getUnits());
2406 at->del_attr(
"valid_range");
2412 if ((*it_g)->getFieldType() == 4){
2413 at->del_attr(
"units");
2414 at->append_attr(
"units",
"String",(*it_g)->getUnits());
2418 if ((*it_g)->getFieldType() == 0){
2419 at->del_attr(
"coordinates");
2423 string coordinate = (*it_g)->getCoordinate();
2424 if (coordinate !=
"")
2425 at->append_attr(
"coordinates",
"String", coordinate);
2432 HDFCFUtil::handle_otherhdf_special_attrs(f,das);
2435 HDFCFUtil::add_missing_cf_attrs(f,das);
2439 for (it_g = spsds.begin(); it_g != spsds.end(); it_g++){
2441 AttrTable *at = das.get_table((*it_g)->getNewName());
2442 if (at !=
nullptr) {
2443 int32 var_type = (*it_g)->getType();
2457 if (
true == HDF4RequestHandler::get_enable_check_scale_offset_type() && at !=
nullptr)
2462 HDFCFUtil::handle_merra_ceres_attrs_with_bes_keys(f,das,filename);
2468 HDFCFUtil::handle_vdata_attrs_with_desc_key(f,das);
2485bool read_das_special_eos2(DAS &das,
const string& filename,int32 sdfd,int32 fileid,
bool ecs_metadata,
HDFSP::File**fpptr) {
2487 BESDEBUG(
"h4",
"Coming to read_das_special_eos2 " << endl);
2500 throw InternalErr(e.
what());
2510 throw InternalErr(e.
what());
2516 read_das_special_eos2_core(das, f, filename,ecs_metadata);
2528bool read_das_special_eos2_core(DAS &das,
const HDFSP::File* f,
const string& filename,
bool ecs_metadata) {
2530 BESDEBUG(
"h4",
"Coming to read_das_special_eos2_core "<<endl);
2533 string core_metadata =
"";
2534 string archive_metadata =
"";
2535 string struct_metadata =
"";
2544 if ((attr->getName().compare(0, 12,
"CoreMetadata" )== 0) ||
2545 (attr->getName().compare(0, 12,
"coremetadata" )== 0)){
2547 if (ecs_metadata ==
true) {
2552 string tempstring(attr->getValue().begin(),attr->getValue().end());
2553 core_metadata.append(tempstring);
2556 else if((attr->getName().compare(0, 15,
"ArchiveMetadata" )== 0) ||
2557 (attr->getName().compare(0, 16,
"ArchivedMetadata")==0) ||
2558 (attr->getName().compare(0, 15,
"archivemetadata" )== 0)){
2559 if (ecs_metadata ==
true) {
2560 string tempstring(attr->getValue().begin(),attr->getValue().end());
2561 archive_metadata.append(tempstring);
2564 else if((attr->getName().compare(0, 14,
"StructMetadata" )== 0) ||
2565 (attr->getName().compare(0, 14,
"structmetadata" )== 0))
2569 AttrTable *at = das.get_table(
"HDF_GLOBAL");
2571 at = das.add_table(
"HDF_GLOBAL",
new AttrTable);
2574 if(attr->getType()==DFNT_UCHAR || attr->getType() == DFNT_CHAR){
2575 string tempstring2(attr->getValue().begin(),attr->getValue().end());
2576 auto tempfinalstr= string(tempstring2.c_str());
2577 at->append_attr(attr->getNewName(),
"String" , tempfinalstr);
2581 for (
int loc=0; loc < attr->getCount() ; loc++) {
2591 if (ecs_metadata ==
true) {
2594 if (core_metadata.size() > 0){
2595 AttrTable *at = das.get_table(
"CoreMetadata");
2597 at = das.add_table(
"CoreMetadata",
new AttrTable);
2599 void *buf = hdfeos_string(core_metadata.c_str());
2602 if (hdfeosparse(&arg) != 0) {
2603 hdfeos_delete_buffer(buf);
2604 throw Error(
"Parse error while processing a CoreMetadata attribute.");
2608 if (arg.status() ==
false) {
2609 ERROR_LOG(
"Parse error while processing a CoreMetadata attribute. (2)");
2612 << arg.error()->get_error_message() << endl;
2616 hdfeos_delete_buffer(buf);
2621 if (archive_metadata.size() > 0){
2622 AttrTable *at = das.get_table(
"ArchiveMetadata");
2624 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
2626 void *buf = hdfeos_string(archive_metadata.c_str());
2628 if (hdfeosparse(&arg) != 0) {
2629 hdfeos_delete_buffer(buf);
2630 throw Error(
"Parse error while processing an ArchiveMetadata attribute.");
2634 if (arg.status() ==
false)
2635 ERROR_LOG(
"Parse error while processing an ArchiveMetadata attribute. (2)");
2637 hdfeos_delete_buffer(buf);
2644 for (
const auto &sdf:spsds){
2646 if(sdf->getFieldType() != 0){
2648 AttrTable *at = das.get_table(sdf->getNewName());
2650 at = das.add_table(sdf->getNewName(),
new AttrTable);
2652 string tempunits = sdf->getUnits();
2653 if(at->simple_find(
"units")== at->attr_end() && tempunits!=
"")
2654 at->append_attr(
"units",
"String" ,tempunits);
2655 if(sdf->getFieldType() == 1){
2656 if(at->simple_find(
"long_name")== at->attr_end())
2657 at->append_attr(
"long_name",
"String",
"Latitude");
2659 else if(sdf->getFieldType() == 2) {
2660 if(at->simple_find(
"long_name")== at->attr_end())
2661 at->append_attr(
"long_name",
"String",
"Longitude");
2666 AttrTable *at = das.get_table(sdf->getNewName());
2668 at = das.add_table(sdf->getNewName(),
new AttrTable);
2669 string tempcoors = sdf->getCoordinate();
2673 at->del_attr(
"coordinates");
2674 at->append_attr(
"coordinates",
"String",tempcoors);
2679 if (sdf->getAttributes().empty())
2682 AttrTable *at = das.get_table(sdf->getNewName());
2684 at = das.add_table(sdf->getNewName(),
new AttrTable);
2687 for (
const auto &attr:sdf->getAttributes()) {
2690 if (attr->getType()==DFNT_UCHAR || attr->getType() == DFNT_CHAR){
2691 string tempstring2(attr->getValue().begin(),attr->getValue().end());
2692 auto tempfinalstr= string(tempstring2.c_str());
2693 at->append_attr(attr->getNewName(),
"String" ,tempfinalstr);
2696 for (
int loc=0; loc < attr->getCount() ; loc++) {
2705 HDFCFUtil::map_eos2_objects_attrs(das,filename);
2712void change_das_mod08_scale_offset(DAS &das,
const HDFSP::File *f) {
2718 for (
const auto &sdf:spsds) {
2719 if (sdf->getFieldType() == 0){
2720 AttrTable *at = das.get_table(sdf->getNewName());
2722 at = das.add_table(sdf->getNewName(),
new AttrTable);
2725 string add_offset_type;
2728 string add_offset_value=
"0";
2729 double orig_offset_value = 0;
2730 bool add_offset_modify =
false;
2736 AttrTable::Attr_iter it = at->attr_begin();
2737 while (it!=at->attr_end())
2739 if (at->get_name(it)==
"add_offset")
2741 add_offset_value = (*at->get_attr_vector(it)->begin());
2742 orig_offset_value = atof(add_offset_value.c_str());
2743 add_offset_type = at->get_type(it);
2744 if(add_offset_value ==
"0.0" || orig_offset_value == 0)
2745 add_offset_modify =
false;
2747 add_offset_modify =
true;
2755 if (
true == add_offset_modify) {
2758 string scale_factor_type;
2761 string scale_factor_value=
"";
2762 double orig_scale_value = 1;
2764 it = at->attr_begin();
2765 while (it!=at->attr_end())
2767 if(at->get_name(it)==
"scale_factor")
2769 scale_factor_value = (*at->get_attr_vector(it)->begin());
2770 orig_scale_value = atof(scale_factor_value.c_str());
2771 scale_factor_type = at->get_type(it);
2776 if (scale_factor_value.size() !=0) {
2777 double new_offset_value = -1 * orig_scale_value*orig_offset_value;
2779 at->del_attr(
"add_offset");
2788bool read_dds_special_1d_grid(DDS &dds,
const HDFSP::File* spf,
const string& filename, int32 sdid,
bool check_cache) {
2790 BESDEBUG(
"h4",
"Coming to read_dds_special_1d_grid "<<endl);
2791 bool dds_cache =
false;
2792 size_t total_bytes_dds_cache = 0;
2795 if (
true == check_cache) {
2797 total_bytes_dds_cache = HDFCFUtil::obtain_dds_cache_size(spf);
2798 BESDEBUG(
"h4",
"Total DDS cache file size is "<< total_bytes_dds_cache<<endl);
2799 if(total_bytes_dds_cache !=0)
2804 SPType sptype = OTHERHDF;
2805 const vector<HDFSP::SDField *>& spsds = spf->
getSD()->
getFields();
2808 for (
const auto &spsdsf:spsds) {
2810 BaseType *bt=
nullptr;
2811 switch(spsdsf->getType()) {
2812#define HANDLE_CASE(tid, type) \
2814 bt = new (type)(spsdsf->getNewName(),filename); \
2818 HANDLE_CASE(DFNT_CHAR,
HDFStr)
2819#ifndef SIGNED_BYTE_TO_INT32
2820 HANDLE_CASE(DFNT_INT8,
HDFByte)
2824 HANDLE_CASE(DFNT_UINT8,
HDFByte)
2829 HANDLE_CASE(DFNT_UCHAR8,
HDFByte)
2831 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
2838 const vector<HDFSP::Dimension*>& dims= spsdsf->getDimensions();
2843 if(DFNT_CHAR == spsdsf->getType()) {
2844 if(1 == spsdsf->getRank()) {
2849 spsdsf->getFieldRef(),
2852 spsdsf->getNewName(),
2858 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
2860 dds.add_var(sca_str);
2870 spsdsf->getRank() -1 ,
2874 spsdsf->getFieldRef(),
2877 spsdsf->getNewName(),
2883 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStrField instance.");
2886 for(it_d = dims.begin(); it_d != dims.begin()+dims.size()-1; it_d++)
2887 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
2898 if(spsdsf->getFieldType()!= 4) {
2903 vector<int32>dimsizes;
2905 dimsizes.resize(spsdsf->getRank());
2906 for(
int i = 0; i <spsdsf->getRank();i++)
2907 dimsizes[i] = (dims[i])->getSize();
2912 spsdsf->getFieldRef(),
2917 spsdsf->getNewName(),
2922 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFSPArray_RealField instance.");
2924 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
2925 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
2931 if(spsdsf->getRank()!=1){
2933 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
2935 int nelem = (spsdsf->getDimensions()[0])->getSize();
2943 spsdsf->getNewName(),
2948 throw InternalErr(__FILE__,__LINE__,
2949 "Unable to allocate the HDFSPArrayMissGeoField instance.");
2953 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
2954 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
2965 if (
true == dds_cache) {
2968 string md_cache_dir;
2969 string key =
"H4.Cache.metadata.path";
2973 if (
true == found) {
2976 string base_file_name = basename(filename);
2977 string dds_filename = md_cache_dir +
"/"+base_file_name +
"_dds";
2980 FILE* dds_file =fopen(dds_filename.c_str(),
"wb");
2981 if(
nullptr == dds_file) {
2982 string msg =
"Cannot create the cache file. " + dds_filename + get_errno();
2983 throw InternalErr(__FILE__,__LINE__,msg);
2985 int fd = fileno(dds_file);
2986 struct flock *l= lock(F_WRLCK);
2987 if (fcntl(fd, F_SETLKW, l) == -1) {
2989 string msg =
"Cannot hold the write lock for dds cached file "+ dds_filename;
2990 throw InternalErr (__FILE__, __LINE__,msg);
2994 HDFCFUtil::write_sp_sds_dds_cache(spf,dds_file,total_bytes_dds_cache,dds_filename);
2997 if (fcntl(fd, F_SETLK, lock(F_UNLCK)) == -1) {
2999 string msg =
"Cannot release the write lock for dds cached file "+ dds_filename;
3000 throw InternalErr (__FILE__, __LINE__,msg);
3004 throw InternalErr(__FILE__,__LINE__,
"Fail to generate a dds cache file.");
3006 if (fcntl(fd, F_SETLK, lock(F_UNLCK)) == -1) {
3008 string msg =
"Cannot release the write lock for dds cached file "+ dds_filename;
3009 throw InternalErr (__FILE__, __LINE__,msg);
3016 throw InternalErr (__FILE__, __LINE__,
3017 "DDS/DAS metadata cache path cannot be found when 'H4.EnableMetaDataCacheFile' key is set to be true.");
3026void read_dds_spfields(DDS &dds,
const string& filename,
const int sdfd,
const HDFSP::SDField *spsds, SPType sptype) {
3028 BESDEBUG(
"h4",
"Coming to read_dds_spfields "<<endl);
3031 if(OTHERHDF == sptype && (
true == spsds->
IsDimNoScale()))
3034 BaseType *bt=
nullptr;
3037#define HANDLE_CASE(tid, type) \
3039 bt = new (type)(spsds->getNewName(),filename); \
3043 HANDLE_CASE(DFNT_CHAR,
HDFStr)
3044#ifndef SIGNED_BYTE_TO_INT32
3045 HANDLE_CASE(DFNT_INT8,
HDFByte)
3051 HANDLE_CASE(DFNT_UINT8,
HDFByte)
3056 HANDLE_CASE(DFNT_UCHAR,
HDFByte)
3058 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
3061 int fieldtype = spsds->getFieldType();
3069 if(DFNT_CHAR == spsds->
getType()) {
3079 spsds->getFieldRef(),
3088 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
3090 dds.add_var(sca_str);
3103 spsds->getFieldRef(),
3112 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStrField instance.");
3115 for(it_d = dims.begin(); it_d != dims.begin()+dims.size()-1; it_d++)
3116 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3125 else if(fieldtype == 0 || fieldtype == 3 ) {
3130 vector<int32>dimsizes;
3131 dimsizes.resize(spsds->
getRank());
3132 for(
int i = 0; i <spsds->
getRank();i++)
3133 dimsizes[i] = (dims[i])->getSize();
3139 spsds->getFieldRef(),
3149 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFSPArray_RealField instance.");
3152 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3153 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3160 else if(fieldtype == 1 || fieldtype == 2) {
3162 if (sptype == MODISARNSS || sptype == TRMML2_V7) {
3166 vector<int32>dimsizes;
3168 dimsizes.resize(spsds->
getRank());
3169 for(
int i = 0; i <spsds->
getRank();i++)
3170 dimsizes[i] = (dims[i])->getSize();
3176 spsds->getFieldRef(),
3186 throw InternalErr(__FILE__,__LINE__,
3187 "Unable to allocate the HDFSPArray_RealField instance.");
3191 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3192 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3207 spsds->getFieldRef(),
3217 throw InternalErr(__FILE__,__LINE__,
3218 "Unable to allocate the HDFSPArray_RealField instance.");
3221 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3222 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3230 else if(fieldtype == 4) {
3233 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
3248 throw InternalErr(__FILE__,__LINE__,
3249 "Unable to allocate the HDFSPArrayMissGeoField instance.");
3253 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3254 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3261 else if(fieldtype == 6) {
3265 throw InternalErr(__FILE__, __LINE__,
"The rank of added coordinate variable must be 1");
3281 throw InternalErr(__FILE__,__LINE__,
3282 "Unable to allocate the HDFSPArrayAddCVField instance.");
3286 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3287 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3294 throw InternalErr(__FILE__, __LINE__,
"The field type should be one of 0,1,2,3,4 or 6.");
3302void read_dds_spvdfields(DDS &dds,
const string & filename,
const int fileid,int32 objref,int32 numrec,
HDFSP::VDField *spvd) {
3304 BESDEBUG(
"h4",
"Coming to read_dds_spvdfields "<<endl);
3307 BaseType *bt=
nullptr;
3309#define HANDLE_CASE(tid, type) \
3311 bt = new (type)(spvd->getNewName(),filename); \
3315 HANDLE_CASE(DFNT_CHAR8,
HDFStr)
3316#ifndef SIGNED_BYTE_TO_INT32
3317 HANDLE_CASE(DFNT_INT8,
HDFByte)
3321 HANDLE_CASE(DFNT_UINT8,
HDFByte)
3326 HANDLE_CASE(DFNT_UCHAR8,
HDFByte)
3330 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
3337 if(DFNT_CHAR == spvd->
getType()) {
3358 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
3360 dds.add_var(sca_str);
3384 throw InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStrField instance.");
3387 string dimname0 =
"VDFDim0_"+spvd->
getNewName();
3388 ar->append_dim(numrec, dimname0);
3413 string dimname1 =
"VDFDim0_"+spvd->
getNewName();
3415 string dimname2 =
"VDFDim1_"+spvd->
getNewName();
3417 ar->append_dim(numrec,dimname1);
3421 ar->append_dim(numrec,dimname1);
3433int check_special_eosfile(
const string & filename,
string& grid_name,int32 sdfd) {
3437 int32 n_sd_attrs = 0;
3438 bool is_eos =
false;
3442 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
3443 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
3446 char attr_name[H4_MAX_NC_NAME];
3447 int32 attr_type = -1;
3448 int32 attr_count = -1;
3449 char structmdname[] =
"StructMetadata.0";
3452 for (
int attr_index = 0; attr_index < n_sd_attrs;attr_index++) {
3453 if(SDattrinfo(sdfd,attr_index,attr_name,&attr_type,&attr_count) == FAIL) {
3454 throw InternalErr (__FILE__,__LINE__,
"SDattrinfo failed ");
3457 if(strcmp(attr_name,structmdname)==0) {
3463 if(
true == is_eos) {
3467 int32 dim_sizes[H4_MAX_VAR_DIMS];
3468 int32 sds_dtype = 0;
3469 int32 n_sds_attrs = 0;
3470 char sds_name[H4_MAX_NC_NAME];
3471 char xdim_name[] =
"XDim";
3472 char ydim_name[] =
"YDim";
3474 string temp_grid_name1;
3475 string temp_grid_name2;
3476 bool xdim_is_cv_flag =
false;
3477 bool ydim_is_cv_flag =
false;
3481 for (sds_index = 0; sds_index < n_sds; sds_index++) {
3483 sds_id = SDselect (sdfd, sds_index);
3484 if (sds_id == FAIL) {
3485 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3489 int status = SDgetinfo (sds_id, sds_name, &sds_rank, dim_sizes,
3490 &sds_dtype, &n_sds_attrs);
3491 if (status == FAIL) {
3492 SDendaccess(sds_id);
3493 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3496 if (1 == sds_rank) {
3499 if(strcmp(sds_name,xdim_name) == 0) {
3500 int32 sds_dimid = SDgetdimid(sds_id,0);
3501 if(sds_dimid == FAIL) {
3502 SDendaccess(sds_id);
3503 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3505 char dim_name[H4_MAX_NC_NAME];
3508 int32 num_dim_attrs = 0;
3509 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3510 SDendaccess(sds_id);
3511 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3516 string tempdimname(dim_name);
3517 if(tempdimname.size() >=5) {
3518 if(tempdimname.compare(0,5,
"XDim:") == 0) {
3521 temp_grid_name1 = tempdimname.substr(5);
3522 xdim_is_cv_flag =
true;
3526 else if(
"XDim" == tempdimname)
3527 xdim_is_cv_flag =
true;
3532 if(strcmp(sds_name,ydim_name) == 0) {
3534 int32 sds_dimid = SDgetdimid(sds_id,0);
3535 if(sds_dimid == FAIL) {
3536 SDendaccess (sds_id);
3537 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3539 char dim_name[H4_MAX_NC_NAME];
3542 int32 num_dim_attrs = 0;
3543 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3544 SDendaccess(sds_id);
3545 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3550 string tempdimname(dim_name);
3551 if(tempdimname.size() >=5) {
3552 if(tempdimname.compare(0,5,
"YDim:") == 0) {
3554 temp_grid_name2 = tempdimname.substr(5);
3555 ydim_is_cv_flag =
true;
3558 else if (
"YDim" == tempdimname)
3559 ydim_is_cv_flag =
true;
3564 SDendaccess(sds_id);
3565 if((
true == xdim_is_cv_flag) && (
true == ydim_is_cv_flag ))
3571 if ((temp_grid_name1 == temp_grid_name2) && (
true == xdim_is_cv_flag) && (
true == ydim_is_cv_flag)) {
3572 grid_name = temp_grid_name1;
3580 else if((basename(filename).size() >8) && (basename(filename).compare(0,4,
"AIRS") == 0)
3581 && ((basename(filename).find(
".L3.")!=string::npos) || (basename(filename).find(
".L2.")!=string::npos))){
3583 bool has_dimscale =
false;
3586 for (sds_index = 0; sds_index < n_sds; sds_index++) {
3588 sds_id = SDselect (sdfd, sds_index);
3589 if (sds_id == FAIL) {
3590 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3594 int status = SDgetinfo (sds_id, sds_name, &sds_rank, dim_sizes,
3595 &sds_dtype, &n_sds_attrs);
3596 if (status == FAIL) {
3597 SDendaccess(sds_id);
3598 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3601 for (
int dim_index = 0; dim_index<sds_rank; dim_index++) {
3603 int32 sds_dimid = SDgetdimid(sds_id,dim_index);
3604 if(sds_dimid == FAIL) {
3605 SDendaccess(sds_id);
3606 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3609 char dim_name[H4_MAX_NC_NAME];
3612 int32 num_dim_attrs = 0;
3613 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3614 SDendaccess(sds_id);
3615 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3619 has_dimscale =
true;
3623 SDendaccess(sds_id);
3624 if(
true == has_dimscale)
3629 if (
true == has_dimscale)
3642 bool has_dimscale =
true;
3643 bool is_grid =
false;
3646 for (sds_index = 0; sds_index < n_sds; sds_index++) {
3648 sds_id = SDselect (sdid, sds_index);
3649 if (sds_id == FAIL) {
3651 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3655 int status = SDgetinfo (sds_id, sds_name, &sds_rank, dim_sizes,
3656 &sds_dtype, &n_sds_attrs);
3657 if (status == FAIL) {
3658 SDendaccess(sds_id);
3660 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3664 for (
int dim_index = 0; dim_index<sds_rank; dim_index++) {
3666 int32 sds_dimid = SDgetdimid(sds_id,dim_index);
3667 if(sds_dimid == FAIL) {
3668 SDendaccess(sds_id);
3670 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3672 char dim_name[H4_MAX_NC_NAME];
3675 int32 num_dim_attrs = 0;
3676 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3677 SDendaccess(sds_id);
3679 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3683 has_dimscale =
false;
3687 SDendaccess(sds_id);
3689 if (
true == has_dimscale)
3700void read_das_sds(DAS & das,
const string & filename,int32 sdfd,
bool ecs_metadata,
HDFSP::File**h4fileptr) {
3705 spf->Handle_AIRS_L23();
3706 read_das_special_eos2_core(das,spf,filename,ecs_metadata);
3712 throw InternalErr(e.
what());
3721void read_dds_sds(DDS &dds,
const string & filename,int32 sdfd,
HDFSP::File*h4file,
bool dds_setcache) {
3724 dds.set_dataset_name(basename(filename));
3725 read_dds_special_1d_grid(dds,h4file,filename,sdfd,dds_setcache);
3730void read_das_simple_cf(DAS &das, int32 sdfd, int32 fileid) {
3733 int32 n_sd_attrs = 0;
3736 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
3737 close_vgroup_fileids(fileid,sdfd,-1);
3738 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
3741 AttrTable *at = das.add_table(
"HDF_GLOBAL",
new AttrTable);
3743 for (
int attr_index = 0; attr_index < n_sd_attrs;attr_index++) {
3745 char attr_name[H4_MAX_NC_NAME];
3746 int32 attr_type = -1;
3747 int32 attr_count = -1;
3749 if (SDattrinfo(sdfd,attr_index,attr_name,&attr_type,&attr_count) == FAIL) {
3750 close_vgroup_fileids(fileid,sdfd,-1);
3751 throw InternalErr (__FILE__,__LINE__,
"SDattrinfo failed ");
3754 vector<char> attr_value;
3755 attr_value.resize(attr_count * DFKNTsize(attr_type));
3756 if (SDreadattr (sdfd, attr_index, attr_value.data()) == -1) {
3757 close_vgroup_fileids(fileid,sdfd,-1);
3758 throw InternalErr(__FILE__,__LINE__,
"SDreadattr failed ");
3761 string das_attrname(attr_name);
3763 if (attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
3764 string tempstring(attr_value.begin(),attr_value.end());
3765 auto tempfinalstr= string(tempstring.c_str());
3770 for (
int loc=0; loc < attr_count ; loc++) {
3779 for (
int i = 0; i <n_sds; i++) {
3781 uint16 name_len = 0;
3782 vector<char> sds_name;
3784 int32 sds_id = SDselect(sdfd,i);
3785 if (sds_id == FAIL) {
3786 close_vgroup_fileids(fileid,sdfd,-1);
3787 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3790 if (SDgetnamelen(sds_id, &name_len) == FAIL) {
3791 SDendaccess(sds_id);
3792 close_vgroup_fileids(fileid,sdfd,-1);
3793 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS name length.");
3796 sds_name.resize(name_len+1);
3798 int32 n_sds_attrs = 0;
3801 if (FAIL == SDgetinfo (sds_id, sds_name.data(),
nullptr,
nullptr,
nullptr, &n_sds_attrs)) {
3802 SDendaccess(sds_id);
3803 close_vgroup_fileids(fileid,sdfd,-1);
3804 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS ID.");
3807 string sds_name_str(sds_name.begin(),sds_name.end()-1);
3812 AttrTable *at_sds = das.get_table(sds_name_str);
3814 at_sds = das.add_table(sds_name_str,
new AttrTable);
3816 char attr_name[H4_MAX_NC_NAME];
3817 for (
int attrindex = 0; attrindex < n_sds_attrs; attrindex++) {
3819 int32 sds_attr_type = 0;
3820 int32 attr_value_count = 0;
3821 if (FAIL==SDattrinfo (sds_id, attrindex, attr_name, &sds_attr_type, &attr_value_count)) {
3822 SDendaccess(sds_id);
3823 close_vgroup_fileids(fileid,sdfd,-1);
3824 throw InternalErr(__FILE__,__LINE__,
"SDattrinfo failed ");
3827 vector<char> attr_value;
3828 attr_value.resize(attr_value_count * DFKNTsize(sds_attr_type));
3829 if (SDreadattr (sds_id, attrindex, attr_value.data()) == -1) {
3830 SDendaccess(sds_id);
3831 close_vgroup_fileids(fileid,sdfd,-1);
3832 throw InternalErr(__FILE__,__LINE__,
"SDreadattr failed ");
3835 string das_attrname (attr_name);
3837 if (sds_attr_type==DFNT_UCHAR || sds_attr_type == DFNT_CHAR){
3838 string tempstring(attr_value.begin(),attr_value.end());
3839 auto tempfinalstr= string(tempstring.c_str());
3844 for (
int loc=0; loc < attr_value_count ; loc++) {
3850 SDendaccess(sds_id);
3854void obtain_cf_simple_lat_lon(int32 sdfd,int32 fileid,int32 n_sds,
string &lat_name,
string &lon_name,
int &lat_size,
int &lon_size) {
3856 bool find_lat =
false;
3857 bool find_lon =
false;
3859 for (
int i = 0; i <n_sds; i++) {
3861 uint16 name_len = 0;
3862 vector<char> sds_name;
3864 int32 sds_id = SDselect(sdfd,i);
3865 if (sds_id == FAIL) {
3866 close_vgroup_fileids(fileid,sdfd,-1);
3867 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3870 if (SDgetnamelen(sds_id, &name_len) == FAIL) {
3871 SDendaccess(sds_id);
3872 close_vgroup_fileids(fileid,sdfd,-1);
3873 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS name length.");
3876 sds_name.resize(name_len+1);
3879 int32 dim_sizes[H4_MAX_VAR_DIMS];
3880 int32 num_attrs = 0;
3883 if (FAIL == SDgetinfo (sds_id, sds_name.data(), &sds_rank, dim_sizes,
nullptr, &num_attrs)) {
3884 SDendaccess(sds_id);
3885 close_vgroup_fileids(fileid,sdfd,-1);
3886 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS ID.");
3890 if (sds_rank == 1) {
3892 char attr_name[H4_MAX_NC_NAME];
3894 for (
int attrindex = 0; attrindex < num_attrs; attrindex++) {
3896 int32 sds_attr_type = 0;
3897 int32 attr_value_count = 0;
3898 if (FAIL==SDattrinfo (sds_id, attrindex, attr_name, &sds_attr_type, &attr_value_count)) {
3899 SDendaccess(sds_id);
3900 close_vgroup_fileids(fileid,sdfd,-1);
3901 throw InternalErr(__FILE__,__LINE__,
"SDattrinfo failed ");
3904 string attrname_str(attr_name);
3905 if(attrname_str ==
"units" && sds_attr_type == DFNT_CHAR) {
3906 vector<char> attr_value;
3907 attr_value.resize(attr_value_count * DFKNTsize(sds_attr_type));
3908 if (SDreadattr (sds_id, attrindex, attr_value.data()) == -1) {
3909 SDendaccess(sds_id);
3910 close_vgroup_fileids(fileid,sdfd,-1);
3911 throw InternalErr(__FILE__,__LINE__,
"SDreadattr failed ");
3913 string tempstring(attr_value.begin(),attr_value.end());
3914 auto tempfinalstr= string(tempstring.c_str());
3915 if (tempfinalstr ==
"degrees_north") {
3917 string sds_name_str(sds_name.begin(),sds_name.end()-1);
3919 lat_size = dim_sizes[0];
3921 else if (tempfinalstr ==
"degrees_east") {
3923 string sds_name_str(sds_name.begin(),sds_name.end()-1);
3925 lon_size = dim_sizes[0];
3928 if (find_lat && find_lon)
3932 if (find_lat && find_lon) {
3933 SDendaccess(sds_id);
3937 SDendaccess(sds_id);
3942void read_dds_simple_cf(DDS &dds,
const string & filename, int32 sdfd, int32 fileid,
short cf_simple_type) {
3944 dds.set_dataset_name(basename(filename));
3947 int32 n_sd_attrs = 0;
3950 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
3951 close_vgroup_fileids(fileid,sdfd,-1);
3952 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
3955 for (
int i = 0; i <n_sds; i++) {
3957 uint16 name_len = 0;
3958 vector<char> sds_name;
3960 int32 sds_id = SDselect(sdfd,i);
3961 if (sds_id == FAIL) {
3962 close_vgroup_fileids(fileid,sdfd,-1);
3963 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3966 int32 obj_ref = SDidtoref(sds_id);
3967 if (obj_ref == FAIL) {
3968 SDendaccess(sds_id);
3969 close_vgroup_fileids(fileid,sdfd,-1);
3970 throw InternalErr (__FILE__,__LINE__,
"SDidtoref failed ");
3973 if (SDgetnamelen(sds_id, &name_len) == FAIL) {
3974 SDendaccess(sds_id);
3975 close_vgroup_fileids(fileid,sdfd,-1);
3976 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS name length.");
3979 sds_name.resize(name_len+1);
3985 if (FAIL == SDgetinfo (sds_id, sds_name.data(), &sds_rank,
nullptr, &sds_type,
nullptr)) {
3986 SDendaccess(sds_id);
3987 close_vgroup_fileids(fileid,sdfd,-1);
3988 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS ID.");
3991 string sds_name_str(sds_name.begin(),sds_name.end()-1);
3996 vector<string> dimnames;
3997 vector<int32> dimsizes;
3998 for (
int dimindex = 0; dimindex <sds_rank; dimindex++) {
4000 int dimid = SDgetdimid (sds_id, dimindex);
4001 if (dimid == FAIL) {
4002 SDendaccess (sds_id);
4003 close_vgroup_fileids(fileid,sdfd,-1);
4004 throw InternalErr(__FILE__, __LINE__,
"SDgetdimid failed.");
4006 char dim_name[H4_MAX_NC_NAME];
4011 int32 num_dim_attrs = 0;
4013 intn status = SDdiminfo (dimid, dim_name, &dim_size, &dim_type,
4016 if (status == FAIL) {
4017 SDendaccess (sds_id);
4018 close_vgroup_fileids(fileid,sdfd,-1);
4019 throw InternalErr(__FILE__, __LINE__,
"SDdiminfo failed.");
4022 if (dim_size == 0) {
4024 SDendaccess (sds_id);
4025 close_vgroup_fileids(fileid,sdfd,-1);
4026 throw InternalErr(__FILE__, __LINE__,
"Currently not support the unlimited dimension for simple CF handling.");
4028 string dim_name_str (dim_name);
4032 dimnames.push_back(dim_name_str);
4033 dimsizes.push_back(dim_size);
4036 BaseType *bt = gen_dap_var(sds_type,sds_name_str, filename);
4037 auto ar_unique = make_unique<HDFSPArray_RealField>(
4049 auto ar = ar_unique.get();
4050 for (
int j = 0; j <sds_rank; j++)
4051 ar->append_dim(dimsizes[j],dimnames[j]);
4052 dds.add_var_nocopy(ar_unique.release());
4054 SDendaccess(sds_id);
4058 if (cf_simple_type == 1) {
4064 string lat_dim_name;
4065 string lon_dim_name;
4069 obtain_cf_simple_lat_lon(sdfd,fileid,n_sds,lat_name,lon_name,lat_size,lon_size);
4071 if (!lat_name.empty() && !lon_name.empty()) {
4073 bool find_lat_dim_name =
false;
4074 bool find_lon_dim_name =
false;
4076 for (
const auto &var: dds.variables()) {
4078 if (var->type() == dods_array_c) {
4079 auto ar =
dynamic_cast<Array*
>(var);
4080 if (ar->dimensions() == 1) {
4082 if (cf_var_name == lat_name) {
4083 lat_dim_name = ar->dimension_name(ar->dim_begin());
4084 ar->rename_dim(lat_dim_name, lat_name);
4085 find_lat_dim_name =
true;
4087 else if(cf_var_name == lon_name) {
4088 lon_dim_name = ar->dimension_name(ar->dim_begin());
4089 ar->rename_dim(lon_dim_name, lon_name);
4090 find_lon_dim_name =
true;
4094 if (find_lat_dim_name && find_lon_dim_name)
4098 if (!find_lat_dim_name || !find_lon_dim_name) {
4099 close_vgroup_fileids(fileid,sdfd,-1);
4100 throw InternalErr(__FILE__, __LINE__,
"Cannot find lat or lon dimension names for simple CF handling.");
4105 for (
const auto &var: dds.variables()) {
4107 if (var->type() == dods_array_c) {
4109 auto ar =
dynamic_cast<Array*
>(var);
4111 for (Array::Dim_iter p = ar->dim_begin(); p != ar->dim_end(); ++p) {
4112 if (ar->dimension_size(p) == lat_size && ar->dimension_name(p).find(lat_dim_name)==0)
4113 ar->rename_dim(ar->dimension_name(p),lat_name);
4114 else if (ar->dimension_size(p) == lon_size && ar->dimension_name(p).find(lon_dim_name)==0) {
4115 ar->rename_dim(ar->dimension_name(p),lon_name);
4124void read_dds(DDS & dds,
const string & filename)
4128 dds.set_dataset_name(basename(filename));
4129 build_descriptions(dds, das, filename);
4131 if (!dds.check_semantics()) {
4137void read_das(DAS & das,
const string & filename)
4141 dds.set_dataset_name(basename(filename));
4143 build_descriptions(dds, das, filename);
4145 if (!dds.check_semantics()) {
4153static void build_descriptions(DDS & dds, DAS & das,
4154 const string & filename)
4162 SDS_descriptions(sdsmap, das, filename);
4165 FileAnnot_descriptions(das, filename);
4168 Vdata_descriptions(vdatamap, das, filename);
4171 GR_descriptions(grmap, das, filename);
4174 Vgroup_descriptions(dds, das, filename, sdsmap, vdatamap, grmap);
4189 :
public binary_function < hdf_genvec &, hdf_attr, hdf_genvec & > {
4193 explicit accum_attr(
const string & named):d_named(named) {
4196 hdf_genvec & operator() (hdf_genvec & accum,
const hdf_attr & attr) {
4199 BESDEBUG(
"h4",
"attr.name: " << attr.name << endl);
4200 if (attr.name.find(d_named) != string::npos) {
4203 stuff.assign(attr.values.data(), attr.values.size());
4204 cerr <<
"Attribute chunk: " << attr.name << endl;
4205 cerr << stuff << endl;
4207 accum.append(attr.values.number_type(), attr.values.data(),
4208 attr.values.size());
4217struct is_named:
public unary_function < hdf_attr, bool > {
4220 explicit is_named(
const string & named):d_named(named) {
4223 bool operator() (
const hdf_attr & attr) {
4224 return (attr.name.find(d_named) != string::npos);
4229merge_split_eos_attributes(vector < hdf_attr > &attr_vec,
4230 const string & attr_name)
4233 if (count_if(attr_vec.begin(), attr_vec.end(), is_named(attr_name)) > 1) {
4237 attributes = accumulate(attr_vec.begin(), attr_vec.end(),
4238 attributes, accum_attr(attr_name));
4246 DBG(vector < string > s_m;
4247 attributes.print(s_m);
4248 cerr <<
"Accum struct MD: (" << s_m.size() <<
") "
4252 attr_vec.erase(remove_if(attr_vec.begin(), attr_vec.end(),
4253 is_named(attr_name)), attr_vec.end());
4257 merged_attr.name = attr_name;
4258 merged_attr.values = attributes;
4261 attr_vec.push_back(merged_attr);
4266static void SDS_descriptions(sds_map & map, DAS & das,
4267 const string & filename)
4271 sdsin.setmeta(
true);
4275 vector < hdf_attr > fileattrs;
4280 while (!sdsin.eos()) {
4283 sdi.in_vgroup =
false;
4284 map[sdi.sds.ref] = sdi;
4291 merge_split_eos_attributes(fileattrs,
"StructMetadata");
4292 merge_split_eos_attributes(fileattrs,
"CoreMetadata");
4293 merge_split_eos_attributes(fileattrs,
"ProductMetadata");
4294 merge_split_eos_attributes(fileattrs,
"ArchiveMetadata");
4295 merge_split_eos_attributes(fileattrs,
"coremetadata");
4296 merge_split_eos_attributes(fileattrs,
"productmetadata");
4299 AddHDFAttr(das,
string(
"HDF_GLOBAL"), fileattrs);
4301 vector < hdf_attr > dattrs;
4305 for (SDSI s = map.begin(); s != map.end(); ++s) {
4306 const hdf_sds *sds = &s->second.sds;
4307 AddHDFAttr(das, sds->name, sds->attrs);
4308 for (
int k = 0; k < (
int) sds->dims.size(); ++k) {
4309 dattrs = Dims2Attrs(sds->dims[k]);
4310 AddHDFAttr(das, sds->name +
"_dim_" + num2string(k), dattrs);
4319static void Vdata_descriptions(vd_map & map, DAS & das,
4320 const string & filename)
4326 while (!vdin.eos()) {
4329 vdi.in_vgroup =
false;
4330 map[vdi.vdata.ref] = vdi;
4335 vector < hdf_attr > dattrs;
4336 for (VDI s = map.begin(); s != map.end(); ++s) {
4338 AddHDFAttr(das, vd->name, vd->attrs);
4345static void Vgroup_descriptions(DDS & dds, DAS & das,
4346 const string & filename, sds_map & sdmap,
4347 vd_map & vdmap, gr_map & grmap)
4354 while (!vgin.eos()) {
4357 vgi.toplevel =
true;
4358 vgmap[vgi.vgroup.ref] = vgi;
4362 for (VGI v = vgmap.begin(); v != vgmap.end(); ++v) {
4366 AddHDFAttr(das, vg->name, vg->attrs);
4369 for (uint32 i = 0; i < vg->tags.size(); i++) {
4370 int32 tag = vg->tags[i];
4371 int32 ref = vg->refs[i];
4375 if (grmap.find(ref) != grmap.end())
4376 grmap[ref].in_vgroup =
true;
4378 vgmap[ref].toplevel =
false;
4381 vdmap[ref].in_vgroup =
true;
4384 sdmap[ref].in_vgroup =
true;
4387 ERROR_LOG(
"unknown tag: " + std::to_string(tag) +
" ref: " + std::to_string(ref));
4397 BaseType *pbt =
nullptr;
4398 for (VGI v = vgmap.begin(); v != vgmap.end(); ++v) {
4399 if (!v->second.toplevel)
4401 pbt = NewStructureFromVgroup(v->second.vgroup,
4402 vgmap, sdmap, vdmap,
4404 if (pbt !=
nullptr) {
4412 for (SDSI s = sdmap.begin(); s != sdmap.end(); ++s) {
4413 if (s->second.in_vgroup)
4415 if (s->second.sds.has_scale())
4416 pbt = NewGridFromSDS(s->second.sds, filename);
4418 pbt = NewArrayFromSDS(s->second.sds, filename);
4419 if (pbt !=
nullptr) {
4426 for (VDI v = vdmap.begin(); v != vdmap.end(); ++v) {
4427 if (v->second.in_vgroup)
4429 pbt = NewSequenceFromVdata(v->second.vdata, filename);
4430 if (pbt !=
nullptr) {
4436 for (GRI g = grmap.begin(); g != grmap.end(); ++g) {
4437 if (g->second.in_vgroup)
4439 pbt = NewArrayFromGR(g->second.gri, filename);
4440 if (pbt !=
nullptr) {
4447static void GR_descriptions(gr_map & map, DAS & das,
4448 const string & filename)
4455 vector < hdf_attr > fileattrs;
4460 while (!grin.eos()) {
4463 gri.in_vgroup =
false;
4464 map[gri.gri.ref] = gri;
4470 AddHDFAttr(das,
string(
"HDF_GLOBAL"), fileattrs);
4473 vector < hdf_attr > pattrs;
4474 for (GRI g = map.begin(); g != map.end(); ++g) {
4475 const hdf_gri *gri = &g->second.gri;
4477 AddHDFAttr(das, gri->name, gri->attrs);
4480 pattrs = Pals2Attrs(gri->palettes);
4481 AddHDFAttr(das, gri->name, pattrs);
4489static void FileAnnot_descriptions(DAS & das,
const string & filename)
4493 vector < string > fileannots;
4495 annotin >> fileannots;
4496 AddHDFAttr(das,
string(
"HDF_GLOBAL"), fileannots);
4503void AddHDFAttr(DAS & das,
const string & varname,
4504 const vector < hdf_attr > &hav)
4506 if (hav.size() == 0)
4510 string tempname = varname;
4511 AttrTable *atp = das.get_table(tempname);
4512 if (atp ==
nullptr) {
4513 atp =
new AttrTable;
4514 atp = das.add_table(tempname, atp);
4517 vector < string > attv;
4519 for (
int i = 0; i < (
int) hav.size(); ++i) {
4521 attrtype = DAPTypeName(hav[i].values.number_type());
4523 attv = vector < string > ();
4524 hav[i].values.print(attv);
4527 for (
int j = 0; j < (
int) attv.size(); ++j) {
4529 string container_name = hav[i].name;
4530 if (container_name.find(
"StructMetadata") == 0
4531 || container_name.find(
"CoreMetadata") == 0
4532 || container_name.find(
"ProductMetadata") == 0
4533 || container_name.find(
"ArchiveMetadata") == 0
4534 || container_name.find(
"coremetadata") == 0
4535 || container_name.find(
"productmetadata") == 0) {
4536 string::size_type dotzero = container_name.find(
'.');
4537 if (dotzero != container_name.npos)
4538 container_name.erase(dotzero);
4541 AttrTable *at = das.get_table(container_name);
4543 at = das.add_table(container_name,
new AttrTable);
4546 void *buf = hdfeos_string(attv[j].c_str());
4564 if (hdfeosparse(&arg) != 0){
4565 hdfeos_delete_buffer(buf);
4566 throw Error(
"HDF-EOS parse error while processing a " + container_name +
" HDFEOS attribute.");
4570 if (arg.status() ==
false) {
4571 ERROR_LOG(
"HDF-EOS parse error while processing a " + container_name +
" HDFEOS attribute. (2)");
4575 hdfeos_delete_buffer(buf);
4580 if (attrtype ==
"String")
4581#ifdef ATTR_STRING_QUOTE_FIX
4582 attv[j] = escattr(attv[j]);
4585 attv[j] =
"\"" + escattr(attv[j]) +
"\"";
4589 if (atp->append_attr(hav[i].name, attrtype, attv[j]) == 0)
4600void AddHDFAttr(DAS & das,
const string & varname,
4601 const vector < string > &anv)
4603 if (anv.size() == 0)
4608 AttrTable *atp = das.get_table(varname);
4609 if (atp ==
nullptr) {
4610 atp =
new AttrTable;
4611 atp = das.add_table(varname, atp);
4615 for (
int i = 0; i < (
int) anv.size(); ++i) {
4619#ifdef ATTR_STRING_QUOTE_FIX
4620 an = escattr(anv[i]);
4622 an =
"\"" + escattr(anv[i]) +
"\"";
4625 if (atp->append_attr(
string(
"HDF_ANNOT"),
"String", an) == 0)
4635static vector < hdf_attr > Pals2Attrs(
const vector < hdf_palette > palv)
4637 vector < hdf_attr > pattrs;
4639 if (palv.size() != 0) {
4644 for (
int i = 0; i < (
int) palv.size(); ++i) {
4645 palname =
"hdf_palette_" + num2string(i);
4646 pattr.name = palname;
4647 pattr.values = palv[i].table;
4648 pattrs.push_back(pattr);
4649 pattr.name = palname +
"_ncomps";
4652 int32 *
>(&palv[i].ncomp), 1);
4653 pattrs.push_back(pattr);
4654 if (palv[i].name.size() != 0) {
4655 pattr.name = palname +
"_name";
4658 char *
>(palv[i].name.c_str()),
4659 palv[i].name.size());
4660 pattrs.push_back(pattr);
4669static vector < hdf_attr > Dims2Attrs(
const hdf_dim dim)
4671 vector < hdf_attr > dattrs;
4673 if (dim.name.size() != 0) {
4674 dattr.name =
"name";
4676 hdf_genvec(DFNT_CHAR,
const_cast < char *
>(dim.name.c_str()),
4678 dattrs.push_back(dattr);
4680 if (dim.label.size() != 0) {
4681 dattr.name =
"long_name";
4683 hdf_genvec(DFNT_CHAR,
const_cast < char *
>(dim.label.c_str()),
4685 dattrs.push_back(dattr);
4687 if (dim.unit.size() != 0) {
4688 dattr.name =
"units";
4690 hdf_genvec(DFNT_CHAR,
const_cast < char *
>(dim.unit.c_str()),
4692 dattrs.push_back(dattr);
4694 if (dim.format.size() != 0) {
4695 dattr.name =
"format";
4697 hdf_genvec(DFNT_CHAR,
const_cast < char *
>(dim.format.c_str()),
4699 dattrs.push_back(dattr);
4705void read_dmr(DMR *dmr,
const string &filename) {
4707 BESDEBUG(
"h4",
" Begin read_dmr()"<<endl);
4709 int32 fileid = Hopen(filename.c_str(), DFACC_READ,0);
4711 string invalid_file_msg=
"HDF4 SDstart error for the file ";
4712 invalid_file_msg +=filename;
4713 invalid_file_msg +=
". It is very possible that this file is not an HDF4 file. ";
4714 throw InternalErr(__FILE__,__LINE__,invalid_file_msg);
4717 int32 sdfd = SDstart(filename.c_str(), DFACC_READ);
4720 string invalid_file_msg=
"HDF4 SDstart error for the file ";
4721 invalid_file_msg +=filename;
4722 invalid_file_msg +=
". It is very possible that this file is not an HDF4 file. ";
4723 throw InternalErr(__FILE__,__LINE__,invalid_file_msg);
4726 D4Group* root_grp = dmr->root();
4735 handle_sds_dims(root_grp,fileid, sdfd);
4736 read_lone_sds(root_grp,fileid,sdfd,filename);
4739 read_lone_vdata(root_grp,fileid,sdfd,filename);
4742 read_sd_attrs(root_grp,fileid, sdfd);
4747 bool is_sp_hdf4_file = add_sp_hdf4_info(root_grp, filename, err_msg);
4748 if (is_sp_hdf4_file ==
false) {
4749 close_vgroup_fileids(fileid,sdfd,-1);
4750 throw InternalErr(__FILE__, __LINE__, err_msg);
4754 read_dmr_vlone_groups(root_grp, fileid, sdfd, filename);
4756 if (is_sp_hdf4_file)
4757 add_sp_hdf4_additional_info(root_grp);
4761 BESDEBUG(
"h4",
" End read_dmr()"<<endl);
4764void handle_sds_dims(D4Group *root_grp, int32 fileid, int32 sdfd) {
4766 BESDEBUG(
"h4",
" Begin handle_sds_dims() "<<endl);
4768 int32 n_sd_attrs = 0;
4771 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
4772 close_vgroup_fileids(fileid,sdfd,-1);
4773 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
4776 D4Dimensions *dims = root_grp->dims();
4780 unordered_set<string> sds_dimname_set;
4781 for (
int i = 0; i <n_sds; i++) {
4783 int32 sds_id = SDselect(sdfd,i);
4785 if (sds_id == FAIL) {
4786 close_vgroup_fileids(fileid,sdfd,-1);
4787 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS ID.");
4791 int32 dim_sizes[H4_MAX_VAR_DIMS];
4794 int32 n_sds_attrs = 0;
4795 if (FAIL == SDgetinfo (sds_id,
nullptr, &sds_rank, dim_sizes, &sds_type, &n_sds_attrs)) {
4796 SDendaccess(sds_id);
4797 close_vgroup_fileids(fileid,sdfd,-1);
4798 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain SDS info.");
4801 for (
int dimindex = 0; dimindex <sds_rank; dimindex++) {
4803 int dimid = SDgetdimid (sds_id, dimindex);
4804 if (dimid == FAIL) {
4805 SDendaccess (sds_id);
4806 close_vgroup_fileids(fileid,sdfd,-1);
4807 throw InternalErr(__FILE__, __LINE__,
"SDgetdimid failed.");
4809 char dim_name[H4_MAX_NC_NAME];
4814 int32 num_dim_attrs = 0;
4816 intn status = SDdiminfo (dimid, dim_name, &dim_size, &dim_type,
4819 if (status == FAIL) {
4820 SDendaccess (sds_id);
4821 close_vgroup_fileids(fileid,sdfd,-1);
4822 throw InternalErr(__FILE__, __LINE__,
"SDdiminfo failed.");
4825 if (dim_size == 0 && dim_sizes[dimindex] == 0)
4827 string dim_name_str (dim_name);
4832 auto it_set = sds_dimname_set.insert(dim_name_str);
4833 if (it_set.second) {
4834 auto d4_dim0_unique = make_unique<D4Dimension>(dim_name_str,dim_sizes[dimindex]);
4835 auto d4_dim0 = d4_dim0_unique.release();
4836 dims->add_dim_nocopy(d4_dim0);
4839 SDendaccess(sds_id);
4842 BESDEBUG(
"h4",
" End handle_sds_dims() "<<endl);
4845void read_lone_sds(D4Group *root_grp, int32 file_id,int32 sdfd,
const string &filename) {
4847 BESDEBUG(
"h4",
" Begin read_lone_sds() "<<endl);
4849 unordered_set<int32> lone_sds_refs;
4851 obtain_all_sds_refs(file_id,sdfd,lone_sds_refs);
4852 exclude_all_sds_refs_in_vgroups(file_id,sdfd,lone_sds_refs);
4855 set<int32> ordered_lone_sds_refs(lone_sds_refs.begin(),lone_sds_refs.end());
4858 for (
const auto &sds_ref:ordered_lone_sds_refs) {
4859 convert_sds(file_id, sdfd, -1,sds_ref, root_grp, root_grp, filename,
false,
false);
4862 BESDEBUG(
"h4",
" End read_lone_sds() "<<endl);
4865void obtain_all_sds_refs(int32 file_id, int32 sdfd, unordered_set<int32>& sds_ref) {
4867 BESDEBUG(
"h4",
" Begin obtain_all_sds_refs() "<<endl);
4869 int32 n_sd_attrs = 0;
4872 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
4873 close_vgroup_fileids(file_id,sdfd,-1);
4874 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
4877 for (
int i = 0; i <n_sds; i++) {
4879 int32 sds_id = SDselect(sdfd,i);
4880 if (sds_id == FAIL) {
4881 close_vgroup_fileids(file_id,sdfd,-1);
4882 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
4884 int32 obj_ref = SDidtoref(sds_id);
4885 if (obj_ref == FAIL) {
4886 SDendaccess(sds_id);
4887 close_vgroup_fileids(file_id,sdfd,-1);
4888 throw InternalErr (__FILE__,__LINE__,
"SDidtoref failed ");
4890 sds_ref.insert(obj_ref);
4891 SDendaccess(sds_id);
4894 BESDEBUG(
"h4",
" End obtain_all_sds_refs() "<<endl);
4897void exclude_all_sds_refs_in_vgroups(int32 file_id, int32 sdfd, unordered_set<int32>& sds_ref) {
4899 BESDEBUG(
"h4",
" Begin exclude_all_sds_refs_in_vgroups() "<<endl);
4901 vector<int> ref_array;
4904 istat = Vstart(file_id);
4905 if (istat == FAIL) {
4906 close_vgroup_fileids(file_id,sdfd,-1);
4907 throw InternalErr(__FILE__, __LINE__,
"unable to start hdf4 V interface.");
4910 num_lonevg = Vlone(file_id,
nullptr,0);
4912 if (num_lonevg == FAIL) {
4913 close_vgroup_fileids(file_id,sdfd,-1);
4914 throw InternalErr(__FILE__, __LINE__,
"error in obtaining lone vgroup number.");
4920 if (num_lonevg == 0) {
4925 ref_array.resize(num_lonevg);
4927 num_lonevg = Vlone(file_id,ref_array.data(),num_lonevg);
4931 for(
int lone_vg_number = 0; lone_vg_number < num_lonevg;
4934 int32 vgroup_id = Vattach(file_id,ref_array[lone_vg_number],
"r");
4935 if (vgroup_id ==FAIL) {
4936 close_vgroup_fileids(file_id,sdfd,-1);
4937 throw InternalErr(__FILE__, __LINE__,
"error in attaching lone vgroup.");
4940 uint16 vclassnamelen;
4941 vector<char> vclass_name;
4942 if (Vgetclassnamelen(vgroup_id,&vclassnamelen) == FAIL) {
4943 close_vgroup_fileids(file_id,sdfd,vgroup_id);
4944 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name length.");
4947 if (vclassnamelen!=0) {
4948 vclass_name.resize(vclassnamelen+1);
4949 if (Vgetclass(vgroup_id,vclass_name.data()) == FAIL) {
4950 close_vgroup_fileids(file_id,sdfd,vgroup_id);
4951 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name.");
4953 if (reserved_vgroups(vclass_name)) {
4959 exclude_sds_refs_in_vgroup(file_id,sdfd,vgroup_id,sds_ref);
4965 BESDEBUG(
"h4",
"End exclude_all_sds_refs_in_vgroups() "<<endl);
4968void exclude_sds_refs_in_vgroup(int32 file_id, int32 sdfd, int32 vgroup_id, unordered_set<int32> &sds_ref) {
4974 num_gobjects = Vntagrefs(vgroup_id);
4975 if (num_gobjects == FAIL) {
4976 close_vgroup_fileids(file_id,sdfd,vgroup_id);
4977 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name.");
4980 for(
int i = 0;i<num_gobjects;i++) {
4982 if (Vgettagref(vgroup_id,i,&obj_tag,&obj_ref)==FAIL) {
4983 close_vgroup_fileids(file_id,sdfd,vgroup_id);
4984 throw InternalErr(__FILE__, __LINE__,
"fail to obtain object tag and ref. of Vgroup members");
4987 if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG) {
4989 if (0 == sds_ref.erase(obj_ref)) {
4990 close_vgroup_fileids(file_id,sdfd,vgroup_id);
4991 string err_msg =
"Unable to remove the SDS object from the sds reference list for the reference number " + to_string(obj_ref);
4992 throw InternalErr(__FILE__, __LINE__, err_msg);
4996 else if (Visvg(vgroup_id, obj_ref)) {
4998 int32 vgroup_cid = Vattach(file_id,obj_ref,
"r");
4999 if (vgroup_cid == FAIL) {
5000 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5001 throw InternalErr(__FILE__, __LINE__,
"fail to attach vgroup_cid.");
5004 uint16 vclassnamelen;
5005 vector<char> vclass_name;
5006 if (Vgetclassnamelen(vgroup_cid,&vclassnamelen) == FAIL) {
5007 Vdetach(vgroup_cid);
5008 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5009 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name length.");
5012 if (vclassnamelen!=0) {
5013 vclass_name.resize(vclassnamelen+1);
5014 if (Vgetclass(vgroup_cid,vclass_name.data()) == FAIL) {
5015 Vdetach(vgroup_cid);
5016 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5017 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name.");
5019 if (reserved_vgroups(vclass_name)) {
5020 Vdetach(vgroup_cid);
5025 exclude_sds_refs_in_vgroup(file_id,sdfd,vgroup_cid,sds_ref);
5026 Vdetach(vgroup_cid);
5032void read_sd_attrs(D4Group *root_grp, int32 fileid, int32 sdfd) {
5035 int32 n_sd_attrs = 0;
5038 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
5041 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
5044 for (
int attr_index = 0; attr_index < n_sd_attrs;attr_index++) {
5046 char attr_name[H4_MAX_NC_NAME];
5047 int32 attr_type = -1;
5048 int32 attr_count = -1;
5050 if (SDattrinfo(sdfd,attr_index,attr_name,&attr_type,&attr_count) == FAIL) {
5053 throw InternalErr (__FILE__,__LINE__,
"SDattrinfo failed ");
5056 vector<char> attr_value;
5057 attr_value.resize(attr_count * DFKNTsize(attr_type));
5058 if (SDreadattr (sdfd, attr_index, attr_value.data()) == -1) {
5061 throw InternalErr(__FILE__,__LINE__,
"SDreadattr failed ");
5064 string dap4_attrname (attr_name);
5066 map_vgroup_attr(root_grp, dap4_attrname,attr_type,attr_count, attr_value);
5073void read_lone_vdata(D4Group *root_grp, int32 file_id, int32 sdfd,
const string &filename) {
5075 BESDEBUG(
"h4",
" Begin read_lone_vdata()"<<endl);
5076 if (Vstart(file_id) == FAIL) {
5079 throw InternalErr(__FILE__, __LINE__,
"Fail to start the V interface.");
5082 int num_lone_vdata = VSlone (file_id,
nullptr, 0);
5084 if (num_lone_vdata == FAIL) {
5085 close_vgroup_fileids(file_id,sdfd,-1);
5086 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the number of lone vdatas.");
5089 if (num_lone_vdata > 0) {
5091 vector<int32>ref_array;
5092 ref_array.resize(num_lone_vdata);
5094 if (VSlone (file_id, ref_array.data(), num_lone_vdata) == FAIL) {
5095 close_vgroup_fileids(file_id,sdfd,-1);
5096 throw InternalErr(__FILE__, __LINE__,
"Cannot obtain lone vdata reference arrays.");
5099 for (
int i = 0; i < num_lone_vdata; i++)
5100 convert_vdata(file_id,sdfd, -1, ref_array[i],root_grp,filename);
5104 BESDEBUG(
"h4",
" End read_lone_vdata()"<<endl);
5107void read_dmr_vlone_groups(D4Group *root_grp, int32 file_id, int32 sdfd,
const string & filename) {
5109 BESDEBUG(
"h4",
"Start read_dmr_vlone_groups "<<endl);
5112 vector<int> ref_array;
5115 istat = Vstart(file_id);
5116 if (istat == FAIL) {
5117 close_vgroup_fileids(file_id,sdfd,-1);
5118 throw InternalErr(__FILE__, __LINE__,
"Unable to start hdf4 V interface.");
5121 num_lonevg = Vlone(file_id,
nullptr,0);
5123 if (num_lonevg == FAIL) {
5124 close_vgroup_fileids(file_id,sdfd,-1);
5125 throw InternalErr(__FILE__, __LINE__,
"error in obtaining the total number of lone vgroups.");
5131 if (num_lonevg == 0){
5137 vector<eos2_grid_t> eos2_grid_lls;
5138 vector<eos2_grid_info_t> eos2_grids_info;
5141#ifdef USE_HDFEOS2_LIB
5142 bool ret_value = check_eos2_grids(filename,sdfd,eos2_grid_lls, eos2_grids_info);
5143 if (ret_value ==
false) {
5144 close_vgroup_fileids(file_id,sdfd,-1);
5145 throw InternalErr(__FILE__, __LINE__,
"error in the check_eos2_grid(). ");
5149for(
const auto& eg:eos2_grid_lls) {
5150 cout<<
"grid name: "<<eg.grid_name <<endl;
5151if (eg.oned_latlon==
true)
5152 cout<<
"1d latlon "<<endl;
5154 cout<<
"2d latlon "<<endl;
5155 cout<<
"xdim: "<< eg.xdim <<endl;
5156 cout<<
"ydim: "<< eg.ydim <<endl;
5158for(
const auto& eg:eos2_grids_info) {
5159 cout<<
"eg.proj_code: "<< eg.projcode << endl;
5166 ref_array.resize(num_lonevg);
5168 num_lonevg = Vlone(file_id,ref_array.data(),num_lonevg);
5172 for(
int lone_vg_number = 0; lone_vg_number < num_lonevg;
5175 int32 vgroup_id = Vattach(file_id,ref_array[lone_vg_number],
"r");
5176 if (vgroup_id ==FAIL) {
5177 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5178 throw InternalErr(__FILE__, __LINE__,
"error in attaching lone vgroup.");
5181 uint16 vclassnamelen = 0;
5182 vector<char> vclass_name;
5183 if (Vgetclassnamelen(vgroup_id,&vclassnamelen) == FAIL) {
5184 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5185 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name length.");
5188 if (vclassnamelen!=0) {
5189 vclass_name.resize(vclassnamelen+1);
5190 if (Vgetclass(vgroup_id,vclass_name.data()) == FAIL) {
5191 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5192 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name.");
5194 if (reserved_vgroups(vclass_name)) {
5200 uint16 vgroupnamelen = 0;
5201 if (Vgetnamelen(vgroup_id,&vgroupnamelen) == FAIL) {
5202 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5203 throw InternalErr(__FILE__, __LINE__,
"cannot obtain vgroup name length.");
5206 if (vgroupnamelen == 0) {
5210 vector<char> vgroup_name;
5211 vgroup_name.resize(vgroupnamelen+1);
5213 if (Vgetname(vgroup_id,vgroup_name.data())==FAIL){
5214 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5215 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup name.");
5218 string vgroup_name_orig_str(vgroup_name.begin(),vgroup_name.end()-1);
5220 int eos2_grid_lls_index = -1;
5221 if (!eos2_grid_lls.empty())
5222 eos2_grid_lls_index = is_group_eos2_grid(vgroup_name_orig_str,eos2_grid_lls);
5225 auto tem_d4_cgroup_ptr = make_unique<D4Group>(vgroup_name_str);
5226 auto tem_d4_cgroup = tem_d4_cgroup_ptr.release();
5227 root_grp->add_group_nocopy(tem_d4_cgroup);
5230 bool is_eos2_grid =
false;
5231 bool is_eos2_grid_cf_mapping =
false;
5232 if (eos2_grid_lls_index >=0) {
5233 add_eos2_latlon_info(tem_d4_cgroup, root_grp, eos2_grid_lls[eos2_grid_lls_index],eos2_grids_info[eos2_grid_lls_index],filename);
5234 is_eos2_grid =
true;
5235 int32 proj_code = eos2_grids_info[eos2_grid_lls_index].projcode;
5236 if (proj_code == GCTP_LAMAZ || proj_code == GCTP_PS || proj_code == GCTP_SNSOID)
5237 is_eos2_grid_cf_mapping =
true;
5240 convert_vgroup_objects(vgroup_id,file_id,sdfd,tem_d4_cgroup,root_grp, vgroup_name_orig_str,filename,is_eos2_grid,is_eos2_grid_cf_mapping);
5246 BESDEBUG(
"h4",
"Finish read_dmr_vlone_groups "<<endl);
5250bool reserved_vgroups(
const vector<char>& vgroup_class) {
5252 if(strcmp(vgroup_class.data(),_HDF_ATTRIBUTE)==0)
5254 else if(strcmp(vgroup_class.data(),_HDF_VARIABLE) ==0)
5256 else if(strcmp(vgroup_class.data(),_HDF_DIMENSION)==0)
5258 else if(strcmp(vgroup_class.data(),_HDF_UDIMENSION)==0)
5260 else if(strcmp(vgroup_class.data(),_HDF_CDF)==0)
5262 else if(strcmp(vgroup_class.data(),GR_NAME)==0)
5264 else if(strcmp(vgroup_class.data(),RI_NAME)==0)
5271void vgroup_convert_sds_objects(int32 vgroup_id, int32 file_id, int32 sdfd, D4Group *d4g,
const string &filename) {
5273 int num_gobjects = 0;
5277 num_gobjects = Vntagrefs(vgroup_id);
5278 if (num_gobjects == FAIL) {
5279 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5280 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name.");
5283 for(
int i = 0;i<num_gobjects;i++) {
5285 if (Vgettagref(vgroup_id,i,&obj_tag,&obj_ref)==FAIL) {
5286 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5287 throw InternalErr(__FILE__, __LINE__,
"fail to obtain object tag and ref. of Vgroup members");
5290 if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG) {
5291 convert_sds(file_id, sdfd,vgroup_id, obj_ref, d4g,filename);
5298void convert_vgroup_objects(int32 vgroup_id,int32 file_id,int32 sdfd,D4Group *d4g,D4Group *root_grp,
const string &vgroupname,
const string& filename,
bool is_eos2_grid,
bool is_eos2_grid_cf_mapping) {
5300 BESDEBUG(
"h4",
" Start convert_vgroup_objects"<<endl);
5302 int num_gobjects = 0;
5306 num_gobjects = Vntagrefs(vgroup_id);
5307 if (num_gobjects == FAIL) {
5308 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5309 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup class name.");
5313 for (
int i = 0;i<num_gobjects;i++) {
5315 if (Vgettagref(vgroup_id,i,&obj_tag,&obj_ref)==FAIL) {
5316 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5317 throw InternalErr(__FILE__, __LINE__,
"fail to obtain object tag and ref. of Vgroup members");
5321 if (obj_tag == DFTAG_NDG || obj_tag == DFTAG_SDG) {
5322 convert_sds(file_id,sdfd,vgroup_id,obj_ref,d4g,root_grp, filename,is_eos2_grid, is_eos2_grid_cf_mapping);
5324 else if(Visvs(vgroup_id,obj_ref)) {
5325 convert_vdata(file_id, sdfd, vgroup_id, obj_ref,d4g,filename);
5330 convert_vgroup_attrs(vgroup_id,d4g, vgroupname);
5333 for(
int i = 0;i<num_gobjects;i++) {
5335 if (Vgettagref(vgroup_id,i,&obj_tag,&obj_ref)==FAIL) {
5336 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5337 throw InternalErr(__FILE__, __LINE__,
"fail to obtain object tag and ref. of Vgroup members");
5340 if (Visvg(vgroup_id, obj_ref)) {
5342 int32 vgroup_cid = Vattach(file_id,obj_ref,
"r");
5343 if (vgroup_cid == FAIL) {
5344 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5345 throw InternalErr(__FILE__, __LINE__,
"fail to attach vgroup_cid.");
5348 uint16 vclassnamelen = 0;
5349 vector<char> vclass_name;
5350 if (Vgetclassnamelen(vgroup_cid,&vclassnamelen) == FAIL) {
5351 Vdetach(vgroup_cid);
5352 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5353 throw InternalErr(__FILE__, __LINE__,
"Error in obtaining vgroup class name length.");
5356 if (vclassnamelen!=0) {
5357 vclass_name.resize(vclassnamelen+1);
5358 if (Vgetclass(vgroup_cid,vclass_name.data()) == FAIL) {
5359 Vdetach(vgroup_cid);
5360 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5361 throw InternalErr(__FILE__, __LINE__,
"Error in obtaining vgroup class name.");
5363 if (reserved_vgroups(vclass_name)) {
5364 Vdetach(vgroup_cid);
5369 uint16 vgroupnamelen = 0;
5370 if (Vgetnamelen(vgroup_cid,&vgroupnamelen) == FAIL) {
5371 Vdetach(vgroup_cid);
5372 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5373 throw InternalErr(__FILE__, __LINE__,
"cannot obtain vgroup name length.");
5376 vector<char> vgroup_name;
5377 vgroup_name.resize(vgroupnamelen+1);
5379 if (Vgetname(vgroup_cid,vgroup_name.data())==FAIL){
5380 Vdetach(vgroup_cid);
5381 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5382 throw InternalErr(__FILE__, __LINE__,
"error in obtaining vgroup name.");
5386 string vgroup_name_orig_str(vgroup_name.begin(),vgroup_name.end()-1);
5389 auto d4c_g_ptr = make_unique<D4Group>(vgroup_name_str);
5390 auto d4c_g = d4c_g_ptr.release();
5391 d4g->add_group_nocopy(d4c_g);
5393 convert_vgroup_objects(vgroup_cid,file_id,sdfd,d4c_g,root_grp,vgroup_name_orig_str,filename, is_eos2_grid, is_eos2_grid_cf_mapping);
5395 Vdetach(vgroup_cid);
5398 BESDEBUG(
"h4",
" End convert_vgroup_objects"<<endl);
5401void convert_vgroup_attrs(int32 vgroup_id,D4Group *d4g,
const string &vgroupname) {
5404 intn n_attrs = Vnattrs2(vgroup_id);
5405 if (n_attrs == FAIL) {
5407 throw InternalErr(__FILE__,__LINE__,
"Vnattrs failed");
5410 for(
int attr_index = 0; attr_index <n_attrs; attr_index++) {
5412 char attr_name[H4_MAX_NC_NAME];
5413 int attr_value_size = 0;
5414 int32 attr_type = 0;
5415 int32 attr_count = 0;
5416 intn status_n = Vattrinfo2(vgroup_id, attr_index, attr_name, &attr_type,
5417 &attr_count, &attr_value_size,
nullptr,
nullptr);
5418 if (status_n == FAIL) {
5420 throw InternalErr(__FILE__,__LINE__,
"Vattrinfo failed");
5424 string tempname (attr_name);
5428 if(vgroupname==
"Grid Attributes" || vgroupname==
"Swath Attributes") {
5429 if(tempname.size()>4) {
5430 string tempname_f4chars = tempname.substr(0,4);
5431 if (tempname_f4chars==
"_FV_")
5436 vector<char> attr_value;
5437 attr_value.resize(attr_value_size);
5438 status_n = Vgetattr2(vgroup_id,attr_index,attr_value.data());
5439 if (status_n == FAIL) {
5441 throw InternalErr(__FILE__,__LINE__,
"Vgetattr failed");
5445 map_vgroup_attr(d4g,dap4_attrname,attr_type,attr_count,attr_value);
5452void convert_vdata(int32 fileid, int32 sdfd, int32 vgroup_id,int32 obj_ref ,D4Group* d4g,
const string& filename) {
5455 int32 vdata_id = VSattach (fileid, obj_ref,
"r");
5456 if (vdata_id == FAIL) {
5457 close_vgroup_fileids(fileid,sdfd,vgroup_id);
5458 throw InternalErr(__FILE__, __LINE__,
"Cannot attach vdata.");
5462 char vdata_class[VSNAMELENMAX+1];
5464 if (VSgetclass (vdata_id, vdata_class) == FAIL) {
5465 VSdetach (vdata_id);
5466 close_vgroup_fileids(fileid,sdfd,vgroup_id);
5467 throw InternalErr(__FILE__, __LINE__,
"VSgetclass failed.");
5470 if (VSisattr(vdata_id) == FALSE && VSisinternal(vdata_class) == FALSE) {
5472 int32 vs_nflds = VFnfields(vdata_id);
5473 if (vs_nflds == FAIL) {
5475 close_vgroup_fileids(fileid,sdfd,vgroup_id);
5476 throw InternalErr(__FILE__, __LINE__,
"Cannot get the number of fields of a vdata.");
5479 int32 num_elms = VSelts(vdata_id);
5480 if (num_elms == FAIL) {
5482 close_vgroup_fileids(fileid,sdfd,vgroup_id);
5483 throw InternalErr(__FILE__, __LINE__,
"Cannot get the number of records of a vdata.");
5489 map_vdata_to_dap4_structure_array(vdata_id, num_elms, vs_nflds, obj_ref, d4g, filename);
5490 else if (vs_nflds == 1)
5491 map_vdata_to_dap4_atomic_array(vdata_id, num_elms, obj_ref, d4g, filename);
5495 close_vgroup_fileids(fileid,sdfd,vgroup_id);
5497 throw InternalErr(__FILE__, __LINE__,
"Cannot map vdata to a dap structure array.");
5499 throw InternalErr(__FILE__, __LINE__,
"Cannot map vdata to a dap atomic array.");
5506void map_vdata_to_dap4_atomic_array(int32 vdata_id, int32 num_elms, int32 obj_ref, D4Group *d4g,
const string &filename) {
5509 int32 vdata_field_order = VFfieldorder(vdata_id,0);
5510 if (vdata_field_order == FAIL) {
5511 throw InternalErr(__FILE__, __LINE__,
"VFfieldorder failed");
5514 char vdata_name[VSNAMELENMAX];
5515 if (VSgetname(vdata_id,vdata_name) == FAIL) {
5516 throw InternalErr(__FILE__, __LINE__,
"Cannot get vdata name.");
5519 string vdata_name_str(vdata_name);
5521 const char *fieldname = VFfieldname(vdata_id,0);
5522 if (fieldname ==
nullptr) {
5523 throw InternalErr(__FILE__, __LINE__,
"Cannot get vdata field name.");
5526 string fieldname_str(fieldname);
5527 string dap4_vdata_str;
5530 if (vdata_name_str == fieldname_str)
5531 dap4_vdata_str = fieldname_str;
5535 int32 fieldtype = VFfieldtype(vdata_id,0);
5537 BaseType *bt = gen_dap_var(fieldtype,dap4_vdata_str,filename);
5538 auto ar_unique = make_unique<HDFDMRArray_VD>(filename,obj_ref,dap4_vdata_str,bt);
5539 auto ar = ar_unique.release();
5540 ar->append_dim_ll(num_elms);
5541 if (vdata_field_order != 1) {
5542 ar->append_dim_ll(vdata_field_order);
5547 map_vdata_to_dap4_attrs(ar,vdata_id,obj_ref);
5549 ar->set_is_dap4(
true);
5550 d4g->add_var_nocopy(ar);
5556void map_vdata_to_dap4_structure_array(int32 vdata_id, int32 num_elms, int32 nflds, int32 obj_ref, D4Group *d4g,
const string &filename) {
5558 char vdata_name[VSNAMELENMAX];
5559 if (VSgetname(vdata_id,vdata_name) == FAIL) {
5560 throw InternalErr(__FILE__, __LINE__,
"Cannot get vdata name.");
5562 string vdata_name_str(vdata_name);
5565 auto structure_unique_ptr = make_unique<HDFStructure>(vdata_name_str,filename);
5566 auto structure_ptr = structure_unique_ptr.release();
5568 for (
int j = 0; j <nflds; j++) {
5570 int32 vdata_field_order = VFfieldorder(vdata_id,j);
5571 if (vdata_field_order == FAIL) {
5572 throw InternalErr(__FILE__, __LINE__,
"VFfieldorder failed");
5575 const char *fieldname = VFfieldname(vdata_id,j);
5576 if (fieldname ==
nullptr) {
5577 throw InternalErr(__FILE__, __LINE__,
"Cannot get vdata field name.");
5580 string fieldname_str(fieldname);
5583 int32 fieldtype = VFfieldtype(vdata_id,j);
5585 if (vdata_field_order == 1) {
5586 BaseType *bt = gen_dap_var(fieldtype,fieldname_str,filename);
5587 structure_ptr->add_var(bt);
5591 BaseType *bt = gen_dap_var(fieldtype,fieldname_str,filename);
5592 auto arf_unique = make_unique<HDFArray>(fieldname_str,filename,bt);
5593 auto arf = arf_unique.release();
5594 arf->append_dim_ll(vdata_field_order);
5595 structure_ptr->add_var(arf);
5601 auto ar_unique = make_unique<HDFDMRArray_VD>(filename,obj_ref,vdata_name_str,structure_ptr);
5602 auto ar = ar_unique.release();
5603 ar->append_dim_ll(num_elms);
5606 map_vdata_to_dap4_attrs(ar,vdata_id,obj_ref);
5607 ar->set_is_dap4(
true);
5610 delete structure_ptr;
5614void map_vdata_to_dap4_attrs(
HDFDMRArray_VD *ar, int32 vdata_id, int32 obj_ref) {
5623 nattrs = VSfnattrs (vdata_id, _HDF_VDATA);
5628 for (
int i = 0; i < nattrs; i++) {
5631 char attr_name[H4_MAX_NC_NAME];
5633 int32 attr_type = 0;
5634 int32 attr_count = 0;
5636 status = VSattrinfo (vdata_id, _HDF_VDATA, i, attr_name,
5637 &attr_type, &attr_count, &attrsize);
5638 if (status == FAIL) {
5639 throw InternalErr(__FILE__, __LINE__,
"VSattrinfo failed.");
5643 string tempname(attr_name);
5644 vector<char> attr_value;
5645 attr_value.resize(attrsize);
5647 if (VSgetattr (vdata_id, _HDF_VDATA, i, attr_value.data()) == FAIL) {
5648 throw InternalErr(__FILE__, __LINE__,
"VSgetattr failed.");
5652 map_sds_vdata_attr(ar,dap4_attrname,attr_type,attr_count,attr_value);
5657 add_obj_ref_attr(ar,
false,obj_ref);
5662void convert_sds(int32 file_id, int32 sdfd, int32 vgroup_id, int32 obj_ref, D4Group *d4g, D4Group *root_grp,
const string &filename,
bool is_eos2_grid,
bool is_eos2_grid_cf_mapping) {
5664 int32 sds_index = 0;
5666 vector<char> sds_name;
5667 uint16 name_len = 0;
5670 int32 dim_sizes[H4_MAX_VAR_DIMS];
5671 int32 n_sds_attrs = 0;
5673 sds_index = SDreftoindex(sdfd,obj_ref);
5674 if (sds_index == FAIL) {
5675 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5676 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS index.");
5679 sds_id = SDselect(sdfd,sds_index);
5680 if (sds_id == FAIL) {
5681 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5682 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS ID.");
5685 if (SDgetnamelen(sds_id, &name_len) == FAIL) {
5686 SDendaccess(sds_id);
5687 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5688 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS name length.");
5691 sds_name.resize(name_len+1);
5694 if (FAIL == SDgetinfo (sds_id, sds_name.data(), &sds_rank, dim_sizes, &sds_type, &n_sds_attrs)) {
5695 SDendaccess(sds_id);
5696 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5697 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS ID.");
5700 bool has_zero_dim_size =
false;
5701 for (
int j = 0; j <sds_rank; j++) {
5702 if(dim_sizes[j] == 0) {
5703 has_zero_dim_size =
true;
5708 if (has_zero_dim_size) {
5709 SDendaccess(sds_id);
5713 string sds_name_str(sds_name.begin(),sds_name.end()-1);
5717 BaseType *bt = gen_dap_var(sds_type,sds_name_str, filename);
5718 unsigned int dtype_size = bt->width();
5719 auto ar_unique = make_unique<HDFDMRArray_SDS>(filename, obj_ref, sds_rank,dtype_size,sds_name_str,bt);
5720 auto ar = ar_unique.release();
5725 for (
int dimindex = 0; dimindex < sds_rank; dimindex++) {
5727 int dimid = SDgetdimid (sds_id, dimindex);
5728 if (dimid == FAIL) {
5731 SDendaccess (sds_id);
5732 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5733 throw InternalErr(__FILE__, __LINE__,
"SDgetdimid failed.");
5735 char dim_name[H4_MAX_NC_NAME];
5740 int32 num_dim_attrs = 0;
5742 intn status = SDdiminfo (dimid, dim_name, &dim_size, &dim_type,
5745 if (status == FAIL) {
5748 SDendaccess (sds_id);
5749 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5750 throw InternalErr(__FILE__, __LINE__,
"SDdiminfo failed.");
5753 string dim_name_str (dim_name);
5758 ar->append_dim_ll(dim_sizes[dimindex], dim_name_str);
5761 dims_transform_to_dap4(ar,root_grp,
false);
5765 map_sds_var_dap4_attrs(ar,sds_id,obj_ref,n_sds_attrs);
5770 SDendaccess (sds_id);
5771 close_vgroup_fileids(file_id,sdfd,vgroup_id);
5772 throw InternalErr(__FILE__, __LINE__,
"Map SDS attributes to DAP4 failed.");
5780 string d4_grp_path = d4g->FQN();
5783 string grid_name = first_part_of_full_path(d4_grp_path);
5784 string coordinates =grid_name+
"/Longitude ";
5785 coordinates +=grid_name+
"/Latitude";
5786 add_var_dap4_attr(ar,
"coordinates",attr_str_c,coordinates);
5790 if (is_eos2_grid_cf_mapping) {
5791 string grid_cf_mapping = grid_name+
"/eos_cf_projection";
5792 add_var_dap4_attr(ar,
"grid_mapping",attr_str_c,grid_cf_mapping);
5796 ar->set_is_dap4(
true);
5797 d4g->add_var_nocopy(ar);
5800 SDendaccess(sds_id);
5804void map_sds_var_dap4_attrs(
HDFDMRArray_SDS *ar, int32 sds_id, int32 obj_ref, int32 n_sds_attrs) {
5807 if (SDcheckempty(sds_id,&emptySDS) == FAIL) {
5808 SDendaccess(sds_id);
5809 throw InternalErr(__FILE__, __LINE__,
"SDcheckempty failed.");
5811 bool has_fv_attr =
false;
5813 char attr_name[H4_MAX_NC_NAME];
5814 for (
int attrindex = 0; attrindex < n_sds_attrs; attrindex++) {
5816 int32 sds_attr_type = 0;
5817 int32 attr_value_count = 0;
5818 if (FAIL==SDattrinfo (sds_id, attrindex, attr_name, &sds_attr_type, &attr_value_count))
5819 throw InternalErr(__FILE__,__LINE__,
"SDattrinfo failed ");
5821 vector<char> attr_value;
5822 attr_value.resize(attr_value_count * DFKNTsize(sds_attr_type));
5823 if (SDreadattr (sds_id, attrindex, attr_value.data()) == -1)
5824 throw InternalErr(__FILE__,__LINE__,
"SDreadattr failed ");
5826 string dap4_attrname (attr_name);
5827 if (emptySDS == 1) {
5829 if (dap4_attrname ==
"_FillValue")
5835 map_sds_vdata_attr(ar,dap4_attrname,sds_attr_type,attr_value_count,attr_value);
5840 if (!has_fv_attr && emptySDS == 1)
5841 add_sds_fvalue_attr(ar, sds_id);
5843 add_obj_ref_attr(ar,
true,obj_ref);
5847BaseType * gen_dap_var(int32 h4_type,
const string & h4_str,
const string &filename) {
5849 BaseType * ret_bt =
nullptr;
5854 ret_bt =
new HDFInt16(h4_str,filename);
5859 ret_bt =
new HDFInt32(h4_str,filename);
5864 ret_bt =
new HDFUInt16(h4_str,filename);
5869 ret_bt =
new HDFUInt32(h4_str,filename);
5883 ret_bt =
new HDFInt8(h4_str,filename);
5889 ret_bt =
new HDFByte(h4_str,filename);
5893 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
5901D4AttributeType h4type_to_dap4_attrtype(int32 h4_type) {
5903 D4AttributeType dap4_attr_type = attr_null_c;
5907 dap4_attr_type = attr_str_c;
5911 dap4_attr_type = attr_int8_c;
5915 dap4_attr_type = attr_int16_c;
5919 dap4_attr_type = attr_int32_c;
5924 dap4_attr_type = attr_uint16_c;
5929 dap4_attr_type = attr_uint32_c;
5933 dap4_attr_type = attr_float32_c;
5937 dap4_attr_type = attr_float64_c;
5943 dap4_attr_type = attr_byte_c;
5947 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
5950 return dap4_attr_type;
5955print_dap4_attr(int32 type,
int loc,
void *vals)
5964 unsigned short *usp;
5979 gp.ucp = (
unsigned char *) vals;
5989 gp.cp = (
char *) vals;
5997 string tmp_str =
static_cast<const char*
>(vals);
6004 gp.sp = (
short *) vals;
6005 rep << *(gp.sp+loc);
6012 gp.usp = (
unsigned short *) vals;
6013 rep << *(gp.usp+loc);
6020 gp.lp = (int32 *) vals;
6021 rep << *(gp.lp+loc);
6028 gp.ui = (
unsigned int *) vals;
6029 rep << *(gp.ui+loc);
6035 float attr_val = *(
float*)vals;
6036 bool is_a_fin = isfinite(attr_val);
6037 gp.fp = (
float *) vals;
6042 rep << setprecision(10);
6043 rep << *(gp.fp+loc);
6044 string tmp_rep_str = rep.str();
6045 if (tmp_rep_str.find(
'.') == string::npos
6046 && tmp_rep_str.find(
'e') == string::npos
6047 && tmp_rep_str.find(
'E') == string::npos) {
6048 if(
true == is_a_fin)
6057 double attr_val = *(
double*)vals;
6058 bool is_a_fin = isfinite(attr_val);
6059 gp.dp = (
double *) vals;
6060 rep << std::showpoint;
6061 rep << std::setprecision(17);
6062 rep << *(gp.dp+loc);
6063 string tmp_rep_str = rep.str();
6064 if (tmp_rep_str.find(
'.') == string::npos
6065 && tmp_rep_str.find(
'e') == string::npos
6066 && tmp_rep_str.find(
'E') == string::npos) {
6067 if(
true == is_a_fin)
6078void map_vgroup_attr(D4Group *d4g,
const string &dap4_attrname,int32 attr_type, int32 attr_count, vector<char> & attr_value) {
6080 D4AttributeType dap4_attr_type = h4type_to_dap4_attrtype(attr_type);
6083 if (attr_null_c == dap4_attr_type)
6084 throw InternalErr(__FILE__, __LINE__,
"unsupported DAP4 attribute type");
6087 auto d4_attr_unique = make_unique<D4Attribute>(dap4_attrname, dap4_attr_type);
6088 D4Attribute *d4_attr = d4_attr_unique.release();
6091 if (attr_type == DFNT_CHAR) {
6092 string t_dap4_attr_value(attr_value.begin(),attr_value.end());
6093 auto dap4_attr_value = string(t_dap4_attr_value.c_str());
6094 d4_attr->add_value(dap4_attr_value);
6097 for (
int loc=0; loc < attr_count ; loc++) {
6099 string print_rep = print_dap4_attr(attr_type, loc, (
void*) (attr_value.data()));
6100 if (print_rep.empty())
6101 throw InternalErr(__FILE__,__LINE__,
"Cannot obtain the attribute value for DAP4 ");
6103 d4_attr->add_value(print_rep);
6107 d4g->attributes()->add_attribute_nocopy(d4_attr);
6111void map_sds_vdata_attr(BaseType *d4b,
const string &attr_name,int32 attr_type, int32 attr_count, vector<char> & attr_value) {
6113 D4AttributeType dap4_attr_type = h4type_to_dap4_attrtype(attr_type);
6116 if (attr_null_c == dap4_attr_type)
6117 throw InternalErr(__FILE__, __LINE__,
"unsupported DAP4 attribute type");
6121 string dap4_attrname (attr_name);
6122 auto d4_attr_unique = make_unique<D4Attribute>(dap4_attrname, dap4_attr_type);
6123 D4Attribute *d4_attr = d4_attr_unique.release();
6125 if (attr_type == DFNT_CHAR) {
6126 string t_dap4_attr_value(attr_value.begin(),attr_value.end());
6127 auto dap4_attr_value = string(t_dap4_attr_value.c_str());
6128 d4_attr->add_value(dap4_attr_value);
6131 for (
int loc=0; loc < attr_count ; loc++) {
6133 string print_rep = print_dap4_attr(attr_type, loc, (
void*) (attr_value.data()));
6134 if (print_rep.empty())
6135 throw InternalErr(__FILE__,__LINE__,
"Cannot obtain the attribute value for DAP4 ");
6137 d4_attr->add_value(print_rep);
6141 d4b->attributes()->add_attribute_nocopy(d4_attr);
6145void add_obj_ref_attr(BaseType * d4b,
bool is_sds, int32 obj_ref) {
6148 string obj_ref_attr_name;
6150 obj_ref_attr_name =
"dmr_sds_ref";
6152 obj_ref_attr_name =
"dmr_vdata_ref";
6154 auto d4_obj_ref_attr_unique = make_unique<D4Attribute>(obj_ref_attr_name, attr_int32_c);
6155 D4Attribute *d4_obj_ref_attr = d4_obj_ref_attr_unique.release();
6156 string obj_ref_str = print_dap4_attr(DFNT_INT32, 0,(
void*)&obj_ref);
6157 d4_obj_ref_attr->add_value(obj_ref_str);
6159 d4b->attributes()->add_attribute_nocopy(d4_obj_ref_attr);
6163void add_sds_fvalue_attr(BaseType * d4b, int32 sdsid) {
6166 int32 sds_dtype = 0;
6167 if (FAIL == SDgetinfo (sdsid,
nullptr,
nullptr,
nullptr, &sds_dtype,
nullptr)) {
6169 throw InternalErr(__FILE__, __LINE__,
"Fail to obtain the SDS info.");
6173 switch (sds_dtype) {
6178 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6179 fvalue_str = to_string(fvalue);
6181 fvalue_str = to_string(255);
6187 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6188 fvalue_str = to_string(fvalue);
6190 fvalue_str = to_string(FILL_BYTE);
6196 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6197 fvalue_str = to_string(fvalue);
6199 fvalue_str = to_string(FILL_SHORT);
6205 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6206 fvalue_str = to_string(fvalue);
6208 fvalue_str = to_string(65535);
6214 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6215 fvalue_str = to_string(fvalue);
6217 fvalue_str = to_string(FILL_LONG);
6223 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6224 fvalue_str = to_string(fvalue);
6226 fvalue_str = to_string(4294967295);
6232 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6233 fvalue_str = to_string(fvalue);
6235 fvalue_str = to_string(FILL_FLOAT);
6241 if (SDgetfillvalue(sdsid, &fvalue) == SUCCEED)
6242 fvalue_str = to_string(fvalue);
6244 fvalue_str = to_string(FILL_DOUBLE);
6252 D4AttributeType dap4_attr_type = h4type_to_dap4_attrtype(sds_dtype);
6255 if (attr_null_c == dap4_attr_type)
6256 throw InternalErr(__FILE__, __LINE__,
"unsupported DAP4 attribute type");
6258 auto d4_fvalue_attr_unique = make_unique<D4Attribute>(
"_FillValue", dap4_attr_type);
6259 D4Attribute *d4_fvalue_attr = d4_fvalue_attr_unique.get();
6260 d4_fvalue_attr->add_value(fvalue_str);
6262 d4b->attributes()->add_attribute_nocopy(d4_fvalue_attr_unique.release());
6267void close_vgroup_fileids(int32 fileid, int32 sdfd, int32 vgroup_id) {
6268 if (vgroup_id != FAIL)
6276void add_var_dap4_attr(BaseType *var,
const string& attr_name, D4AttributeType attr_type,
const string& attr_value){
6278 auto d4_attr_unique = make_unique<D4Attribute>(attr_name,attr_type);
6279 auto d4_attr = d4_attr_unique.release();
6280 d4_attr->add_value(attr_value);
6281 var->attributes()->add_attribute_nocopy(d4_attr);
6285int is_group_eos2_grid(
const string& vgroup_name, vector<eos2_grid_t>& eos2_grid_lls) {
6288 for (
int i = 0; i <eos2_grid_lls.size();i++) {
6289 if (vgroup_name==eos2_grid_lls[i].grid_name){
6298void add_eos2_latlon_info(D4Group *d4_grp, D4Group *root_grp,
const eos2_grid_t &eos2_grid,
const eos2_grid_info_t & eos2_grid_info,
const string &filename){
6301 string ydim_path =
"YDim/"+eos2_grid.grid_name;
6303 string xdim_path =
"XDim/"+eos2_grid.grid_name;
6306 int32 proj_code = eos2_grid_info.projcode;
6307 if (proj_code == GCTP_SNSOID || proj_code == GCTP_PS || proj_code == GCTP_LAMAZ) {
6309 add_dummy_grid_cv(d4_grp, eos2_grid, eos2_grid_info);
6311 add_CF_1D_cvs(d4_grp,root_grp,eos2_grid,eos2_grid_info,xdim_path,ydim_path);
6313 string lat_name =
"Latitude";
6314 string lon_name =
"Longitude";
6317 auto ar_bt_lat_unique = make_unique<Float64>(lat_name);
6318 auto ar_bt_lat = ar_bt_lat_unique.get();
6319 auto ar_lat_unique = make_unique<HDFDMRArray_EOS2LL>(filename, eos2_grid.grid_name,
true, lat_name,ar_bt_lat);
6320 auto ar_lat = ar_lat_unique.release();
6323 ar_lat->append_dim_ll(eos2_grid.ydim,ydim_path);
6324 if (!eos2_grid.oned_latlon)
6325 ar_lat->append_dim_ll(eos2_grid.xdim,xdim_path);
6327 ar_lat->set_rank(1);
6329 dims_transform_to_dap4(ar_lat,root_grp,
true);
6332 add_var_dap4_attr(ar_lat,
"units",attr_str_c,
"degrees_north");
6335 string eos_latlon_value = eos2_grid.grid_name +
" lat";
6336 add_var_dap4_attr(ar_lat,
"eos_latlon",attr_str_c,eos_latlon_value);
6338 ar_lat->set_is_dap4(
true);
6339 d4_grp->add_var_nocopy(ar_lat);
6341 auto ar_bt_lon_unique = make_unique<Float64>(lon_name);
6342 auto ar_bt_lon = ar_bt_lon_unique.get();
6343 auto ar_lon_unique = make_unique<HDFDMRArray_EOS2LL>(filename,eos2_grid.grid_name,
false, lon_name, ar_bt_lon);
6344 auto ar_lon = ar_lon_unique.release();
6345 if (!eos2_grid.oned_latlon)
6346 ar_lon->append_dim_ll(eos2_grid.ydim,ydim_path);
6348 ar_lon->set_rank(1);
6349 ar_lon->append_dim_ll(eos2_grid.xdim,xdim_path);
6351 dims_transform_to_dap4(ar_lon,root_grp,
true);
6353 add_var_dap4_attr(ar_lon,
"units",attr_str_c,
"degrees_east");
6356 eos_latlon_value = eos2_grid.grid_name +
" lon";
6357 add_var_dap4_attr(ar_lon,
"eos_latlon",attr_str_c,eos_latlon_value);
6359 ar_lon->set_is_dap4(
true);
6360 d4_grp->add_var_nocopy(ar_lon);
6364#ifdef USE_HDFEOS2_LIB
6365bool check_eos2_grids(
const string &filename, int32 sdfd, vector<eos2_grid_t>& eos2_grid_lls, vector<eos2_grid_info_t>& eos2_grids_info) {
6367 bool ret_value =
true;
6369 string dummy_grid_name;
6370 bool is_eos2_file =
false;
6371 if (1 == check_special_eosfile(filename,dummy_grid_name,sdfd))
6372 is_eos2_file =
true;
6376 vector<string> eos2_grid_names;
6377 ret_value = HDFEOS2::Utility::ReadNamelist(filename.c_str(),GDinqgrid,eos2_grid_names);
6378 if (ret_value ==
false)
6381 for (
const auto& gname:eos2_grid_names) {
6384 bool one_d_ll =
false;
6385 eos2_grid_info_t eg_info;
6386 ret_value = obtain_eos2_gd_ll_info(filename,gname,ydim,xdim,one_d_ll,eg_info);
6387 if (ret_value ==
false)
6391 eg.oned_latlon = one_d_ll;
6394 eg.grid_name = gname;
6395 eos2_grid_lls.push_back(eg);
6396 eos2_grids_info.push_back(eg_info);
6404bool obtain_eos2_gd_ll_info(
const string & fname,
const string & grid_name, int32 &ydim, int32 &xdim,
bool &oned_ll, eos2_grid_info_t &eg_info) {
6406 int32 gfid = GDopen(
const_cast<char*
>(fname.c_str()),DFACC_READ);
6409 int32 gridid = GDattach(gfid,
const_cast < char *
>(grid_name.c_str ()));
6416 int32 projcode = -1;
6421 float64 lowright[2];
6423 if (GDprojinfo (gridid, &projcode, &zone, &sphere, params) == -1) {
6430 if (GDgridinfo(gridid, &xdim, &ydim, upleft,
6437 if (GCTP_CEA == projcode || GCTP_GEO == projcode)
6440 eg_info.projcode = projcode;
6441 eg_info.zone = zone;
6442 eg_info.sphere = sphere;
6443 for (
int i = 0; i<2;i++) {
6444 eg_info.upleft[i] = upleft[i];
6445 eg_info.lowright[i] = lowright[i];
6447 for (
int i = 0; i<16;i++)
6448 eg_info.params[i] = params[i];
6455void add_dummy_grid_cv(D4Group *d4_grp,
const eos2_grid_t & eos2_grid,
const eos2_grid_info_t &eg_info) {
6457 string dummy_proj_cf_name =
"eos_cf_projection";
6458 auto dummy_proj_cf_unique = make_unique<HDFEOS2GeoCFProj>(dummy_proj_cf_name, dummy_proj_cf_name);
6459 HDFEOS2GeoCFProj *dummy_proj_cf = dummy_proj_cf_unique.get();
6460 dummy_proj_cf->set_is_dap4(
true);
6462 if (eg_info.projcode == GCTP_SNSOID) {
6464 add_var_dap4_attr(dummy_proj_cf,
"grid_mapping_name", attr_str_c,
"sinusoidal");
6465 add_var_dap4_attr(dummy_proj_cf,
"longitude_of_central_meridian", attr_float64_c,
"0.0");
6466 add_var_dap4_attr(dummy_proj_cf,
"earth_radius", attr_float64_c,
"6371007.181");
6467 add_var_dap4_attr(dummy_proj_cf,
"_CoordinateAxisTypes", attr_str_c,
"GeoX GeoY");
6468 }
else if (eg_info.projcode == GCTP_PS)
6469 add_ps_cf_grid_mapping_attrs(dummy_proj_cf, eg_info);
6470 else if (eg_info.projcode == GCTP_LAMAZ)
6471 add_lamaz_cf_grid_mapping_attrs(dummy_proj_cf, eg_info);
6473 string eos_cf_grid_value = eos2_grid.grid_name +
" eos_cf_projection";
6474 add_var_dap4_attr(dummy_proj_cf,
"eos_cf_grid_mapping",attr_str_c,eos_cf_grid_value);
6475 d4_grp->add_var_nocopy(dummy_proj_cf_unique.release());
6479void add_CF_1D_cvs(D4Group *d4_grp, D4Group *root_grp,
const eos2_grid_t &eos2_grid,
const eos2_grid_info_t &eos2_grid_info,
const string& xdim_path,
const string &ydim_path) {
6481 auto ar_bt_dim1_unique = make_unique<Float64>(xdim_path);
6482 auto ar_bt_dim1 = ar_bt_dim1_unique.get();
6483 auto ar_dim1_unique = make_unique<HDFEOS2GeoCF1D>(eos2_grid_info.projcode, eos2_grid_info.upleft[0], eos2_grid_info.lowright[0],
6484 eos2_grid.xdim, xdim_path, ar_bt_dim1);
6485 auto ar_dim1 = ar_dim1_unique.get();
6486 ar_dim1->append_dim_ll(eos2_grid.xdim, xdim_path);
6487 dims_transform_to_dap4(ar_dim1,root_grp,
true);
6488 ar_dim1->set_is_dap4(
true);
6489 add_CF_1D_cv_attrs(ar_dim1,
false);
6491 string eos_cf_grid_value = eos2_grid.grid_name +
" XDim";
6492 add_var_dap4_attr(ar_dim1,
"eos_cf_grid",attr_str_c,eos_cf_grid_value);
6493 d4_grp->add_var_nocopy(ar_dim1_unique.release());
6495 auto ar_bt_dim0_unique = make_unique<Float64>(ydim_path);
6496 auto ar_bt_dim0 = ar_bt_dim0_unique.get();
6497 auto ar_dim0_unique = make_unique<HDFEOS2GeoCF1D>(eos2_grid_info.projcode,
6498 eos2_grid_info.upleft[1], eos2_grid_info.lowright[1],
6499 eos2_grid.ydim, ydim_path, ar_bt_dim0);
6500 auto ar_dim0 = ar_dim0_unique.get();
6501 ar_dim0->append_dim_ll(eos2_grid.ydim, ydim_path);
6502 dims_transform_to_dap4(ar_dim0,root_grp,
true);
6504 ar_dim0->set_is_dap4(
true);
6505 add_CF_1D_cv_attrs(ar_dim0,
true);
6507 eos_cf_grid_value = eos2_grid.grid_name +
" YDim";
6508 add_var_dap4_attr(ar_dim0,
"eos_cf_grid",attr_str_c,eos_cf_grid_value);
6510 d4_grp->add_var_nocopy(ar_dim0_unique.release());
6516void add_CF_1D_cv_attrs(libdap::BaseType *var,
bool is_ydim) {
6518 string standard_name;
6520 string COORAxisTypes;
6522 if (
true == is_ydim) {
6523 standard_name =
"projection_y_coordinate";
6524 long_name =
"y coordinate of projection ";
6525 COORAxisTypes =
"GeoY";
6528 standard_name =
"projection_x_coordinate";
6529 long_name =
"x coordinate of projection ";
6530 COORAxisTypes =
"GeoX";
6533 add_var_dap4_attr(var,
"standard_name", attr_str_c, standard_name);
6534 add_var_dap4_attr(var,
"long_name", attr_str_c, long_name);
6535 add_var_dap4_attr(var,
"units", attr_str_c,
"meter");
6536 add_var_dap4_attr(var,
"_CoordinateAxisType", attr_str_c, COORAxisTypes);
6541void add_lamaz_cf_grid_mapping_attrs(libdap::BaseType *var,
const eos2_grid_info_t & eg_info) {
6543 double lon_proj_origin = EHconvAng(eg_info.params[4],HDFE_DMS_DEG);
6544 double lat_proj_origin = EHconvAng(eg_info.params[5],HDFE_DMS_DEG);
6545 double fe = eg_info.params[6];
6546 double fn = eg_info.params[7];
6548 add_var_dap4_attr(var,
"grid_mapping_name", attr_str_c,
"lambert_azimuthal_equal_area");
6551 ostringstream s_lon_proj_origin;
6552 s_lon_proj_origin << lon_proj_origin;
6553 add_var_dap4_attr(var,
"longitude_of_projection_origin", attr_float64_c, s_lon_proj_origin.str());
6555 ostringstream s_lat_proj_origin;
6556 s_lat_proj_origin << lat_proj_origin;
6558 add_var_dap4_attr(var,
"latitude_of_projection_origin", attr_float64_c, s_lat_proj_origin.str());
6561 add_var_dap4_attr(var,
"false_easting",attr_float64_c,
"0.0");
6565 add_var_dap4_attr(var,
"false_easting",attr_float64_c,s_fe.str());
6569 add_var_dap4_attr(var,
"false_northing",attr_float64_c,
"0.0");
6573 add_var_dap4_attr(var,
"false_northing",attr_float64_c,s_fn.str());
6576 add_var_dap4_attr(var,
"_CoordinateAxisTypes", attr_str_c,
"GeoX GeoY");
6580void add_ps_cf_grid_mapping_attrs(libdap::BaseType *var,
const eos2_grid_info_t & eg_info) {
6586 double vert_lon_pole = EHconvAng(eg_info.params[4],HDFE_DMS_DEG);
6589 double lat_true_scale = EHconvAng(eg_info.params[5],HDFE_DMS_DEG);
6592 double fe = eg_info.params[6];
6595 double fn = eg_info.params[7];
6597 add_var_dap4_attr(var,
"grid_mapping_name",attr_str_c,
"polar_stereographic");
6599 ostringstream s_vert_lon_pole;
6600 s_vert_lon_pole << vert_lon_pole;
6604 add_var_dap4_attr(var,
"straight_vertical_longitude_from_pole", attr_float64_c, s_vert_lon_pole.str());
6607 add_var_dap4_attr(var,
"straight_vertical_longitude_from_pole", attr_float64_c, to_string(vert_lon_pole));
6610 ostringstream s_lat_true_scale;
6611 s_lat_true_scale << lat_true_scale;
6612 add_var_dap4_attr(var,
"standard_parallel", attr_float64_c, s_lat_true_scale.str());
6615 add_var_dap4_attr(var,
"false_easting",attr_float64_c,
"0.0");
6619 add_var_dap4_attr(var,
"false_easting",attr_float64_c,s_fe.str());
6623 add_var_dap4_attr(var,
"false_northing",attr_float64_c,
"0.0");
6627 add_var_dap4_attr(var,
"false_northing",attr_float64_c,s_fn.str());
6630 if(lat_true_scale >0)
6631 add_var_dap4_attr(var,
"latitude_of_projection_origin",attr_float64_c,
"+90.0");
6633 add_var_dap4_attr(var,
"latitude_of_projection_origin",attr_float64_c,
"-90.0");
6635 add_var_dap4_attr(var,
"_CoordinateAxisTypes", attr_str_c,
"GeoX GeoY");
6646bool add_sp_hdf4_info(D4Group *d4_grp,
const string &filename,
string &err_msg) {
6648 bool ret_value =
true;
6649 BESDEBUG(
"h4",
"Coming to add_sp_hdf4_info "<<endl);
6651 D4Attributes *d4_attrs = d4_grp->attributes();
6652 if (d4_attrs->find(
"FileHeader")) {
6653 const D4Attribute *d4_attr = d4_attrs->find(
"GridHeader");
6655 string d_attr_value = d4_attr->value(0);
6656 if (d_attr_value.find(
"Origin")!=string::npos)
6657 ret_value = add_sp_hdf4_trmm_info(d4_grp,filename,d4_attr, err_msg);
6666bool add_sp_hdf4_trmm_info(D4Group *d4_grp,
const string& filename,
const D4Attribute *d4_attr,
string &err_msg) {
6668 BESDEBUG(
"h4",
"Coming to add_sp_hdf4_trmm_info "<<endl);
6670 bool ret_value =
true;
6672 D4Dimensions *dims = d4_grp->dims();
6673 string lat_name =
"nlat";
6675 string lon_name =
"nlon";
6679 for (D4Dimensions::D4DimensionsIter di = dims->dim_begin(), de = dims->dim_end(); di != de; ++di) {
6681 if ((*di)->name() ==
"nlat")
6682 lat_size = (
int)((*di)->size());
6683 else if ((*di)->name() ==
"nlon")
6684 lon_size = (
int)((*di)->size());
6687 if ((lat_size !=0) && (lon_size !=0) && num_dims ==2) {
6690 string grid_header_value = d4_attr->value(0);
6691 int lat_size_gh = 0;
6692 int lon_size_gh = 0;
6693 float lat_start = 0;
6694 float lon_start = 0;
6698 vector<char> grid_header_value_vc(grid_header_value.begin(),grid_header_value.end());
6699 HDFCFUtil::parser_trmm_v7_gridheader(grid_header_value_vc,lat_size_gh,lon_size_gh,
6700 lat_start,lon_start,lat_res,lon_res,
false);
6702 if(lat_size != lat_size_gh || lon_size != lon_size_gh) {
6703 err_msg =
"Either the latitude size is not the same as the size retrieved from the gridheader";
6704 err_msg =
" or the longitude size is not the same as the size retrieved from the gridheader\n";
6705 err_msg =
"The lat_size is " + to_string(lat_size) +
'\n';
6706 err_msg =
"The lat_size retrieved from the header is " + to_string(lat_size_gh) +
'\n';
6707 err_msg =
"The lon_size is " + to_string(lon_size) +
'\n';
6708 err_msg =
"The lon_size retrieved from the header is " + to_string(lon_size_gh) +
'\n';
6714 auto ar_bt_lat_unique = make_unique<Float32>(lat_name);
6715 auto ar_bt_lat = ar_bt_lat_unique.get();
6717 auto ar_lat_unique = make_unique<HDFDMRArray_SPLL>(filename, lat_start, lat_res, lat_name,ar_bt_lat);
6718 auto ar_lat = ar_lat_unique.release();
6721 auto ar_lat_unique = make_unique<HDFArray>(lat_name,filename,ar_bt_lat);
6722 auto ar_lat = ar_lat_unique.release();
6726 ar_lat->append_dim_ll(lat_size,lat_name);
6727 dims_transform_to_dap4(ar_lat,d4_grp,
true);
6730 add_var_dap4_attr(ar_lat,
"units",attr_str_c,
"degrees_north");
6734 string grid_header_value = d4_attr->value(0);
6735 int lat_size_gh = 0;
6736 int lon_size_gh = 0;
6737 float lat_start = 0;
6738 float lon_start = 0;
6742 vector<char> grid_header_value_vc(grid_header_value.begin(),grid_header_value.end());
6743 HDFCFUtil::parser_trmm_v7_gridheader(grid_header_value_vc,lat_size_gh,lon_size_gh,
6744 lat_start,lon_start,lat_res,lon_res,
false);
6746 if(lat_size != lat_size_gh || lon_size != lon_size_gh) {
6747 err_msg =
"Either the latitude size is not the same as the size retrieved from the gridheader";
6748 err_msg =
" or the longitude size is not the same as the size retrieved from the gridheader\n";
6749 err_msg =
"The lat_size is " + to_string(lat_size) +
'\n';
6750 err_msg =
"The lat_size retrieved from the header is " + to_string(lat_size_gh) +
'\n';
6751 err_msg =
"The lon_size is " + to_string(lon_size) +
'\n';
6752 err_msg =
"The lon_size retrieved from the header is " + to_string(lon_size_gh) +
'\n';
6759 string sp_h4_value =
"lat " + to_string(lat_start) +
' '+to_string(lat_res);
6760 add_var_dap4_attr(ar_lat,
"sp_h4_ll",attr_str_c,sp_h4_value);
6761 ar_lat->set_is_dap4(
true);
6762 d4_grp->add_var_nocopy(ar_lat);
6764 auto ar_bt_lon_unique = make_unique<Float32>(lon_name);
6765 auto ar_bt_lon = ar_bt_lon_unique.get();
6767 auto ar_lon_unique = make_unique<HDFDMRArray_SPLL>(filename, lon_start,lon_res, lon_name,ar_bt_lon);
6768 auto ar_lon = ar_lon_unique.release();
6771 auto ar_lon_unique = make_unique<HDFArray>(lon_name,filename,ar_bt_lon);
6772 auto ar_lon = ar_lon_unique.release();
6774 ar_lon->append_dim_ll(lon_size,lon_name);
6775 dims_transform_to_dap4(ar_lon,d4_grp,
true);
6777 add_var_dap4_attr(ar_lon,
"units",attr_str_c,
"degrees_east");
6780 sp_h4_value =
"lon " + to_string(lon_start) +
' '+to_string(lon_res);
6781 add_var_dap4_attr(ar_lon,
"sp_h4_ll",attr_str_c,sp_h4_value);
6782 ar_lon->set_is_dap4(
true);
6783 d4_grp->add_var_nocopy(ar_lon);
6791void add_sp_hdf4_additional_info(D4Group *d4_grp) {
6795 D4Group* grid_grp = d4_grp->find_child_grp(
"Grid");
6797 BaseType *hq_prec = grid_grp->find_var(
"HQprecipitation");
6799 add_var_dap4_attr(hq_prec,
"_FillValue",attr_float32_c,
"-9999.9");
6804void dims_transform_to_dap4(Array *ar,D4Group *root_grp,
bool missing_vars) {
6806 D4Dimensions *root_dims = root_grp->dims();
6807 for (Array::Dim_iter d = ar->dim_begin(), e = ar->dim_end(); d != e; ++d) {
6808 if (
false == (*d).name.empty()) {
6809 D4Dimension *d4_dim = root_dims->find_dim((*d).name);
6810 if (d4_dim ==
nullptr) {
6812 auto d4_dim_unique = make_unique<D4Dimension>((*d).name, (*d).size);
6813 d4_dim = d4_dim_unique.release();
6814 root_dims->add_dim_nocopy(d4_dim);
6818 throw InternalErr(__FILE__,__LINE__,
"DAP4 Dimension name should be found. ");
This class provides a way to map HDF4 1-D character array to DAP Str for the CF option.
This class provides a way to map HDFEOS2 character >1D array to DAP Str array for the CF option.
This class provides a way to map HDFEOS2 1-D character array to DAP Str for the CF option.
const char * what() const override
Return exception message.
int32 getType() const
Get the data type of this field.
const std::string & getNewName() const
Get the CF name(special characters replaced by underscores) of this field.
int32 getRank() const
Get the dimension rank of this field.
const std::string & getName() const
Get the name of this field.
static File * Read(const char *path, int32 sdid, int32 fileid)
Retrieve SDS and Vdata information from the HDF4 file.
const std::vector< VDATA * > & getVDATAs() const
Public interface to Obtain Vdata.
const std::vector< AttrContainer * > & getVgattrs() const
Get attributes for all vgroups.
bool Has_Dim_NoScale_Field() const
This file has a field that is a SDS dimension but no dimension scale.
SD * getSD() const
Public interface to Obtain SD.
static File * Read_Hybrid(const char *path, int32 sdid, int32 fileid)
SPType getSPType() const
Obtain special HDF4 product type.
One instance of this class represents one SDS object.
const std::vector< Dimension * > & getCorrectedDimensions() const
Get the list of the corrected dimensions.
const std::vector< Dimension * > & getDimensions() const
Get the list of dimensions.
bool IsDimNoScale() const
Is this field a dimension without dimension scale(or empty[no data]dimension variable)
This class retrieves all SDS objects and SD file attributes.
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain the SD(file) attributes.
const std::vector< SDField * > & getFields() const
Public interface to obtain information of all SDS vectors(objects).
One instance of this class represents one Vdata field.
int32 getFieldOrder() const
Get the order of this field.
bool open(const std::string &filename, const int sd_id, const int file_id)
openes \afilename HDF4 file.
string get_metadata(const std::string &metadataname, bool &suffix_is_num, std::vector< std::string > &non_num_names, std::vector< std::string > &non_num_data)
retrieves the merged metadata.
bool write_attribute(const std::string &gname, const std::string &fname, const std::string &newfname, int n_groups, int fieldtype)
bool write_attribute_coordinates(const std::string &varname, const std::string &coord)
void set_DAS(libdap::DAS *das)
sets DAS pointer so that we can bulid attribute tables.
bool close()
closes the opened file.
bool write_attribute_units(const std::string &varname, const std::string &units)
bool write_attribute_FillValue(const std::string &varname, int type, float val)
void get_value(const std::string &s, std::string &val, bool &found)
Retrieve the value of a given key, if set.
static TheBESKeys * TheKeys()
Access to the singleton.
static std::string print_attr(int32, int, void *)
Print attribute values in string.
static std::string print_type(int32)
Print datatype in string.
static void correct_scale_offset_type(libdap::AttrTable *at)
static std::string get_CF_string(std::string s)
Change special characters to "_".
static void correct_fvalue_type(libdap::AttrTable *at, int32 dtype)