36 #include "InternalErr.h"
42 HDFCFStr::HDFCFStr(
const int h4fd, int32 field_ref,
const string &filename,
const string &varname,
const string &varnewname,
bool is_vdata)
43 : Str(varnewname, filename),
63 BESDEBUG(
"h4",
"Coming to HDFCFStr read "<<endl);
64 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
65 bool check_pass_fileid_key =
false;
69 if(
false == is_vdata) {
72 if(
false == check_pass_fileid_key) {
73 sdid = SDstart (const_cast < char *>(filename.c_str ()), DFACC_READ);
76 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
77 throw InternalErr (__FILE__, __LINE__, eherr.str ());
86 int32 sdsindex = SDreftoindex (sdid, field_ref);
90 eherr <<
"SDS index " << sdsindex <<
" is not right.";
91 throw InternalErr (__FILE__, __LINE__, eherr.str ());
95 sdsid = SDselect (sdid, sdsindex);
99 eherr <<
"SDselect failed.";
100 throw InternalErr (__FILE__, __LINE__, eherr.str ());
103 int32 dim_sizes[H4_MAX_VAR_DIMS];
104 int32 sds_rank, data_type, n_attrs;
105 char name[H4_MAX_NC_NAME];
108 r = SDgetinfo (sdsid, name, &sds_rank, dim_sizes,
109 &data_type, &n_attrs);
114 eherr <<
"SDgetinfo failed.";
115 throw InternalErr (__FILE__, __LINE__, eherr.str ());
122 eherr <<
"The rank of string doesn't match with the rank of character array";
123 throw InternalErr (__FILE__, __LINE__, eherr.str ());
127 vector<int32>offset32;
129 vector<int32>count32;
134 count32[0] = dim_sizes[0];
138 val.resize(count32[0]);
140 r = SDreaddata (sdsid, &offset32[0], &step32[0], &count32[0], &val[0]);
145 eherr <<
"SDreaddata failed.";
146 throw InternalErr (__FILE__, __LINE__, eherr.str ());
149 string final_str(val.begin(),val.end());
150 set_value(final_str);
158 if(
true == check_pass_fileid_key)
162 file_id = Hopen (filename.c_str (), DFACC_READ, 0);
165 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
166 throw InternalErr (__FILE__, __LINE__, eherr.str ());
172 if (Vstart (file_id) < 0) {
175 eherr <<
"This file cannot be open.";
176 throw InternalErr (__FILE__, __LINE__, eherr.str ());
180 int32 vdref = field_ref;
181 int32 vdata_id = VSattach (file_id, vdref,
"r");
182 if (vdata_id == -1) {
186 eherr <<
"Vdata cannot be attached.";
187 throw InternalErr (__FILE__, __LINE__, eherr.str ());
190 int32 num_rec = VSelts(vdata_id);
197 eherr <<
"The number of elements from this vdata cannot be obtained.";
198 throw InternalErr (__FILE__, __LINE__, eherr.str ());
205 if (VSseek (vdata_id, 0) == -1) {
210 eherr <<
"VSseek failed at " << 0;
211 throw InternalErr (__FILE__, __LINE__, eherr.str ());
215 if (VSsetfields (vdata_id, varname.c_str ()) == -1) {
220 eherr <<
"VSsetfields failed with the name " << varname;
221 throw InternalErr (__FILE__, __LINE__, eherr.str ());
227 r = VSread (vdata_id, (uint8 *) &val[0], num_rec,
231 string final_str(val.begin(),val.end());
232 set_value(final_str);
233 if (VSdetach (vdata_id) == -1) {
237 eherr <<
"VSdetach failed.";
238 throw InternalErr (__FILE__, __LINE__, eherr.str ());
241 if (Vend (file_id) == -1) {
244 eherr <<
"VSdetach failed.";
245 throw InternalErr (__FILE__, __LINE__, eherr.str ());
static void close_fileid(int32 sdfd, int32 file_id, int32 gridfd, int32 swathfd, bool pass_fileid_key)
Close HDF4 and HDF-EOS2 file IDs. For performance reasons, we want to keep HDF-EOS2/HDF4 IDs open for...
HDFCFStr(const int h4fd, int32 field_ref, const std::string &filename, const std::string &varname, const std::string &varnewname, bool is_vdata)
virtual BaseType * ptr_duplicate()
This class provides a way to map HDF4 1-D character array to DAP Str for the CF option.
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.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream