29 #include <sys/types.h>
40 #include <D4BaseTypeFactory.h>
43 #include <mime_util.h>
44 #include <InternalErr.h>
45 #include <Ancillary.h>
60 #include <InternalErr.h>
64 #include <Ancillary.h>
67 #define HDF4_NAME "h4"
83 extern void read_das(DAS & das,
const string & filename);
84 extern void read_dds(DDS & dds,
const string & filename);
91 #ifdef USE_HDFEOS2_LIB
93 void read_das_use_eos2lib(DAS & das,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
bool ecs_metadata,
HDFSP::File**h4file,HDFEOS2::File**eosfile);
94 void read_dds_use_eos2lib(DDS & dds,
const string & filename,int32 sdfd,int32 fileid, int32 gridfd, int32 swathfd,
HDFSP::File*h4file,HDFEOS2::File*eosfile);
95 void close_fileid(
const int sdfd,
const int fileid,
const int gridfd,
const int swathfd,
HDFSP::File*h4file,HDFEOS2::File*eosfile);
123 string key=
"H4.EnableCF";
130 if( doset ==
"true" || doset ==
"yes" ) {
157 sdfd = SDstart (const_cast < char *>(accessed.c_str()), DFACC_READ);
159 throw Error(cannot_read_file,
"HDF4 SDstart error");
162 fileid = Hopen(const_cast<char *>(accessed.c_str()), DFACC_READ,0);
165 throw Error(cannot_read_file,
"HDF4 Hopen error");
169 #ifdef USE_HDFEOS2_LIB
173 HDFEOS2::File *eosfile =
NULL;
177 gridfd = GDopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
181 throw Error(cannot_read_file,
"HDF-EOS GDopen error");
185 swathfd = SWopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
190 throw Error(cannot_read_file,
"HDF-EOS SWopen error");
196 if(ecs_metadata ==
true)
197 cerr<<
"output ecs metadata "<<endl;
199 cerr<<
"Don't output ecs metadata "<<endl;
201 read_das_use_eos2lib(*das, accessed,sdfd,fileid,gridfd,swathfd,ecs_metadata,&h4file,&eosfile);
204 close_fileid(sdfd,fileid,gridfd,swathfd,h4file,eosfile);
228 Ancillary::read_ancillary_das(*das, accessed);
235 catch (InternalErr & e) {
236 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
240 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
244 string s =
"unknown exception caught building HDF4 DAS";
245 throw BESDapError(s,
true, unknown_error, __FILE__, __LINE__);
256 string key=
"H4.EnableCF";
263 if( doset ==
"true" || doset ==
"yes" ) {
271 struct timeval start_time,end_time;
272 gettimeofday(&start_time,
NULL);
286 dds->filename(accessed);
300 sdfd = SDstart (const_cast < char *>(accessed.c_str()), DFACC_READ);
302 throw Error(cannot_read_file,
"HDF4 SDstart error");
305 fileid = Hopen(const_cast<char *>(accessed.c_str()), DFACC_READ,0);
308 throw Error(cannot_read_file,
"HDF4 Hopen error");
313 #ifdef USE_HDFEOS2_LIB
318 HDFEOS2::File *eosfile =
NULL;
322 gridfd = GDopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
326 throw Error(cannot_read_file,
"HDF-EOS GDopen error");
330 swathfd = SWopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
335 throw Error(cannot_read_file,
"HDF-EOS SWopen error");
340 read_das_use_eos2lib(*das, accessed,sdfd,fileid,gridfd,swathfd,ecs_metadata,&h4file,&eosfile);
342 Ancillary::read_ancillary_das(*das, accessed);
346 cerr<<
"HDFEOS2 file pointer is NULL "<<endl;
348 cerr<<
"HDF4 file pointer is NULL"<<endl;
351 read_dds_use_eos2lib(*dds, accessed,sdfd,fileid,gridfd,swathfd,h4file,eosfile);
354 close_fileid(sdfd,fileid,gridfd,swathfd,h4file,eosfile);
367 Ancillary::read_ancillary_das(*das, accessed);
383 Ancillary::read_ancillary_das(*das, accessed);
389 gettimeofday(&end_time,
NULL);
390 int total_time_spent = (end_time.tv_sec - start_time.tv_sec)*1000000 +end_time.tv_usec-start_time.tv_usec;
391 cerr<<
"total time spent for DDS buld is "<<total_time_spent<<
"micro seconds "<<endl;
394 Ancillary::read_ancillary_dds(*dds, accessed);
396 dds->transfer_attributes(das);
405 catch (InternalErr & e) {
406 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
410 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
414 string s =
"unknown exception caught building HDF4 DDS";
415 throw BESDapError(s,
true, unknown_error, __FILE__, __LINE__);
426 string key=
"H4.EnableCF";
437 if( doset ==
"true" || doset ==
"yes" ) {
463 DataDDS *dds = bdds->
get_dds();
469 dds->filename(accessed);
481 sdfd = SDstart (const_cast < char *>(accessed.c_str()), DFACC_READ);
483 throw Error(cannot_read_file,
"HDF4 SDstart error");
486 fileid = Hopen(const_cast<char *>(accessed.c_str()), DFACC_READ,0);
489 throw Error(cannot_read_file,
"HDF4 Hopen error");
493 #ifdef USE_HDFEOS2_LIB
497 HDFEOS2::File *eosfile =
NULL;
501 gridfd = GDopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
505 throw Error(cannot_read_file,
"HDF-EOS GDopen error");
509 swathfd = SWopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
514 throw Error(cannot_read_file,
"HDF-EOS SWopen error");
522 bool ecs_metadata =
true;
525 ecs_metadata =
false;
527 read_das_use_eos2lib(*das, accessed,sdfd,fileid,gridfd,swathfd,ecs_metadata,&h4file,&eosfile);
528 Ancillary::read_ancillary_das(*das, accessed);
531 read_dds_use_eos2lib(*dds, accessed,sdfd,fileid,gridfd,swathfd,h4file,eosfile);
534 close_fileid(sdfd,fileid,gridfd,swathfd,h4file,eosfile);
546 Ancillary::read_ancillary_das(*das, accessed);
560 Ancillary::read_ancillary_das(*das, accessed);
564 Ancillary::read_ancillary_dds(*dds, accessed);
565 dds->transfer_attributes(das);
574 catch (InternalErr & e) {
575 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
579 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
583 string s =
"unknown exception caught building HDF4 DataDDS";
584 throw BESDapError(s,
true, unknown_error, __FILE__, __LINE__);
596 #ifdef USE_HDFEOS2_LIB
599 HDFEOS2::File *eosfile =
NULL;
620 hdds->filename(accessed);
629 sdfd = SDstart (const_cast < char *>(accessed.c_str()), DFACC_READ);
631 throw Error(cannot_read_file,
"HDF4 SDstart error");
634 fileid = Hopen(const_cast<char *>(accessed.c_str()), DFACC_READ,0);
637 throw Error(cannot_read_file,
"HDF4 Hopen error");
640 #ifdef USE_HDFEOS2_LIB
646 gridfd = GDopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
650 throw Error(cannot_read_file,
"HDF-EOS GDopen error");
654 swathfd = SWopen(const_cast < char *>(accessed.c_str()), DFACC_READ);
659 throw Error(cannot_read_file,
"HDF-EOS SWopen error");
667 bool ecs_metadata =
true;
670 ecs_metadata =
false;
673 read_das_use_eos2lib(*das, accessed,sdfd,fileid,gridfd,swathfd,ecs_metadata,&h4file,&eosfile);
676 Ancillary::read_ancillary_das(*das, accessed);
679 read_dds_use_eos2lib(*hdds, accessed,sdfd,fileid,gridfd,swathfd,h4file,eosfile);
687 Ancillary::read_ancillary_das(*das, accessed);
695 Ancillary::read_ancillary_dds(*hdds, accessed);
697 hdds->transfer_attributes(das);
707 #ifdef USE_HDFEOS2_LIB
721 catch (InternalErr & e) {
722 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
726 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
730 #ifdef USE_HDFEOS2_LIB
731 close_fileid(sdfd,fileid,gridfd,swathfd,h4file,eosfile);
735 string s =
"unknown exception caught building HDF4 DataDDS";
736 throw BESDapError(s,
true, unknown_error, __FILE__, __LINE__);
751 BaseTypeFactory factory;
752 DDS dds(&factory, name_path(data_path),
"3.2");
753 dds.filename(data_path);
760 string key=
"H4.EnableCF";
774 if( doset ==
"true" || doset ==
"yes" ) {
786 return hdf4_build_dmr_with_IDs(dhi);
799 sdfd = SDstart (const_cast < char *>(data_path.c_str()), DFACC_READ);
801 throw Error(cannot_read_file,
"HDF4 SDstart error");
804 fileid = Hopen(const_cast<char *>(data_path.c_str()), DFACC_READ,0);
807 throw Error(cannot_read_file,
"HDF4 Hopen error");
810 #ifdef USE_HDFEOS2_LIB
812 HDFEOS2::File *eosfile =
NULL;
816 gridfd = GDopen(const_cast < char *>(data_path.c_str()), DFACC_READ);
820 throw Error(cannot_read_file,
"HDF-EOS GDopen error");
824 swathfd = SWopen(const_cast < char *>(data_path.c_str()), DFACC_READ);
829 throw Error(cannot_read_file,
"HDF-EOS SWopen error");
839 bool ecs_metadata =
true;
842 ecs_metadata =
false;
846 read_das_use_eos2lib(das, data_path,sdfd,fileid,gridfd,swathfd,ecs_metadata,&h4file,&eosfile);
849 Ancillary::read_ancillary_das(das, data_path);
852 read_dds_use_eos2lib(dds, data_path,sdfd,fileid,gridfd,swathfd,h4file,eosfile);
856 close_fileid(sdfd,fileid,gridfd,swathfd,h4file,eosfile);
867 Ancillary::read_ancillary_das(das, data_path);
883 Ancillary::read_ancillary_das(das, data_path);
888 Ancillary::read_ancillary_dds(dds, data_path);
890 dds.transfer_attributes(&das);
897 catch (InternalErr & e) {
898 throw BESDapError(e.get_error_message(),
true, e.get_error_code(),
902 throw BESDapError(e.get_error_message(),
false, e.get_error_code(),
906 string s =
"unknown exception caught building HDF4 DataDDS";
907 throw BESDapError(s,
true, unknown_error, __FILE__, __LINE__);
921 D4BaseTypeFactory* MyD4TypeFactory =
NULL;
922 MyD4TypeFactory =
new D4BaseTypeFactory;
923 dmr->set_factory(MyD4TypeFactory);
926 D4BaseTypeFactory MyD4TypeFactory;
927 dmr->set_factory(&MyD4TypeFactory);
929 dmr->build_using_dds(dds);
943 if(MyD4TypeFactory !=
NULL)
944 delete MyD4TypeFactory;
957 BaseTypeFactory factory;
958 DDS dds(&factory, name_path(data_path),
"3.2");
959 dds.filename(data_path);
972 sdfd = SDstart (const_cast < char *>(data_path.c_str()), DFACC_READ);
974 throw Error(cannot_read_file,
"HDF4 SDstart error");
977 fileid = Hopen(const_cast<char *>(data_path.c_str()), DFACC_READ,0);
980 throw Error(cannot_read_file,
"HDF4 Hopen error");
984 #ifdef USE_HDFEOS2_LIB
986 HDFEOS2::File *eosfile =
NULL;
989 gridfd = GDopen(const_cast < char *>(data_path.c_str()), DFACC_READ);
993 throw Error(cannot_read_file,
"HDF-EOS GDopen error");
997 swathfd = SWopen(const_cast < char *>(data_path.c_str()), DFACC_READ);
1002 throw Error(cannot_read_file,
"HDF-EOS SWopen error");
1011 bool ecs_metadata =
true;
1014 ecs_metadata =
false;
1018 read_das_use_eos2lib(das, data_path,sdfd,fileid,gridfd,swathfd,ecs_metadata,&h4file,&eosfile);
1020 Ancillary::read_ancillary_das(das, data_path);
1023 read_dds_use_eos2lib(dds, data_path,sdfd,fileid,gridfd,swathfd,h4file,eosfile);
1027 close_fileid(sdfd,fileid,gridfd,swathfd,h4file,eosfile);
1036 Ancillary::read_ancillary_das(das, data_path);
1049 Ancillary::read_ancillary_dds(dds, data_path);
1051 dds.transfer_attributes(&das);
1057 #ifdef USE_HDFEOS2_LIB
1079 D4BaseTypeFactory MyD4TypeFactory;
1080 dmr->set_factory(&MyD4TypeFactory);
1081 dmr->build_using_dds(dds);
1082 HDF4DMR *hdf4_dmr =
new HDF4DMR(dmr);
1083 #ifdef USE_HDFEOS2_LIB
1084 hdf4_dmr->setHDF4Dataset(sdfd,fileid,gridfd,swathfd);
1086 hdf4_dmr->setHDF4Dataset(sdfd,fileid);
1098 hdf4_dmr->set_factory(0);
1111 map < string, string > attrs;
1112 attrs[
"name"] = MODULE_NAME ;
1113 attrs[
"version"] = MODULE_VERSION ;
1118 list < string > services;
1120 if (services.size() > 0) {
1122 attrs[
"handles"] = handles;
1139 info->
add_module(MODULE_NAME, MODULE_VERSION);
1144 #ifdef USE_HDFEOS2_LIB
1178 cerr<<
"OK to pass pointer of a NULL pointer "<<endl;
brief represents simple text information in a response object, such as version and help inforamtion...
void read_dds(DDS &dds, const string &filename)
#define DAP4DATA_RESPONSE
static bool hdf4_build_version(BESDataHandlerInterface &dhi)
void set_dds(DataDDS *ddsIn)
Set the response object's DDS.
static bool hdf4_build_data_with_IDs(BESDataHandlerInterface &dhi)
exception thrown if inernal error encountered
string get_symbolic_name() const
retrieve the symbolic name for this container
static string lowercase(const string &s)
Convert a string to all lower case.
Represents an OPeNDAP DDS DAP2 data object within the BES.
virtual void clear_container()
clear the container in the DAP response object
static bool hdf4_build_dds(BESDataHandlerInterface &dhi)
void setHDF4Dataset(const int sdfd_in, const int fileid_in, const int gridfd_in, const int swathfd_in)
HDF4RequestHandler(const string &name)
This class retrieves all information from an HDF4 file. It is a container for SDS and Vdata...
virtual void set_dap4_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
bool read_das_hdfsp(DAS &das, const string &filename, int32 sdfd, int32 fileid, HDFSP::File **h4fileptr)
bool read_dds_hdfsp(DDS &dds, const string &filename, int32 sdfd, int32 fileid, HDFSP::File *h4file)
virtual string access()=0
returns the true name of this container
virtual void clear_container()
clear the container in the DAP response object
virtual void set_dap4_function(BESDataHandlerInterface &dhi)
set the constraint depending on the context
informational response object
static string implode(const list< string > &values, char delim)
implode a list of values into a single string delimited by delim
void close_hdf4_fileid(const int sdfd, const int fileid, HDFSP::File *h4file)
virtual BESResponseObject * get_response_object()
return the current response object
Abstract exception class for the BES with basic string message.
static BESServiceRegistry * TheRegistry()
BESResponseHandler * response_handler
virtual void set_constraint(BESDataHandlerInterface &dhi)
set the constraint depending on the context
virtual void begin_tag(const string &tag_name, map< string, string > *attrs=0)
Represents an OPeNDAP DMR DAP4 data object within the BES.
virtual void set_container(const string &cn)
set the container in the DAP response object
error object created from libdap error objects and can handle those errors
void read_das(DAS &das, const string &filename)
Represents an OPeNDAP DataDDS DAP2 data object within the BES.
static bool hdf4_build_help(BESDataHandlerInterface &dhi)
static bool hdf4_build_data(BESDataHandlerInterface &dhi)
virtual ~HDF4RequestHandler(void)
void close_fileid(hid_t fid)
closes HDF5 file reffered by fid.
virtual void clear_container()
clear the container in the DAP response object
Represents a specific data type request handler.
void get_value(const string &s, string &val, bool &found)
Retrieve the value of a given key, if set.
Structure storing information used by the BES to handle the request.
static bool hdf4_build_das(BESDataHandlerInterface &dhi)
This specialization of DDS is used to manage the 'resource' of the open HDF4 dataset handle so that t...
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.
virtual void set_container(const string &cn)
set the container in the DAP response object
virtual bool add_handler(const string &handler_name, p_request_handler handler_method)
add a handler method to the request handler that knows how to fill in a specific response object ...
Represents an OPeNDAP DAS DAP2 data object within the BES.
static BESKeys * TheKeys()
virtual void set_container(const string &cn)
set the container in the DAP response object
virtual void add_module(const string &n, const string &v)
Abstract base class representing a specific set of information in response to a request to the BES...
BESContainer * container
pointer to current container in this interface
virtual void end_tag(const string &tag_name)
virtual void services_handled(const string &handler, list< string > &services)
returns the list of servies provided by the handler in question