67 #ifdef HAVE_SYS_PARAM_H
68 #include <sys/param.h>
72 #include <sys/types.h>
85 #include <InternalErr.h>
105 #define SIGNED_BYTE_TO_INT32 1
132 #ifdef USE_HDFEOS2_LIB
155 #define ATTR_STRING_QUOTE_FIX
169 struct yy_buffer_state;
174 void AddHDFAttr(DAS & das,
const string & varname,
175 const vector < hdf_attr > &hav);
176 void AddHDFAttr(DAS & das,
const string & varname,
177 const vector < string > &anv);
179 static void build_descriptions(DDS & dds, DAS & das,
180 const string & filename);
181 static void SDS_descriptions(
sds_map & map, DAS & das,
182 const string & filename);
183 static void Vdata_descriptions(
vd_map & map, DAS & das,
184 const string & filename);
185 static void Vgroup_descriptions(DDS & dds, DAS & das,
186 const string & filename,
sds_map & sdmap,
188 static void GR_descriptions(
gr_map & map, DAS & das,
189 const string & filename);
190 static void FileAnnot_descriptions(DAS & das,
const string & filename);
191 static vector < hdf_attr > Pals2Attrs(
const vector < hdf_palette > palv);
192 static vector < hdf_attr > Dims2Attrs(
const hdf_dim dim);
194 void read_das(DAS & das,
const string & filename);
195 void read_dds(DDS & dds,
const string & filename);
224 #ifdef USE_HDFEOS2_LIB
227 void parse_ecs_metadata(DAS &das,
const string & metaname,
const string &metadata);
245 int read_dds_hdfeos2(DDS & dds,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
HDFSP::File*h4file,HDFEOS2::File*eosfile);
248 int 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);
252 void read_dds_hdfeos2_grid_swath(DDS &dds,
const string&filename, HDFEOS2::Dataset *dataset,
int grid_or_swath,
bool ownll,
SOType sotype,
253 int32 sdfd, int32 fileid, int32 gridfd,int32 swathfd)
256 BESDEBUG(
"h4",
"Coming to read_dds_hdfeos2_grid_swath "<<endl);
258 if(grid_or_swath < 0 || grid_or_swath > 1)
259 throw InternalErr(__FILE__, __LINE__,
"The current type should be either grid or swath");
264 vector<struct dimmap_entry> dimmaps;
267 string modis_geofilename=
"";
268 bool geofile_has_dimmap =
false;
272 if(grid_or_swath == 1)
273 HDFCFUtil::obtain_dimmap_info(filename,dataset,dimmaps,modis_geofilename,geofile_has_dimmap);
282 if(0 == grid_or_swath)
284 HDFEOS2::GridDataset *gd =
static_cast<HDFEOS2::GridDataset *
>(dataset);
285 projcode = gd->getProjection().getCode();
291 const vector<HDFEOS2::Field*>& fields = (dataset)->getDataFields();
292 vector<HDFEOS2::Field*> all_fields = fields;
293 vector<HDFEOS2::Field*>::const_iterator it_f;
295 if(1 == grid_or_swath) {
296 HDFEOS2::SwathDataset *sw =
static_cast<HDFEOS2::SwathDataset *
>(dataset);
297 const vector<HDFEOS2::Field*>geofields = sw->getGeoFields();
298 for (it_f = geofields.begin(); it_f != geofields.end(); it_f++)
299 all_fields.push_back(*it_f);
304 for(it_f = all_fields.begin(); it_f != all_fields.end(); it_f++)
306 BESDEBUG(
"h4",
"New field Name " <<(*it_f)->getNewName()<<endl);
311 int fieldtype = (*it_f)->getFieldType();
315 bool changedtype =
false;
317 if ((*i) == (*it_f)->getNewName()){
323 switch((*it_f)->getType())
326 #define HANDLE_CASE2(tid, type) \
328 if(true == changedtype && fieldtype==0) \
329 bt = new (HDFFloat32) ((*it_f)->getNewName(), (dataset)->getName()); \
331 bt = new (type)((*it_f)->getNewName(), (dataset)->getName()); \
334 #define HANDLE_CASE(tid, type)\
336 bt = new (type)((*it_f)->getNewName(), (dataset)->getName()); \
341 #ifndef SIGNED_BYTE_TO_INT32
342 HANDLE_CASE2(DFNT_INT8,
HDFByte);
346 HANDLE_CASE2(DFNT_UINT8,
HDFByte);
351 HANDLE_CASE2(DFNT_UCHAR8,
HDFByte);
353 throw InternalErr(__FILE__,__LINE__,
"unsupported data type.");
360 const vector<HDFEOS2::Dimension*>& dims= (*it_f)->getCorrectedDimensions();
361 vector<HDFEOS2::Dimension*>::const_iterator it_d;
363 if(DFNT_CHAR == (*it_f)->getType()) {
365 if((*it_f)->getRank() >1) {
367 HDFEOS2CFStrField * ar =
NULL;
371 ar =
new HDFEOS2CFStrField(
372 (*it_f)->getRank() -1,
373 (grid_or_swath ==0)?gridfd:swathfd,
375 (dataset)->getName(),
378 (*it_f)->getNewName(),
383 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
385 for(it_d = dims.begin(); it_d != dims.begin()+dims.size()-1; it_d++){
386 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
397 HDFEOS2CFStr * sca_str =
NULL;
400 sca_str =
new HDFEOS2CFStr(
401 (grid_or_swath ==0)?gridfd:swathfd,
403 (dataset)->getName(),
405 (*it_f)->getNewName(),
410 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
412 dds.add_var(sca_str);
420 else if(fieldtype == 0 || fieldtype == 3 || fieldtype == 5) {
423 if(grid_or_swath==0){
424 HDFEOS2Array_RealField *ar =
NULL;
425 ar =
new HDFEOS2Array_RealField(
427 filename,
false,sdfd,gridfd,
428 (dataset)->getName(),
"", (*it_f)->getName(),
430 (*it_f)->getNewName(), bt);
431 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
432 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
438 else if(grid_or_swath==1){
440 string tempfieldname = (*it_f)->getName();
443 if((*it_f)->UseDimMap()) {
446 if (!modis_geofilename.empty()) {
449 if (
true == HDFCFUtil::is_modis_dimmap_nonll_field(tempfieldname)) {
451 if(
false == geofile_has_dimmap) {
458 HDFEOS2Array_RealField *ar =
NULL;
459 ar =
new HDFEOS2Array_RealField(
466 "MODIS_Swath_Type_GEO",
469 (*it_f)->getNewName(),
472 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
473 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
480 HDFEOS2ArraySwathDimMapField * ar =
NULL;
487 ar =
new HDFEOS2ArraySwathDimMapField(
494 "MODIS_Swath_Type_GEO",
498 (*it_f)->getNewName(),
500 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
501 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
509 HDFEOS2ArraySwathDimMapField * ar =
NULL;
515 ar =
new HDFEOS2ArraySwathDimMapField(
522 (dataset)->getName(),
526 (*it_f)->getNewName(),
528 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
529 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
538 HDFEOS2ArraySwathDimMapField * ar =
NULL;
539 ar =
new HDFEOS2ArraySwathDimMapField(
546 (dataset)->getName(),
550 (*it_f)->getNewName(),
552 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
553 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
562 HDFEOS2Array_RealField * ar =
NULL;
563 ar =
new HDFEOS2Array_RealField(
570 (dataset)->getName(),
573 (*it_f)->getNewName(),
575 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
576 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
584 throw InternalErr(__FILE__, __LINE__,
"The current type should be either grid or swath");
589 else if(fieldtype == 1 || fieldtype == 2) {
592 if(grid_or_swath==0) {
594 HDFEOS2ArrayGridGeoField *ar =
NULL;
595 int fieldtype = (*it_f)->getFieldType();
596 bool ydimmajor = (*it_f)->getYDimMajor();
597 bool condenseddim = (*it_f)->getCondensedDim();
598 bool speciallon = (*it_f)->getSpecialLon();
599 int specialformat = (*it_f)->getSpecialLLFormat();
603 ar =
new HDFEOS2ArrayGridGeoField(
614 (dataset)->getName(),
616 (*it_f)->getNewName(),
619 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
620 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
633 if(grid_or_swath ==1) {
636 if((*it_f)->UseDimMap()) {
639 if(!modis_geofilename.empty()) {
641 if (
false == geofile_has_dimmap) {
642 HDFEOS2ArraySwathGeoDimMapExtraField *ar =
NULL;
643 ar =
new HDFEOS2ArraySwathGeoDimMapExtraField(
647 (*it_f)->getNewName(),
649 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
650 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
657 HDFEOS2ArraySwathDimMapField * ar =
NULL;
663 ar =
new HDFEOS2ArraySwathDimMapField(
670 "MODIS_Swath_Type_GEO",
674 (*it_f)->getNewName(),
676 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
677 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
687 HDFEOS2ArraySwathDimMapField * ar =
NULL;
688 ar =
new HDFEOS2ArraySwathDimMapField(
695 (dataset)->getName(),
699 (*it_f)->getNewName(),
701 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
702 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
711 HDFEOS2ArraySwathGeoField * ar =
NULL;
712 ar =
new HDFEOS2ArraySwathGeoField(
716 (dataset)->getName(),
718 (*it_f)->getNewName(),
721 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
722 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
731 else if(fieldtype == 4) {
733 if((*it_f)->getRank()!=1){
735 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
738 int nelem = ((*it_f)->getCorrectedDimensions()[0])->getSize();
739 HDFEOS2ArrayMissGeoField *ar =
NULL;
740 ar =
new HDFEOS2ArrayMissGeoField(
743 (*it_f)->getNewName(),
746 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
747 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
760 int read_dds_hdfeos2(DDS & dds,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
HDFSP::File*spf,HDFEOS2::File*f)
763 BESDEBUG(
"h4",
"Coming to read_dds_hdfeos2 "<<endl);
766 dds.set_dataset_name(
basename(filename));
775 if((
basename(filename).size() >=5) && ((
basename(filename)).compare(0,5,
"MERRA")==0))
779 string check_enable_spec_eos_key=
"H4.EnableSpecialEOS";
780 bool turn_on_enable_spec_eos_key=
false;
783 if(
true == turn_on_enable_spec_eos_key) {
795 if(2 == ret_val || 3 == ret_val) {
801 struct timeval start_time,end_time;
802 gettimeofday(&start_time,
NULL);
814 throw InternalErr(e.
what());
820 gettimeofday(&end_time,
NULL);
822 int total_time_spent = (end_time.tv_sec - start_time.tv_sec)*1000000 +end_time.tv_usec-start_time.tv_usec;
823 cerr<<
"total time spent is "<<total_time_spent<<
"micro seconds "<<endl;
832 if(spf->Check_if_special(grid_name)==
true){
834 special_1d_grid =
true;
841 airs_l2_l3_v6 =
true;
871 struct timeval start_time,end_time;
872 gettimeofday(&start_time,
NULL);
881 f= HDFEOS2::File::Read(filename.c_str(),gridfd,swathfd);
883 catch (HDFEOS2::Exception &e){
888 if (!e.getFileType()){
894 throw InternalErr(e.what());
901 f->Prepare(filename.c_str());
904 catch (HDFEOS2:: Exception &e) {
907 throw InternalErr(e.what());
912 gettimeofday(&end_time,
NULL);
914 int total_time_spent = (end_time.tv_sec - start_time.tv_sec)*1000000 +end_time.tv_usec-start_time.tv_usec;
915 cerr<<
"total time spent is "<<total_time_spent<<
"micro seconds "<<endl;
923 f = HDFEOS2::File::Read(filename.c_str());
924 }
catch (HDFEOS2::Exception &e)
927 if(!e.getFileType()){
932 throw InternalErr(e.what());
937 bool special_1d_grid =
false;
941 if (f->check_special_1d_grid()) {
943 cerr<<
"This is a special 1d grid at the EOS layer" <<endl;
948 myfileid = Hopen(const_cast<char *>(filename.c_str()), DFACC_READ,0);
953 string grid_name = f->get_first_grid_name();
954 cerr<<
"grid name is "<<grid_name <<endl;
956 if(spf->Check_if_special(grid_name)==
true){
957 special_1d_grid =
true;
958 cerr<<
"This is a special 1d grid " <<endl;
967 throw InternalErr(e.
what());
971 }
catch (HDFEOS2::Exception &e)
974 throw InternalErr(e.what());
977 if (
true == special_1d_grid){
978 cerr<<
"special_1d_grid is true "<<endl;
987 catch (HDFEOS2:: Exception &e) {
989 throw InternalErr(e.what());
999 const vector<HDFEOS2::GridDataset *>& grids = f->getGrids();
1001 bool onelatlon = f->getOneLatLon();
1007 vector<HDFEOS2::GridDataset *>::const_iterator it_g;
1008 for(it_g = grids.begin(); it_g != grids.end(); it_g++){
1011 ownll = onelatlon?onelatlon:(*it_g)->getLatLonFlag();
1014 sotype = (*it_g)->getScaleType();
1016 read_dds_hdfeos2_grid_swath(
1017 dds, filename, static_cast<HDFEOS2::Dataset*>(*it_g), 0,ownll,sotype,sdfd,fileid,gridfd,swathfd);
1026 const vector<HDFEOS2::SwathDataset *>& swaths= f->getSwaths();
1027 vector<HDFEOS2::SwathDataset *>::const_iterator it_s;
1028 for(it_s = swaths.begin(); it_s != swaths.end(); it_s++) {
1031 sotype = (*it_s)->getScaleType();
1033 read_dds_hdfeos2_grid_swath(
1034 dds, filename, static_cast<HDFEOS2::Dataset*>(*it_s), 1,
false,sotype,sdfd,fileid,gridfd,swathfd);
1060 BESDEBUG(
"h4",
"Coming to read_dds_hdfhybrid "<<endl);
1062 dds.set_dataset_name(
basename(filename));
1077 throw InternalErr(e.
what());
1085 vector<HDFSP::SDField *>::const_iterator it_g;
1086 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
1103 string check_hybrid_vdata_key=
"H4.EnableHybridVdata";
1104 bool turn_on_hybrid_vdata_key =
false;
1107 if(
true == turn_on_hybrid_vdata_key) {
1112 for(vector<HDFSP::VDATA *>::const_iterator i = f->
getVDATAs().begin(); i!=f->
getVDATAs().end();i++) {
1113 if(
false == (*i)->getTreatAsAttrFlag()){
1114 for(vector<HDFSP::VDField *>::const_iterator j=(*i)->getFields().begin();j!=(*i)->getFields().end();j++) {
1137 BESDEBUG(
"h4",
"Coming to read_das_hdfhybrid "<<endl);
1148 throw InternalErr(e.
what());
1154 string check_scale_offset_type_key =
"H4.EnableCheckScaleOffsetType";
1155 bool turn_on_enable_check_scale_offset_key=
false;
1160 vector<HDFSP::SDField *>::const_iterator it_g;
1161 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
1164 AttrTable *at = das.get_table((*it_g)->getNewName());
1166 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
1169 bool long_name_flag =
false;
1171 for(vector<HDFSP::Attribute *>::const_iterator i=(*it_g)->getAttributes().begin();i!=(*it_g)->getAttributes().end();i++) {
1173 if((*i)->getName() ==
"long_name") {
1174 long_name_flag =
true;
1179 if(
false == long_name_flag)
1180 at->append_attr(
"long_name",
"String", (*it_g)->getName());
1183 for(vector<HDFSP::Attribute *>::const_iterator i=(*it_g)->getAttributes().begin();i!=(*it_g)->getAttributes().end();i++) {
1186 if((*i)->getType()==DFNT_UCHAR || (*i)->getType() == DFNT_CHAR){
1189 string tempstring2((*i)->getValue().begin(),(*i)->getValue().end());
1190 string tempfinalstr= string(tempstring2.c_str());
1195 at->append_attr((*i)->getNewName(),
"String" , ((*i)->getNewName()==
"fullpath")?tempfinalstr:
HDFCFUtil::escattr(tempfinalstr));
1198 for (
int loc=0; loc < (*i)->getCount() ; loc++) {
1208 int32 var_type = (*it_g)->getType();
1223 if (
true == turn_on_enable_check_scale_offset_key && at !=
NULL)
1244 void read_dds_use_eos2lib(DDS & dds,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
HDFSP::File*h4file,HDFEOS2::File*eosfile)
1247 BESDEBUG(
"h4",
"Coming to read_dds_use_eos2lib" <<endl);
1249 int ret_value = read_dds_hdfeos2(dds,filename,sdfd,fileid,gridfd,swathfd,h4file,eosfile);
1251 BESDEBUG(
"h4",
"ret_value of read_dds_hdfeos2 is "<<ret_value<<endl);
1269 if (0 == ret_value || 5 == ret_value || 4 == ret_value ) {
1274 else if ( 1 == ret_value ) {
1287 if(
true == read_dds_hdfeos2(dds, filename)){
1307 void write_non_ecsmetadata_attrs(
HE2CF& cf) {
1314 void write_ecsmetadata(DAS& das,
HE2CF& cf,
const string& _meta)
1333 bool suffix_is_number =
true;
1334 vector<string> meta_nonum_names;
1335 vector<string> meta_nonum_data;
1337 string meta = cf.
get_metadata(_meta,suffix_is_number,meta_nonum_names, meta_nonum_data);
1339 if(
""==meta &&
true == suffix_is_number){
1345 if (
false == suffix_is_number) {
1349 for (
unsigned int i = 0; i <meta_nonum_names.size(); i++)
1350 parse_ecs_metadata(das,meta_nonum_names[i],meta_nonum_data[i]);
1353 parse_ecs_metadata(das,_meta,meta);
1357 void parse_ecs_metadata(DAS &das,
const string & metaname,
const string &metadata) {
1360 AttrTable *at = das.get_table(metaname);
1362 at = das.add_table(metaname,
new AttrTable);
1370 throw Error(
"HDF-EOS parse error while processing a " + metadata +
" HDFEOS attribute.");
1373 if (arg.status() ==
false) {
1375 << metadata <<
" HDFEOS attribute. (2) " << endl;
1383 int read_das_hdfeos2(DAS & das,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
1384 bool ecs_metadata,
HDFSP::File**spfpptr,HDFEOS2::File **fpptr)
1387 BESDEBUG(
"h4",
"Coming to read_das_hdfeos2 " << endl);
1397 if((
basename(filename).size() >=5) && ((
basename(filename)).compare(0,5,
"MERRA")==0)) {
1403 string check_enable_spec_eos_key=
"H4.EnableSpecialEOS";
1404 bool turn_on_enable_spec_eos_key=
false;
1406 if(
true == turn_on_enable_spec_eos_key) {
1415 bool airs_l2_l3_v6 =
false;
1416 bool special_1d_grid =
false;
1419 if(2 == ret_val || 3 == ret_val) {
1425 struct timeval start_time3,end_time3;
1426 gettimeofday(&start_time3,
NULL);
1437 throw InternalErr(e.
what());
1442 gettimeofday(&end_time3,
NULL);
1444 int total_time_spent3 = (end_time3.tv_sec - start_time3.tv_sec)*1000000 +end_time3.tv_usec-start_time3.tv_usec;
1445 cerr<<
"total time spent DAS is "<<total_time_spent3<<
"micro seconds "<<endl;
1454 special_1d_grid =
true;
1459 if(grid_name ==
"mod08") {
1466 airs_l2_l3_v6 =
true;
1479 if (
true == special_1d_grid ||
true == airs_l2_l3_v6) {
1487 HDFEOS2::File *f =
NULL;
1491 f= HDFEOS2::File::Read(filename.c_str(),gridfd,swathfd);
1493 catch (HDFEOS2::Exception &e){
1499 if (!e.getFileType()){
1505 throw InternalErr(e.what());
1512 f->Prepare(filename.c_str());
1515 catch (HDFEOS2:: Exception &e) {
1518 throw InternalErr(e.what());
1528 AttrTable *at = das.get_table(
"HDF_GLOBAL");
1530 at = das.add_table(
"HDF_GLOBAL",
new AttrTable);
1533 for (
int i = 0; i < (int) f->getGrids().size(); i++) {
1535 HDFEOS2::GridDataset* grid = f->getGrids()[i];
1536 string gname = grid->getName();
1537 const vector<HDFEOS2::Attribute *> grid_attrs = grid->getAttributes();
1538 vector<HDFEOS2::Attribute*>::const_iterator it_a;
1539 for (it_a = grid_attrs.begin(); it_a != grid_attrs.end(); ++it_a) {
1541 string attr_name = (*it_a)->getName();
1542 int attr_type = (*it_a)->getType();
1545 if(attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
1546 string tempstring2((*it_a)->getValue().begin(),(*it_a)->getValue().end());
1547 string tempfinalstr= string(tempstring2.c_str());
1557 for (
int loc=0; loc < (*it_a)->getCount() ; loc++) {
1558 string print_rep =
HDFCFUtil::print_attr((*it_a)->getType(), loc, (
void*) &((*it_a)->getValue()[0]));
1567 for (
int i = 0; i < (int) f->getSwaths().size(); i++) {
1569 HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
1570 string gname = swath->getName();
1571 const vector<HDFEOS2::Attribute *> swath_attrs = swath->getAttributes();
1572 vector<HDFEOS2::Attribute*>::const_iterator it_a;
1573 for (it_a = swath_attrs.begin(); it_a != swath_attrs.end(); ++it_a) {
1575 string attr_name = (*it_a)->getName();
1576 int attr_type = (*it_a)->getType();
1579 if(attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
1580 string tempstring2((*it_a)->getValue().begin(),(*it_a)->getValue().end());
1581 string tempfinalstr= string(tempstring2.c_str());
1591 for (
int loc=0; loc < (*it_a)->getCount() ; loc++) {
1592 string print_rep =
HDFCFUtil::print_attr((*it_a)->getType(), loc, (
void*) &((*it_a)->getValue()[0]));
1611 cf.
open(filename,sdfd,fileid);
1624 bool tempstrflag =
false;
1627 bool filename_change_scale =
false;
1628 if (f->getSwaths().size() > 0) {
1629 string temp_fname =
basename(filename);
1630 string temp_prod_prefix =
"AMSR_E";
1631 if ((temp_fname.size() > temp_prod_prefix.size()) &&
1632 (0 == (temp_fname.compare(0,temp_prod_prefix.size(),temp_prod_prefix))))
1633 filename_change_scale =
true;
1637 bool gridname_change_valid_range =
false;
1638 if(1 == f->getGrids().size()) {
1639 string gridname = f->getGrids()[0]->getName();
1640 if (
"VIP_CMG_GRID" == gridname)
1641 gridname_change_valid_range =
true;
1645 bool is_modis_l1b =
false;
1647 for (
int i = 0; i<(int) f->getSwaths().size(); i++) {
1648 HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
1649 string sname = swath->getName();
1650 if(
"MODIS_SWATH_Type_L1B" == sname){
1651 is_modis_l1b =
true;
1656 string check_disable_scale_comp_key =
"H4.DisableScaleOffsetComp";
1657 bool turn_on_disable_scale_comp_key=
false;
1660 string check_scale_offset_type_key =
"H4.EnableCheckScaleOffsetType";
1661 bool turn_on_enable_check_scale_offset_key=
false;
1667 for (
int i = 0; i < (int) f->getGrids().size(); i++) {
1669 HDFEOS2::GridDataset* grid = f->getGrids()[i];
1670 string gname = grid->getName();
1671 sotype = grid->getScaleType();
1673 const vector<HDFEOS2::Field*>gfields = grid->getDataFields();
1674 vector<HDFEOS2::Field*>::const_iterator it_gf;
1676 for (it_gf = gfields.begin();it_gf != gfields.end();++it_gf) {
1678 bool change_fvtype =
false;
1681 string fname = (*it_gf)->getName();
1684 string newfname = (*it_gf)->getNewName();
1686 BESDEBUG(
"h4",
"Original field name: " << fname << endl);
1687 BESDEBUG(
"h4",
"Corrected field name: " << newfname << endl);
1690 int fieldtype = (*it_gf)->getFieldType();
1693 if (fieldtype == 0){
1696 if((*it_gf)->haveAddedFillValue()) {
1697 BESDEBUG(
"h4",
"Has an added fill value." << endl);
1698 float addedfillvalue =
1699 (*it_gf)->getAddedFillValue();
1701 (*it_gf)->getType();
1702 BESDEBUG(
"h4",
"Added fill value = "<<addedfillvalue);
1704 type, addedfillvalue);
1706 string coordinate = (*it_gf)->getCoordinate();
1707 BESDEBUG(
"h4",
"Coordinate attribute: " << coordinate <<endl);
1708 if (coordinate !=
"")
1714 f->getGrids().size(), fieldtype);
1726 if(fieldtype == 1 && ((*it_gf)->getSpecialLLFormat())==3)
1731 if (fieldtype !=3) {
1732 string tempunits = (*it_gf)->getUnits();
1734 "fieldtype " << fieldtype
1735 <<
" units" << tempunits
1742 AttrTable *at = das.get_table(newfname);
1747 bool has_Key_attr =
false;
1748 AttrTable::Attr_iter it = at->attr_begin();
1749 while (it!=at->attr_end())
1751 if(at->get_name(it)==
"Key")
1753 has_Key_attr =
true;
1759 if((
false == is_modis_l1b) && (
false == gridname_change_valid_range)&&(
false == has_Key_attr) && (
true == turn_on_disable_scale_comp_key))
1760 HDFCFUtil::handle_modis_special_attrs_disable_scale_comp(at,
basename(filename),
true, newfname,sotype);
1764 bool changedtype = HDFCFUtil::change_data_type(das,sotype,newfname);
1767 if (
true == changedtype)
1770 HDFCFUtil::handle_modis_special_attrs(at,
basename(filename),
true, newfname,sotype,gridname_change_valid_range,changedtype,change_fvtype);
1776 HDFCFUtil::handle_amsr_attrs(at);
1780 if((
false == change_fvtype) && at !=
NULL) {
1781 int32 var_type = (*it_gf)->getType();
1790 if (
true == turn_on_enable_check_scale_offset_key && at!=
NULL)
1802 for (
int i = 0; i < (int) f->getSwaths().size(); i++) {
1804 HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
1808 const vector<HDFEOS2::Field*> geofields = swath->getGeoFields();
1809 vector<HDFEOS2::Field*> all_fields = geofields;
1810 vector<HDFEOS2::Field*>::const_iterator it_f;
1812 const vector<HDFEOS2::Field*> datafields = swath->getDataFields();
1813 for (it_f = datafields.begin(); it_f != datafields.end(); it_f++)
1814 all_fields.push_back(*it_f);
1816 int total_geofields = geofields.size();
1818 string gname = swath->getName();
1819 BESDEBUG(
"h4",
"Swath name: " << gname << endl);
1821 sotype = swath->getScaleType();
1824 int field_counter = 0;
1826 for(it_f = all_fields.begin(); it_f != all_fields.end(); it_f++)
1828 bool change_fvtype =
false;
1829 string fname = (*it_f)->getName();
1830 string newfname = (*it_f)->getNewName();
1831 BESDEBUG(
"h4",
"Original Field name: " << fname << endl);
1832 BESDEBUG(
"h4",
"Corrected Field name: " << newfname << endl);
1834 int fieldtype = (*it_f)->getFieldType();
1835 if (fieldtype == 0){
1836 string coordinate = (*it_f)->getCoordinate();
1837 BESDEBUG(
"h4",
"Coordinate attribute: " << coordinate <<endl);
1838 if (coordinate !=
"")
1846 if(fieldtype >0 && fieldtype !=3){
1847 string tempunits = (*it_f)->getUnits();
1849 "fieldtype " << fieldtype
1850 <<
" units" << tempunits << endl);
1854 BESDEBUG(
"h4",
"Field Name: " << fname << endl);
1858 if (field_counter >=total_geofields) {
1859 if((*it_f)->haveAddedFillValue()){
1860 float addedfillvalue =
1861 (*it_f)->getAddedFillValue();
1864 BESDEBUG(
"h4",
"Added fill value = "<<addedfillvalue);
1870 f->getSwaths().size(), fieldtype);
1872 AttrTable *at = das.get_table(newfname);
1878 bool has_Key_attr =
false;
1879 AttrTable::Attr_iter it = at->attr_begin();
1880 while (it!=at->attr_end())
1882 if(at->get_name(it)==
"Key")
1884 has_Key_attr =
true;
1890 if((
false == is_modis_l1b) && (
false == gridname_change_valid_range) &&(
false == has_Key_attr) && (
true == turn_on_disable_scale_comp_key))
1891 HDFCFUtil::handle_modis_special_attrs_disable_scale_comp(at,
basename(filename),
false,newfname,sotype);
1895 bool changedtype = HDFCFUtil::change_data_type(das,sotype,newfname);
1898 if (
true == changedtype)
1905 HDFCFUtil::handle_modis_special_attrs(at,
basename(filename),
false,newfname,sotype,gridname_change_valid_range,changedtype,change_fvtype);
1910 HDFCFUtil::handle_amsr_attrs(at);
1914 if((
false == change_fvtype) && at !=
NULL) {
1915 int32 var_type = (*it_f)->getType();
1924 if (
true == turn_on_enable_check_scale_offset_key && at !=
NULL)
1939 if(ecs_metadata ==
true) {
1942 write_ecsmetadata(das,cf,
"CoreMetadata");
1944 write_ecsmetadata(das,cf,
"coremetadata");
1946 write_ecsmetadata(das,cf,
"ArchiveMetadata");
1948 write_ecsmetadata(das,cf,
"archivemetadata");
1950 write_ecsmetadata(das,cf,
"ProductMetadata");
1952 write_ecsmetadata(das,cf,
"productmetadata");
1956 if(
false == tempstrflag) {
1958 string check_disable_smetadata_key =
"H4.DisableStructMetaAttr";
1959 bool is_check_disable_smetadata =
false;
1962 if (
false == is_check_disable_smetadata) {
1963 write_ecsmetadata(das, cf,
"StructMetadata");
1968 write_non_ecsmetadata_attrs(cf);
1980 string check_enable_sg_attr_key=
"H4.EnableSwathGridAttr";
1981 bool turn_on_enable_sg_attr_key=
false;
1984 if(
true == turn_on_enable_sg_attr_key) {
1987 for (
int i = 0; i < (int) f->getGrids().size(); i++) {
1990 HDFEOS2::GridDataset* grid = f->getGrids()[i];
1994 AttrTable*at =
NULL;
1997 if(grid->getAttributes().size() != 0) {
1998 at = das.get_table(gname);
2000 at = das.add_table(gname,
new AttrTable);
2004 const vector<HDFEOS2::Attribute *> grid_attrs = grid->getAttributes();
2005 vector<HDFEOS2::Attribute*>::const_iterator it_a;
2006 for (it_a = grid_attrs.begin(); it_a != grid_attrs.end(); ++it_a) {
2008 int attr_type = (*it_a)->getType();
2011 if(attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
2012 string tempstring2((*it_a)->getValue().begin(),(*it_a)->getValue().end());
2013 string tempfinalstr= string(tempstring2.c_str());
2023 for (
int loc=0; loc < (*it_a)->getCount() ; loc++) {
2024 string print_rep =
HDFCFUtil::print_attr((*it_a)->getType(), loc, (
void*) &((*it_a)->getValue()[0]));
2033 for (
int i = 0; i < (int) f->getSwaths().size(); i++) {
2035 HDFEOS2::SwathDataset* swath = f->getSwaths()[i];
2036 string sname = swath->getName();
2037 AttrTable*at =
NULL;
2040 if(swath->getAttributes().size() != 0) {
2041 at = das.get_table(sname);
2043 at = das.add_table(sname,
new AttrTable);
2046 const vector<HDFEOS2::Attribute *> swath_attrs = swath->getAttributes();
2047 vector<HDFEOS2::Attribute*>::const_iterator it_a;
2048 for (it_a = swath_attrs.begin(); it_a != swath_attrs.end(); ++it_a) {
2050 int attr_type = (*it_a)->getType();
2053 if(attr_type==DFNT_UCHAR || attr_type == DFNT_CHAR){
2054 string tempstring2((*it_a)->getValue().begin(),(*it_a)->getValue().end());
2055 string tempfinalstr= string(tempstring2.c_str());
2065 for (
int loc=0; loc < (*it_a)->getCount() ; loc++) {
2066 string print_rep =
HDFCFUtil::print_attr((*it_a)->getType(), loc, (
void*) &((*it_a)->getValue()[0]));
2087 void read_das_use_eos2lib(DAS & das,
const string & filename,
2088 int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
bool ecs_metadata,
2089 HDFSP::File**h4filepptr,HDFEOS2::File**eosfilepptr)
2092 BESDEBUG(
"h4",
"Coming to read_das_use_eos2lib" << endl);
2094 int ret_value = read_das_hdfeos2(das,filename,sdfd,fileid, gridfd, swathfd,ecs_metadata,h4filepptr,eosfilepptr);
2096 BESDEBUG(
"h4",
"ret_value of read_das_hdfeos2 is "<<ret_value <<endl);
2113 if (ret_value == 4) {
2118 else if (ret_value == 2 || ret_value == 3) {
2121 else if (ret_value == 1) {
2128 if(
true ==
read_das_hdfsp(das, filename,sdfd, fileid,h4filepptr))
2136 if(
true == read_das_hdfeos2(das, filename)){
2154 #endif // #ifdef USE_HDFEOS2_LIB
2161 BESDEBUG(
"h4",
"Coming to read_dds_sp "<<endl);
2162 dds.set_dataset_name(
basename(filename));
2174 throw InternalErr(e.
what());
2184 throw InternalErr(e.
what());
2192 vector<HDFSP::SDField *>::const_iterator it_g;
2193 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
2199 if (
false == f->
Has_Dim_NoScale_Field() || (0 == (*it_g)->getFieldType()) || (
true == (*it_g)->IsDimScale())){
2212 string check_ceres_vdata_key=
"H4.EnableCERESVdata";
2213 bool turn_on_ceres_vdata_key=
false;
2216 bool output_vdata_flag =
true;
2217 if (
false == turn_on_ceres_vdata_key &&
2222 output_vdata_flag =
false;
2228 if(
true == output_vdata_flag) {
2229 for(vector<HDFSP::VDATA *>::const_iterator i=f->
getVDATAs().begin(); i!=f->
getVDATAs().end();i++) {
2230 if(!(*i)->getTreatAsAttrFlag()){
2231 for(vector<HDFSP::VDField *>::const_iterator j=(*i)->getFields().begin();j!=(*i)->getFields().end();j++) {
2254 BESDEBUG(
"h4",
"Coming to read_das_sp "<<endl);
2267 throw InternalErr(e.
what());
2277 throw InternalErr(e.
what());
2282 string check_enable_vg_attr_key=
"H4.EnableVgroupAttr";
2283 bool turn_on_enable_vg_attr_key=
false;
2288 string check_ceres_vdata_key=
"H4.EnableCERESVdata";
2289 bool turn_on_ceres_vdata_key=
false;
2292 bool output_vdata_flag =
true;
2293 if (
false == turn_on_ceres_vdata_key &&
2298 output_vdata_flag =
false;
2303 if(
true == turn_on_enable_vg_attr_key ) {
2306 vector<HDFSP::AttrContainer *>vg_container = f->
getVgattrs();
2307 for(vector<HDFSP::AttrContainer *>::const_iterator i=f->
getVgattrs().begin();i!=f->
getVgattrs().end();i++) {
2308 AttrTable *vgattr_at = das.get_table((*i)->getName());
2310 vgattr_at = das.add_table((*i)->getName(),
new AttrTable);
2312 for(vector<HDFSP::Attribute *>::const_iterator j=(*i)->getAttributes().begin();j!=(*i)->getAttributes().end();j++) {
2315 if((*j)->getType()==DFNT_UCHAR || (*j)->getType() == DFNT_CHAR){
2316 string tempstring2((*j)->getValue().begin(),(*j)->getValue().end());
2317 string tempfinalstr= string(tempstring2.c_str());
2320 vgattr_at->append_attr((*j)->getNewName(),
"String" ,
HDFCFUtil::escattr(tempfinalstr));
2323 for (
int loc=0; loc < (*j)->getCount() ; loc++) {
2334 string core_metadata =
"";
2335 string archive_metadata =
"";
2336 string struct_metadata =
"";
2347 if(((*i)->getName().compare(0, 12,
"CoreMetadata" )== 0) ||
2348 ((*i)->getName().compare(0, 12,
"coremetadata" )== 0)){
2353 string tempstring((*i)->getValue().begin(),(*i)->getValue().end());
2360 core_metadata.append(tempstring);
2362 else if(((*i)->getName().compare(0, 15,
"ArchiveMetadata" )== 0) ||
2363 ((*i)->getName().compare(0, 16,
"ArchivedMetadata")==0) ||
2364 ((*i)->getName().compare(0, 15,
"archivemetadata" )== 0)){
2365 string tempstring((*i)->getValue().begin(),(*i)->getValue().end());
2370 archive_metadata.append(tempstring);
2372 else if(((*i)->getName().compare(0, 14,
"StructMetadata" )== 0) ||
2373 ((*i)->getName().compare(0, 14,
"structmetadata" )== 0)){
2375 string check_disable_smetadata_key =
"H4.DisableStructMetaAttr";
2376 bool is_check_disable_smetadata =
false;
2379 if (
false == is_check_disable_smetadata) {
2381 string tempstring((*i)->getValue().begin(),(*i)->getValue().end());
2389 struct_metadata.append(tempstring);
2395 AttrTable *at = das.get_table(
"HDF_GLOBAL");
2397 at = das.add_table(
"HDF_GLOBAL",
new AttrTable);
2400 if((*i)->getType()==DFNT_UCHAR || (*i)->getType() == DFNT_CHAR){
2401 string tempstring2((*i)->getValue().begin(),(*i)->getValue().end());
2402 string tempfinalstr= string(tempstring2.c_str());
2411 for (
int loc=0; loc < (*i)->getCount() ; loc++) {
2425 if(core_metadata.size() > 0){
2426 AttrTable *at = das.get_table(
"CoreMetadata");
2428 at = das.add_table(
"CoreMetadata",
new AttrTable);
2436 throw Error(
"Parse error while processing a CoreMetadata attribute.");
2440 if (arg.status() ==
false) {
2442 (*
BESLog::TheLog()) <<
"Parse error while processing a CoreMetadata attribute. (2) " << endl;
2450 if(archive_metadata.size() > 0){
2451 AttrTable *at = das.get_table(
"ArchiveMetadata");
2453 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
2460 throw Error(
"Parse error while processing an ArchiveMetadata attribute.");
2464 if (arg.status() ==
false) {
2465 (*
BESLog::TheLog())<<
"Parse error while processing an ArchiveMetadata attribute. (2) " << endl;
2473 if(struct_metadata.size() > 0){
2474 AttrTable *at = das.get_table(
"StructMetadata");
2476 at = das.add_table(
"StructMetadata",
new AttrTable);
2483 throw Error(
"Parse error while processing a StructMetadata attribute.");
2486 if (arg.status() ==
false) {
2487 (*
BESLog::TheLog())<<
"Parse error while processing a StructMetadata attribute. (2)" << endl;
2493 if (arg.status() ==
false) {
2494 (*
BESLog::TheLog())<<
"Parse error while processing a StructMetadata attribute. (2)" << endl
2495 << arg.error()->get_error_message() << endl;
2508 bool global_slope_flag =
false;
2509 float intercept = 0.;
2510 bool global_intercept_flag =
false;
2518 vector<HDFSP::SDField *>::const_iterator it_g;
2519 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
2526 ((*it_g)->getFieldType() !=0)&&
2527 ((*it_g)->IsDimScale() ==
false))
2534 AttrTable *at = das.get_table((*it_g)->getNewName());
2536 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
2539 bool long_name_flag =
false;
2541 for(vector<HDFSP::Attribute *>::const_iterator i=(*it_g)->getAttributes().begin();
2542 i!=(*it_g)->getAttributes().end();i++) {
2544 if((*i)->getName() ==
"long_name") {
2545 long_name_flag =
true;
2550 if(
false == long_name_flag) {
2552 if((*it_g)->getFieldType() == 1)
2553 at->append_attr(
"standard_name",
"String",
"latitude");
2554 else if ((*it_g)->getFieldType() == 2) {
2555 at->append_attr(
"standard_name",
"String",
"longitude");
2561 if((*it_g)->getFieldType() == 1) {
2562 at->append_attr(
"long_name",
"String",
"latitude");
2563 at->append_attr(
"standard_name",
"String",
"latitude");
2566 else if ((*it_g)->getFieldType() == 2) {
2567 at->append_attr(
"long_name",
"String",
"longitude");
2568 at->append_attr(
"standard_name",
"String",
"longitude");
2573 at->append_attr(
"long_name",
"String", (*it_g)->getName());
2582 for(vector<HDFSP::Attribute *>::const_iterator i=(*it_g)->getAttributes().begin();i!=(*it_g)->getAttributes().end();i++) {
2585 if((*i)->getType()==DFNT_UCHAR || (*i)->getType() == DFNT_CHAR){
2586 string tempstring2((*i)->getValue().begin(),(*i)->getValue().end());
2587 string tempfinalstr= string(tempstring2.c_str());
2593 at->append_attr((*i)->getNewName(),
"String" ,((*i)->getNewName()==
"fullpath")?tempfinalstr:
HDFCFUtil::escattr(tempfinalstr));
2596 for (
int loc=0; loc < (*i)->getCount() ; loc++) {
2612 bool has_dim_info =
true;
2613 vector<HDFSP::AttrContainer *>::const_iterator it_end = (*it_g)->getDimInfo().end();
2614 if((*it_g)->getType() == DFNT_CHAR) {
2615 if((*it_g)->getRank() >1 && (*it_g)->getDimInfo().size() >1)
2616 it_end = (*it_g)->getDimInfo().begin()+(*it_g)->getDimInfo().size() -1;
2618 has_dim_info =
false;
2621 if(
true == has_dim_info) {
2622 for(vector<HDFSP::AttrContainer *>::const_iterator i=(*it_g)->getDimInfo().begin();i!=it_end;i++) {
2626 string attr_container_name = (*it_g)->getNewName() + (*i)->getName();
2627 AttrTable *dim_at = das.get_table(attr_container_name);
2629 dim_at = das.add_table(attr_container_name,
new AttrTable);
2631 for(vector<HDFSP::Attribute *>::const_iterator j=(*i)->getAttributes().begin();j!=(*i)->getAttributes().end();j++) {
2634 if((*j)->getType()==DFNT_UCHAR || (*j)->getType() == DFNT_CHAR){
2635 string tempstring2((*j)->getValue().begin(),(*j)->getValue().end());
2636 string tempfinalstr= string(tempstring2.c_str());
2639 dim_at->append_attr((*j)->getNewName(),
"String" ,
HDFCFUtil::escattr(tempfinalstr));
2642 for (
int loc=0; loc < (*j)->getCount() ; loc++) {
2655 if((*it_g)->getFieldType() == 1){
2657 at->del_attr(
"units");
2658 at->append_attr(
"units",
"String",(*it_g)->getUnits());
2660 at->del_attr(
"valid_range");
2665 if((*it_g)->getFieldType() == 2){
2666 at->del_attr(
"units");
2667 at->append_attr(
"units",
"String",(*it_g)->getUnits());
2669 at->del_attr(
"valid_range");
2675 if((*it_g)->getFieldType() == 4){
2676 at->del_attr(
"units");
2677 at->append_attr(
"units",
"String",(*it_g)->getUnits());
2681 if((*it_g)->getFieldType() == 0){
2682 at->del_attr(
"coordinates");
2686 string coordinate = (*it_g)->getCoordinate();
2687 if (coordinate !=
"")
2688 at->append_attr(
"coordinates",
"String", coordinate);
2700 string check_scale_offset_type_key =
"H4.EnableCheckScaleOffsetType";
2701 bool turn_on_enable_check_scale_offset_key=
false;
2706 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
2708 AttrTable *at = das.get_table((*it_g)->getNewName());
2710 int32 var_type = (*it_g)->getType();
2725 if (
true == turn_on_enable_check_scale_offset_key && at !=
NULL)
2757 BESDEBUG(
"h4",
"Coming to read_das_special_eos2 " << endl);
2762 myfileid = Hopen(const_cast<char *>(filename.c_str()), DFACC_READ,0);
2776 throw InternalErr(e.
what());
2786 throw InternalErr(e.
what());
2808 BESDEBUG(
"h4",
"Coming to read_das_special_eos2_core "<<endl);
2810 string core_metadata =
"";
2811 string archive_metadata =
"";
2812 string struct_metadata =
"";
2821 if(((*i)->getName().compare(0, 12,
"CoreMetadata" )== 0) ||
2822 ((*i)->getName().compare(0, 12,
"coremetadata" )== 0)){
2824 if(ecs_metadata ==
true) {
2828 string tempstring((*i)->getValue().begin(),(*i)->getValue().end());
2829 core_metadata.append(tempstring);
2832 else if(((*i)->getName().compare(0, 15,
"ArchiveMetadata" )== 0) ||
2833 ((*i)->getName().compare(0, 16,
"ArchivedMetadata")==0) ||
2834 ((*i)->getName().compare(0, 15,
"archivemetadata" )== 0)){
2835 if(ecs_metadata ==
true) {
2836 string tempstring((*i)->getValue().begin(),(*i)->getValue().end());
2837 archive_metadata.append(tempstring);
2840 else if(((*i)->getName().compare(0, 14,
"StructMetadata" )== 0) ||
2841 ((*i)->getName().compare(0, 14,
"structmetadata" )== 0))
2845 AttrTable *at = das.get_table(
"HDF_GLOBAL");
2847 at = das.add_table(
"HDF_GLOBAL",
new AttrTable);
2850 if((*i)->getType()==DFNT_UCHAR || (*i)->getType() == DFNT_CHAR){
2851 string tempstring2((*i)->getValue().begin(),(*i)->getValue().end());
2852 string tempfinalstr= string(tempstring2.c_str());
2861 for (
int loc=0; loc < (*i)->getCount() ; loc++) {
2874 if(ecs_metadata ==
true) {
2876 if(core_metadata.size() > 0){
2877 AttrTable *at = das.get_table(
"CoreMetadata");
2879 at = das.add_table(
"CoreMetadata",
new AttrTable);
2886 throw Error(
"Parse error while processing a CoreMetadata attribute.");
2890 if (arg.status() ==
false) {
2891 (*
BESLog::TheLog()) <<
"Parse error while processing a CoreMetadata attribute. (2)" << endl;
2900 if(archive_metadata.size() > 0){
2901 AttrTable *at = das.get_table(
"ArchiveMetadata");
2903 at = das.add_table(
"ArchiveMetadata",
new AttrTable);
2909 throw Error(
"Parse error while processing an ArchiveMetadata attribute.");
2913 if (arg.status() ==
false) {
2914 (*
BESLog::TheLog())<<
"Parse error while processing an ArchiveMetadata attribute. (2)" << endl;
2924 vector<HDFSP::SDField *>::const_iterator it_g;
2925 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
2929 if((*it_g)->getFieldType() != 0){
2931 AttrTable *at = das.get_table((*it_g)->getNewName());
2933 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
2935 string tempunits = (*it_g)->getUnits();
2936 if(at->simple_find(
"units")== at->attr_end() && tempunits!=
"")
2937 at->append_attr(
"units",
"String" ,tempunits);
2938 if((*it_g)->getFieldType() == 1){
2939 if(at->simple_find(
"long_name")== at->attr_end())
2940 at->append_attr(
"long_name",
"String",
"Latitude");
2942 else if((*it_g)->getFieldType() == 2) {
2943 if(at->simple_find(
"long_name")== at->attr_end())
2944 at->append_attr(
"long_name",
"String",
"Longitude");
2948 AttrTable *at = das.get_table((*it_g)->getNewName());
2950 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
2951 string tempcoors = (*it_g)->getCoordinate();
2954 at->del_attr(
"coordinates");
2955 at->append_attr(
"coordinates",
"String",tempcoors);
2961 if((*it_g)->getAttributes().size() == 0)
2964 AttrTable *at = das.get_table((*it_g)->getNewName());
2966 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
2969 for(vector<HDFSP::Attribute *>::const_iterator i=(*it_g)->getAttributes().begin();i!=(*it_g)->getAttributes().end();i++) {
2972 if((*i)->getType()==DFNT_UCHAR || (*i)->getType() == DFNT_CHAR){
2973 string tempstring2((*i)->getValue().begin(),(*i)->getValue().end());
2974 string tempfinalstr= string(tempstring2.c_str());
2980 at->append_attr((*i)->getNewName(),
"String" ,((*i)->getNewName()==
"fullpath")?tempfinalstr:
HDFCFUtil::escattr(tempfinalstr));
2983 for (
int loc=0; loc < (*i)->getCount() ; loc++) {
3000 vector<HDFSP::SDField *>::const_iterator it_g;
3001 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
3002 if((*it_g)->getFieldType() == 0){
3003 AttrTable *at = das.get_table((*it_g)->getNewName());
3005 at = das.add_table((*it_g)->getNewName(),
new AttrTable);
3008 string add_offset_type;
3011 string add_offset_value=
"0";
3012 double orig_offset_value = 0;
3013 bool add_offset_modify =
false;
3019 AttrTable::Attr_iter it = at->attr_begin();
3020 while (it!=at->attr_end())
3022 if(at->get_name(it)==
"add_offset")
3024 add_offset_value = (*at->get_attr_vector(it)->begin());
3025 orig_offset_value = atof(add_offset_value.c_str());
3026 add_offset_type = at->get_type(it);
3027 if(add_offset_value ==
"0.0" || orig_offset_value == 0)
3028 add_offset_modify =
false;
3030 add_offset_modify =
true;
3038 if(
true == add_offset_modify) {
3041 string scale_factor_type;
3044 string scale_factor_value=
"";
3045 double orig_scale_value = 1;
3047 it = at->attr_begin();
3048 while (it!=at->attr_end())
3050 if(at->get_name(it)==
"scale_factor")
3052 scale_factor_value = (*at->get_attr_vector(it)->begin());
3053 orig_scale_value = atof(scale_factor_value.c_str());
3054 scale_factor_type = at->get_type(it);
3059 if(scale_factor_value.length() !=0) {
3060 double new_offset_value = -1 * orig_scale_value*orig_offset_value;
3062 at->del_attr(
"add_offset");
3076 BESDEBUG(
"h4",
"Coming to read_dds_special_1d_grid "<<endl);
3079 const vector<HDFSP::SDField *>& spsds = spf->
getSD()->
getFields();
3082 vector<HDFSP::SDField *>::const_iterator it_g;
3083 for(it_g = spsds.begin(); it_g != spsds.end(); it_g++){
3086 switch((*it_g)->getType()) {
3087 #define HANDLE_CASE(tid, type) \
3089 bt = new (type)((*it_g)->getNewName(),filename); \
3094 #ifndef SIGNED_BYTE_TO_INT32
3106 InternalErr(__FILE__,__LINE__,
"unsupported data type.");
3113 const vector<HDFSP::Dimension*>& dims= (*it_g)->getDimensions();
3115 vector<HDFSP::Dimension*>::const_iterator it_d;
3116 if(DFNT_CHAR == (*it_g)->getType()) {
3118 if(1 == (*it_g)->getRank()) {
3124 (*it_g)->getFieldRef(),
3127 (*it_g)->getNewName(),
3133 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
3135 dds.add_var(sca_str);
3145 (*it_g)->getRank() -1 ,
3149 (*it_g)->getFieldRef(),
3152 (*it_g)->getNewName(),
3158 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStrField instance.");
3161 for(it_d = dims.begin(); it_d != dims.begin()+dims.size()-1; it_d++)
3162 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3172 if((*it_g)->getFieldType() != 4) {
3180 (*it_g)->getFieldRef(),
3184 (*it_g)->getNewName(),
3189 InternalErr(__FILE__,__LINE__,
"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());
3198 if((*it_g)->getRank()!=1){
3200 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
3202 int nelem = ((*it_g)->getDimensions()[0])->getSize();
3210 (*it_g)->getNewName(),
3215 InternalErr(__FILE__,__LINE__,
3216 "Unable to allocate the HDFSPArrayMissGeoField instance.");
3220 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3221 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3239 BESDEBUG(
"h4",
"Coming to read_dds_spfields "<<endl);
3247 #define HANDLE_CASE(tid, type) \
3249 bt = new (type)(spsds->getNewName(),filename); \
3254 #ifndef SIGNED_BYTE_TO_INT32
3268 InternalErr(__FILE__,__LINE__,
"unsupported data type.");
3277 vector<HDFSP::Dimension*>::const_iterator it_d;
3279 if(DFNT_CHAR == spsds->
getType()) {
3298 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
3300 dds.add_var(sca_str);
3322 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStrField instance.");
3325 for(it_d = dims.begin(); it_d != dims.begin()+dims.size()-1; it_d++)
3326 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3335 else if(fieldtype == 0 || fieldtype == 3 ) {
3353 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFSPArray_RealField instance.");
3356 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3357 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3364 else if(fieldtype == 1 || fieldtype == 2) {
3384 InternalErr(__FILE__,__LINE__,
3385 "Unable to allocate the HDFSPArray_RealField instance.");
3389 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3390 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3415 InternalErr(__FILE__,__LINE__,
3416 "Unable to allocate the HDFSPArray_RealField instance.");
3419 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3420 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3428 else if(fieldtype == 4) {
3431 throw InternalErr(__FILE__, __LINE__,
"The rank of missing Z dimension field must be 1");
3446 InternalErr(__FILE__,__LINE__,
3447 "Unable to allocate the HDFSPArrayMissGeoField instance.");
3451 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3452 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3459 else if(fieldtype == 6) {
3463 throw InternalErr(__FILE__, __LINE__,
"The rank of added coordinate variable must be 1");
3479 InternalErr(__FILE__,__LINE__,
3480 "Unable to allocate the HDFSPArrayAddCVField instance.");
3484 for(it_d = dims.begin(); it_d != dims.end(); it_d++)
3485 ar->append_dim((*it_d)->getSize(), (*it_d)->getName());
3499 BESDEBUG(
"h4",
"Coming to read_dds_spvdfields "<<endl);
3504 #define HANDLE_CASE(tid, type) \
3506 bt = new (type)(spvd->getNewName(),filename); \
3511 #ifndef SIGNED_BYTE_TO_INT32
3525 InternalErr(__FILE__,__LINE__,
"unsupported data type.");
3532 if(DFNT_CHAR == spvd->
getType()) {
3553 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStr instance.");
3555 dds.add_var(sca_str);
3579 InternalErr(__FILE__,__LINE__,
"Unable to allocate the HDFCFStrField instance.");
3582 string dimname0 =
"VDFDim0_"+spvd->
getNewName();
3583 ar->append_dim(numrec, dimname0);
3608 string dimname1 =
"VDFDim0_"+spvd->
getNewName();
3610 string dimname2 =
"VDFDim1_"+spvd->
getNewName();
3612 ar->append_dim(numrec,dimname1);
3616 ar->append_dim(numrec,dimname1);
3633 int32 n_sd_attrs = 0;
3634 bool is_eos =
false;
3638 sdid = SDstart (const_cast < char *>(filename.c_str ()), DFACC_READ);
3640 throw InternalErr(__FILE__, __LINE__,
"The SD interface cannot be open.");
3644 if (SDfileinfo (sdfd, &n_sds, &n_sd_attrs) == FAIL){
3645 throw InternalErr (__FILE__,__LINE__,
"SDfileinfo failed ");
3648 char attr_name[H4_MAX_NC_NAME];
3649 int32 attr_type = -1;
3650 int32 attr_count = -1;
3651 char structmdname[] =
"StructMetadata.0";
3654 for (
int attr_index = 0; attr_index < n_sd_attrs;attr_index++) {
3655 if(SDattrinfo(sdfd,attr_index,attr_name,&attr_type,&attr_count) == FAIL) {
3656 throw InternalErr (__FILE__,__LINE__,
"SDattrinfo failed ");
3659 if(strcmp(attr_name,structmdname)==0) {
3665 if(
true == is_eos) {
3669 int32 dim_sizes[H4_MAX_VAR_DIMS];
3670 int32 sds_dtype = 0;
3671 int32 n_sds_attrs = 0;
3672 char sds_name[H4_MAX_NC_NAME];
3673 char xdim_name[] =
"XDim";
3674 char ydim_name[] =
"YDim";
3676 string temp_grid_name1;
3677 string temp_grid_name2;
3678 bool xdim_is_cv_flag =
false;
3679 bool ydim_is_cv_flag =
false;
3683 for (sds_index = 0; sds_index < (int)n_sds; sds_index++) {
3685 sds_id = SDselect (sdfd, sds_index);
3686 if (sds_id == FAIL) {
3687 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3691 int status = SDgetinfo (sds_id, sds_name, &sds_rank, dim_sizes,
3692 &sds_dtype, &n_sds_attrs);
3693 if (status == FAIL) {
3694 SDendaccess(sds_id);
3695 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3701 if(strcmp(sds_name,xdim_name) == 0) {
3702 int32 sds_dimid = SDgetdimid(sds_id,0);
3703 if(sds_dimid == FAIL) {
3704 SDendaccess(sds_id);
3705 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3707 char dim_name[H4_MAX_NC_NAME];
3710 int32 num_dim_attrs = 0;
3711 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3712 SDendaccess(sds_id);
3713 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3718 string tempdimname(dim_name);
3719 if(tempdimname.size() >=5) {
3720 if(tempdimname.compare(0,5,
"XDim:") == 0) {
3723 temp_grid_name1 = tempdimname.substr(5);
3724 xdim_is_cv_flag =
true;
3728 else if(
"XDim" == tempdimname)
3729 xdim_is_cv_flag =
true;
3734 if(strcmp(sds_name,ydim_name) == 0) {
3736 int32 sds_dimid = SDgetdimid(sds_id,0);
3737 if(sds_dimid == FAIL) {
3738 SDendaccess (sds_id);
3739 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3741 char dim_name[H4_MAX_NC_NAME];
3744 int32 num_dim_attrs = 0;
3745 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3746 SDendaccess(sds_id);
3747 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3752 string tempdimname(dim_name);
3753 if(tempdimname.size() >=5) {
3754 if(tempdimname.compare(0,5,
"YDim:") == 0) {
3756 temp_grid_name2 = tempdimname.substr(5);
3757 ydim_is_cv_flag =
true;
3760 else if (
"YDim" == tempdimname)
3761 ydim_is_cv_flag =
true;
3766 SDendaccess(sds_id);
3767 if((
true == xdim_is_cv_flag) && (
true == ydim_is_cv_flag ))
3773 if ((temp_grid_name1 == temp_grid_name2) && (
true == xdim_is_cv_flag) && (
true == ydim_is_cv_flag)) {
3774 grid_name = temp_grid_name1;
3782 else if((
basename(filename).size() >8) && (
basename(filename).compare(0,4,
"AIRS") == 0)
3783 && ((
basename(filename).find(
".L3.")!=string::npos) || (
basename(filename).find(
".L2.")!=string::npos))){
3785 bool has_dimscale =
false;
3788 for (sds_index = 0; sds_index < n_sds; sds_index++) {
3790 sds_id = SDselect (sdfd, sds_index);
3791 if (sds_id == FAIL) {
3792 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3796 int status = SDgetinfo (sds_id, sds_name, &sds_rank, dim_sizes,
3797 &sds_dtype, &n_sds_attrs);
3798 if (status == FAIL) {
3799 SDendaccess(sds_id);
3800 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3803 for (
int dim_index = 0; dim_index<sds_rank; dim_index++) {
3805 int32 sds_dimid = SDgetdimid(sds_id,dim_index);
3806 if(sds_dimid == FAIL) {
3807 SDendaccess(sds_id);
3808 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3811 char dim_name[H4_MAX_NC_NAME];
3814 int32 num_dim_attrs = 0;
3815 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3816 SDendaccess(sds_id);
3817 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3821 has_dimscale =
true;
3826 SDendaccess(sds_id);
3827 if(
true == has_dimscale)
3832 if (
true == has_dimscale)
3843 bool has_dimscale =
true;
3844 bool is_grid =
false;
3847 for (sds_index = 0; sds_index < n_sds; sds_index++) {
3849 sds_id = SDselect (sdid, sds_index);
3850 if (sds_id == FAIL) {
3852 throw InternalErr (__FILE__,__LINE__,
"SDselect failed ");
3856 int status = SDgetinfo (sds_id, sds_name, &sds_rank, dim_sizes,
3857 &sds_dtype, &n_sds_attrs);
3858 if (status == FAIL) {
3859 SDendaccess(sds_id);
3861 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3865 for (
int dim_index = 0; dim_index<sds_rank; dim_index++) {
3867 int32 sds_dimid = SDgetdimid(sds_id,dim_index);
3868 if(sds_dimid == FAIL) {
3869 SDendaccess(sds_id);
3871 throw InternalErr (__FILE__,__LINE__,
"SDgetinfo failed ");
3873 char dim_name[H4_MAX_NC_NAME];
3876 int32 num_dim_attrs = 0;
3877 if(SDdiminfo(sds_dimid,dim_name,&dim_size,&dim_type,&num_dim_attrs) == FAIL) {
3878 SDendaccess(sds_id);
3880 throw InternalErr(__FILE__,__LINE__,
"SDdiminfo failed ");
3884 has_dimscale =
false;
3888 SDendaccess(sds_id);
3890 if (
true == has_dimscale)
3904 dds.set_dataset_name(
basename(filename));
3905 build_descriptions(dds, das, filename);
3907 if (!dds.check_semantics()) {
3917 dds.set_dataset_name(
basename(filename));
3919 build_descriptions(dds, das, filename);
3921 if (!dds.check_semantics()) {
3929 static void build_descriptions(DDS & dds, DAS & das,
3930 const string & filename)
3938 SDS_descriptions(sdsmap, das, filename);
3941 FileAnnot_descriptions(das, filename);
3944 Vdata_descriptions(vdatamap, das, filename);
3947 GR_descriptions(grmap, das, filename);
3950 Vgroup_descriptions(dds, das, filename, sdsmap, vdatamap, grmap);
3965 :
public binary_function < hdf_genvec &, hdf_attr, hdf_genvec & > {
3969 accum_attr(
const string & named):d_named(named) {
3976 if (attr.
name.find(d_named) != string::npos) {
3980 cerr <<
"Attribute chunk: " << attr.
name << endl;
3981 cerr << stuff << endl;
3993 struct is_named:
public unary_function < hdf_attr, bool > {
3996 is_named(
const string & named):d_named(named) {
3999 bool operator() (
const hdf_attr & attr) {
4000 return (attr.
name.find(d_named) != string::npos);
4005 merge_split_eos_attributes(vector < hdf_attr > &attr_vec,
4006 const string & attr_name)
4009 if (count_if(attr_vec.begin(), attr_vec.end(), is_named(attr_name)) > 1) {
4013 attributes = accumulate(attr_vec.begin(), attr_vec.end(),
4014 attributes, accum_attr(attr_name));
4022 DBG(vector < string > s_m;
4023 attributes.
print(s_m);
4024 cerr <<
"Accum struct MD: (" << s_m.size() <<
") "
4028 attr_vec.erase(remove_if(attr_vec.begin(), attr_vec.end(),
4029 is_named(attr_name)), attr_vec.end());
4033 merged_attr.
name = attr_name;
4034 merged_attr.
values = attributes;
4037 attr_vec.push_back(merged_attr);
4042 static void SDS_descriptions(
sds_map & map, DAS & das,
4043 const string & filename)
4047 sdsin.setmeta(
true);
4051 vector < hdf_attr > fileattrs;
4056 while (!sdsin.eos()) {
4067 merge_split_eos_attributes(fileattrs,
"StructMetadata");
4068 merge_split_eos_attributes(fileattrs,
"CoreMetadata");
4069 merge_split_eos_attributes(fileattrs,
"ProductMetadata");
4070 merge_split_eos_attributes(fileattrs,
"ArchiveMetadata");
4071 merge_split_eos_attributes(fileattrs,
"coremetadata");
4072 merge_split_eos_attributes(fileattrs,
"productmetadata");
4075 AddHDFAttr(das,
string(
"HDF_GLOBAL"), fileattrs);
4077 vector < hdf_attr > dattrs;
4081 for (
SDSI s = map.begin(); s != map.end(); ++s) {
4082 const hdf_sds *sds = &s->second.sds;
4084 for (
int k = 0; k < (int) sds->
dims.size(); ++k) {
4085 dattrs = Dims2Attrs(sds->
dims[k]);
4095 static void Vdata_descriptions(
vd_map & map, DAS & das,
4096 const string & filename)
4102 while (!vdin.eos()) {
4111 vector < hdf_attr > dattrs;
4112 for (
VDI s = map.begin(); s != map.end(); ++s) {
4121 static void Vgroup_descriptions(DDS & dds, DAS & das,
4122 const string & filename,
sds_map & sdmap,
4130 while (!vgin.eos()) {
4138 for (
VGI v = vgmap.begin(); v != vgmap.end(); ++v) {
4145 for (uint32 i = 0; i < vg->
tags.size(); i++) {
4146 int32 tag = vg->
tags[i];
4147 int32 ref = vg->
refs[i];
4151 if (grmap.find(ref) != grmap.end())
4152 grmap[ref].in_vgroup =
true;
4154 vgmap[ref].toplevel =
false;
4157 vdmap[ref].in_vgroup =
true;
4160 sdmap[ref].in_vgroup =
true;
4163 (*
BESLog::TheLog()) <<
"unknown tag: " << tag <<
" ref: " << ref << endl;
4174 for (
VGI v = vgmap.begin(); v != vgmap.end(); ++v) {
4175 if (!v->second.toplevel)
4178 vgmap, sdmap, vdmap,
4188 for (
SDSI s = sdmap.begin(); s != sdmap.end(); ++s) {
4189 if (s->second.in_vgroup)
4191 if (s->second.sds.has_scale())
4202 for (
VDI v = vdmap.begin(); v != vdmap.end(); ++v) {
4203 if (v->second.in_vgroup)
4212 for (
GRI g = grmap.begin(); g != grmap.end(); ++g) {
4213 if (g->second.in_vgroup)
4223 static void GR_descriptions(
gr_map & map, DAS & das,
4224 const string & filename)
4231 vector < hdf_attr > fileattrs;
4236 while (!grin.eos()) {
4246 AddHDFAttr(das,
string(
"HDF_GLOBAL"), fileattrs);
4249 vector < hdf_attr > pattrs;
4250 for (
GRI g = map.begin(); g != map.end(); ++g) {
4251 const hdf_gri *gri = &g->second.gri;
4256 pattrs = Pals2Attrs(gri->
palettes);
4265 static void FileAnnot_descriptions(DAS & das,
const string & filename)
4269 vector < string > fileannots;
4271 annotin >> fileannots;
4272 AddHDFAttr(das,
string(
"HDF_GLOBAL"), fileannots);
4280 const vector < hdf_attr > &hav)
4282 if (hav.size() == 0)
4286 string tempname = varname;
4287 AttrTable *atp = das.get_table(tempname);
4289 atp =
new AttrTable;
4290 atp = das.add_table(tempname, atp);
4293 vector < string > attv;
4295 for (
int i = 0; i < (int) hav.size(); ++i) {
4297 attrtype =
DAPTypeName(hav[i].values.number_type());
4299 attv = vector < string > ();
4300 hav[i].values.print(attv);
4303 for (
int j = 0; j < (int) attv.size(); ++j) {
4305 string container_name = hav[i].name;
4306 if (container_name.find(
"StructMetadata") == 0
4307 || container_name.find(
"CoreMetadata") == 0
4308 || container_name.find(
"ProductMetadata") == 0
4309 || container_name.find(
"ArchiveMetadata") == 0
4310 || container_name.find(
"coremetadata") == 0
4311 || container_name.find(
"productmetadata") == 0) {
4312 string::size_type dotzero = container_name.find(
'.');
4313 if (dotzero != container_name.npos)
4314 container_name.erase(dotzero);
4317 AttrTable *at = das.get_table(container_name);
4319 at = das.add_table(container_name,
new AttrTable);
4342 throw Error(
"HDF-EOS parse error while processing a " + container_name +
" HDFEOS attribute.");
4346 if (arg.status() ==
false) {
4348 << container_name <<
" HDFEOS attribute. (2)" << endl;
4355 if (attrtype ==
"String")
4356 #ifdef ATTR_STRING_QUOTE_FIX
4357 attv[j] = escattr(attv[j]);
4359 attv[j] =
"\"" + escattr(attv[j]) +
"\"";
4362 if (atp->append_attr(hav[i].name, attrtype, attv[j]) == 0)
4374 const vector < string > &anv)
4376 if (anv.size() == 0)
4381 AttrTable *atp = das.get_table(varname);
4383 atp =
new AttrTable;
4384 atp = das.add_table(varname, atp);
4388 for (
int i = 0; i < (int) anv.size(); ++i) {
4389 #ifdef ATTR_STRING_QUOTE_FIX
4390 an = escattr(anv[i]);
4392 an =
"\"" + escattr(anv[i]) +
"\"";
4394 if (atp->append_attr(
string(
"HDF_ANNOT"),
"String", an) == 0)
4404 static vector < hdf_attr > Pals2Attrs(
const vector < hdf_palette > palv)
4406 vector < hdf_attr > pattrs;
4408 if (palv.size() != 0) {
4413 for (
int i = 0; i < (int) palv.size(); ++i) {
4415 pattr.
name = palname;
4416 pattr.
values = palv[i].table;
4417 pattrs.push_back(pattr);
4418 pattr.
name = palname +
"_ncomps";
4421 int32 * >(&palv[i].ncomp), 1);
4422 pattrs.push_back(pattr);
4423 if (palv[i].name.length() != 0) {
4424 pattr.
name = palname +
"_name";
4427 char *>(palv[i].name.c_str()),
4428 palv[i].name.length());
4429 pattrs.push_back(pattr);
4438 static vector < hdf_attr > Dims2Attrs(
const hdf_dim dim)
4440 vector < hdf_attr > dattrs;
4442 if (dim.
name.length() != 0) {
4443 dattr.
name =
"name";
4447 dattrs.push_back(dattr);
4449 if (dim.
label.length() != 0) {
4450 dattr.
name =
"long_name";
4453 dim.
label.length());
4454 dattrs.push_back(dattr);
4456 if (dim.
unit.length() != 0) {
4457 dattr.
name =
"units";
4461 dattrs.push_back(dattr);
4463 if (dim.
format.length() != 0) {
4464 dattr.
name =
"format";
4468 dattrs.push_back(dattr);
const std::vector< VDATA * > & getVDATAs() const
Public interface to Obtain Vdata.
HDFArray * NewArrayFromGR(const hdf_gri &gr, const string &dataset)
bool read_dds_special_1d_grid(DDS &dds, HDFSP::File *spf, const string &filename, int32 sdfd, int32 fileid)
bool read_das_special_eos2(DAS &das, const string &filename, int32 sdid, int32 fileid, bool ecs_metadata, HDFSP::File **h4filepptr)
static void add_missing_cf_attrs(HDFSP::File *f, libdap::DAS &das)
void read_dds(DDS &dds, const string &filename)
int32 getRank() const
Get the dimension rank of this field.
void change_das_mod08_scale_offset(DAS &das, HDFSP::File *spf)
std::vector< std::string > ctype_field_namelist
bool read_das_hdfhybrid(DAS &das, const string &filename, int32 sdfd, int32 fileid, HDFSP::File **h4filepptr)
bool read_dds_hdfhybrid(DDS &dds, const string &filename, int32 sdfd, int32 fileid, HDFSP::File *h4file)
map< int32, vd_info, less< int32 > > vd_map
bool open(const string &filename, const int sd_id, const int file_id)
openes HDF4 file.
string basename(const string &path)
HDFGrid * NewGridFromSDS(const hdf_sds &sds, const string &dataset)
bool write_attribute_FillValue(const string &varname, int type, float val)
writes _FillValue attribute into varname attribute table.
const std::vector< Dimension * > & getDimensions() const
Get the list of dimensions.
A class for writing attributes from an HDF-EOS2 file.
static void check_obpg_global_attrs(HDFSP::File *f, std::string &scaling, float &slope, bool &global_slope_flag, float &intercept, bool &global_intercept_flag)
const char * data(void) const
This class retrieves all information from an HDF4 file. It is a container for SDS and Vdata...
const std::string & getNewName() const
Get the CF name(special characters replaced by underscores) of this field.
void read_das(DAS &das, const string &filename)
map< int32, sds_info, less< int32 > >::const_iterator SDSI
bool read_dds_hdfsp(DDS &dds, const string &filename, int32 sdfd, int32 fileid, HDFSP::File *h4file)
This class retrieves all SDS objects and SD file attributes.
#define HANDLE_CASE(tid, type)
static void handle_otherhdf_special_attrs(HDFSP::File *f, libdap::DAS &das)
int check_special_eosfile(const string &filename, string &grid_name, int32 sdfd, int32 fileid)
void read_dds_spfields(DDS &dds, const string &filename, const int sdfd, HDFSP::SDField *spsds, SPType sptype)
void * hdfeos_string(const char *yy_str)
bool set_non_ecsmetadata_attrs()
HDFSequence * NewSequenceFromVdata(const hdf_vdata &vd, const string &dataset)
One instance of this class represents one Vdata field.
string DAPTypeName(int32 hdf_type)
map< int32, gr_info, less< int32 > > gr_map
bool IsDimNoScale() const
Is this field a dimension without dimension scale(or empty[no data]dimension variable) ...
SD * getSD() const
Public interface to Obtain SD.
static void handle_merra_ceres_attrs_with_bes_keys(HDFSP::File *f, libdap::DAS &das, const std::string &filename)
map< int32, vd_info, less< int32 > >::const_iterator VDI
vector< hdf_palette > palettes
static void handle_vdata_attrs_with_desc_key(HDFSP::File *f, libdap::DAS &das)
static void correct_fvalue_type(libdap::AttrTable *at, int32 dtype)
CF requires the _FillValue attribute datatype is the same as the corresponding field datatype...
int32 getFieldOrder() const
Get the order of this field.
const int getFieldType() const
bool write_attribute_units(const string &varname, string units)
writes units attribute into varname attribute table.
int32 number_type(void) const
One instance of this class represents one SDS object.
HDFArray * NewArrayFromSDS(const hdf_sds &sds, const string &dataset)
bool Check_update_special(const std::string &gridname)
void Prepare()
The main step to make HDF4 SDS objects CF-complaint. All dimension(coordinate variables) information ...
static std::string print_type(int32)
Print datatype in string.
void print(vector< string > &strv) const
static File * Read(const char *path, int32 sdid, int32 fileid)
Retrieve SDS and Vdata information from the HDF4 file.
void hdfeos_switch_to_buffer(void *new_buffer)
This class provides a way to map HDF4 1-D character array to DAP Str for the CF option.
const std::string & getName() const
Get the name of this field.
void append(int32 nt, const char *new_data, int32 nelts)
static File * Read_Hybrid(const char *path, int32 sdid, int32 fileid)
Retrieve SDS and Vdata information from the hybrid HDF-EOS file. Currently we only support the access...
int32 getFieldRef() const
static void add_obpg_special_attrs(HDFSP::File *f, libdap::DAS &das, HDFSP::SDField *spsds, std::string &scaling, float &slope, bool &global_slope_flag, float &intercept, bool &global_intercept_flag)
void hdfeos_delete_buffer(void *buffer)
virtual const char * what() const
Return exception message.
static std::string escattr(std::string s)
A customized escaping function to escape special characters following OPeNDAP's escattr function that...
bool close()
closes the opened file.
bool write_attribute_coordinates(const string &varname, string coord)
writes coordinates attribute into varname attribute table.
void set_DAS(DAS *das)
sets DAS pointer so that we can bulid attribute tables.
int hdfeosparse(libdap::parser_arg *arg)
static std::string print_attr(int32, int, void *)
Print attribute values in string.
This class provides a way to map HDFEOS2 character >1D array to DAP Str array for the CF option...
const std::vector< Attribute * > & getAttributes() const
Public interface to obtain the SD(file) attributes.
HDFStructure * NewStructureFromVgroup(const hdf_vgroup &vg, vg_map &vgmap, sds_map &sdmap, vd_map &vdmap, gr_map &grmap, const string &dataset)
map< int32, vg_info, less< int32 > >::const_iterator VGI
const std::vector< AttrContainer * > & getVgattrs() const
Get attributes for all vgroups.
static std::string get_CF_string(std::string s)
Change special characters to "_".
void read_dds_spvdfields(DDS &dds, const string &filename, const int fileid, int32 vdref, int32 numrec, HDFSP::VDField *spvd)
static bool check_beskeys(const std::string &key)
Check the BES key. This function will check a BES key specified at the file h4.conf.in. If the key's value is either true or yes. The handler claims to find a key and will do some operations. Otherwise, will do different operations. For example, One may find a line H4.EnableCF=true at h4.conf.in. That means, the HDF4 handler will handle the HDF4 files by following CF conventions.
const std::vector< Dimension * > & getCorrectedDimensions() const
Get the list of the corrected dimensions.
string get_metadata(const string &metadataname, bool &suffix_is_num, vector< string > &non_num_names, vector< string > &non_num_data)
retrieves the merged metadata.
SPType getSPType() const
Obtain special HDF4 product type.
This class provides a way to map HDFEOS2 1-D character array to DAP Str for the CF option...
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream
int32 getType() const
Get the data type of this field.
static void correct_scale_offset_type(libdap::AttrTable *at)
CF requires the scale_factor and add_offset attribute datatypes hold the same datatype. So far we haven't found that scale_factor and add_offset attributes hold different datatypes in NASA files. But just in case, we implement a BES key to give users a chance to check this. By default, the key is always off.
bool Has_Dim_NoScale_Field() const
This file has a field that is a SDS dimension but no dimension scale.
void AddHDFAttr(DAS &das, const string &varname, const vector< hdf_attr > &hav)
const std::vector< SDField * > & getFields() const
Public interface to obtain information of all SDS vectors(objects).
bool read_das_hdfsp(DAS &das, const string &filename, int32 sdfd, int32 fileid, HDFSP::File **h4filepptr)
bool write_attribute(const string &gname, const string &fname, const string &newfname, int n_groups, int fieldtype)
writes attribute table into DAS given grid/swath name and its field name.
map< int32, sds_info, less< int32 > > sds_map
yy_buffer_state * hdfeos_scan_string(const char *str)
map< int32, gr_info, less< int32 > >::const_iterator GRI
bool read_das_special_eos2_core(DAS &das, HDFSP::File *spf, const string &filename, bool ecs_metadata)
map< int32, vg_info, less< int32 > > vg_map