11 #ifdef USE_HDFEOS2_LIB
18 #include "InternalErr.h"
22 #define SIGNED_BYTE_TO_INT32 1
25 HDFEOS2ArraySwathGeoField::read ()
28 BESDEBUG(
"h4",
"Coming to HDFEOS2ArraySwathGeoField read "<<endl);
30 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
31 bool check_pass_fileid_key =
false;
43 int nelms = format_constraint (&offset[0], &step[0], &count[0]);
46 vector<int32>offset32;
47 offset32.resize(rank);
54 for (
int i = 0; i < rank; i++) {
55 offset32[i] = (int32) offset[i];
56 count32[i] = (int32) count[i];
57 step32[i] = (int32) step[i];
60 int32 (*openfunc) (
char *, intn);
61 intn (*closefunc) (int32);
62 int32 (*attachfunc) (int32,
char *);
63 intn (*detachfunc) (int32);
64 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
65 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
71 attachfunc = SWattach;
72 detachfunc = SWdetach;
73 fieldinfofunc = SWfieldinfo;
74 readfieldfunc = SWreadfield;
75 datasetname = swathname;
80 int32 sfid = -1, swathid = -1;
82 if(
false == check_pass_fileid_key) {
83 sfid = openfunc (const_cast < char *>(filename.c_str ()), DFACC_READ);
86 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
87 throw InternalErr (__FILE__, __LINE__, eherr.str ());
93 swathid = attachfunc (sfid, const_cast < char *>(datasetname.c_str ()));
98 eherr <<
"Swath " << datasetname.c_str () <<
" cannot be attached.";
99 throw InternalErr (__FILE__, __LINE__, eherr.str ());
103 int32 tmp_rank, tmp_dims[rank];
104 char tmp_dimlist[1024];
107 r = fieldinfofunc (swathid, const_cast < char *>(fieldname.c_str ()),
108 &tmp_rank, tmp_dims, &type, tmp_dimlist);
110 detachfunc (swathid);
113 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
114 throw InternalErr (__FILE__, __LINE__, eherr.str ());
123 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
125 detachfunc (swathid);
128 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
129 throw InternalErr (__FILE__, __LINE__, eherr.str ());
134 #ifndef SIGNED_BYTE_TO_INT32
135 set_value ((dods_byte *) &val[0], nelms);
138 newval.resize(nelms);
140 for (
int counter = 0; counter < nelms; counter++)
141 newval[counter] = (int32) (val[counter]);
142 set_value ((dods_int32 *) &newval[0], nelms);
151 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
153 detachfunc (swathid);
156 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
157 throw InternalErr (__FILE__, __LINE__, eherr.str ());
160 set_value ((dods_byte *) &val[0], nelms);
168 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
170 detachfunc (swathid);
173 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
174 throw InternalErr (__FILE__, __LINE__, eherr.str ());
180 bool needadjust =
false;
182 if ((val[0] < -1000) || (val[0] > 1000))
185 if ((val[nelms / 2] < -1000)
186 || (val[nelms / 2] > 1000))
189 if ((val[nelms - 1] < -1000)
190 || (val[nelms - 1] > 1000))
192 if (
true == needadjust) {
193 vector<float32>newval;
194 newval.resize(nelms);
195 float scale_factor = 0.01;
197 for (
int i = 0; i < nelms; i++)
198 newval[i] = scale_factor * (float32) val[i];
199 set_value ((dods_float32 *) &newval[0], nelms);
203 set_value ((dods_int16 *) &val[0], nelms);
212 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
214 detachfunc (swathid);
217 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
218 throw InternalErr (__FILE__, __LINE__, eherr.str ());
221 set_value ((dods_uint16 *) &val[0], nelms);
229 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
231 detachfunc (swathid);
234 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
235 throw InternalErr (__FILE__, __LINE__, eherr.str ());
238 set_value ((dods_int32 *) &val[0], nelms);
246 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
248 detachfunc (swathid);
251 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
252 throw InternalErr (__FILE__, __LINE__, eherr.str ());
255 set_value ((dods_uint32 *) &val[0], nelms);
263 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
265 detachfunc (swathid);
268 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
269 throw InternalErr (__FILE__, __LINE__, eherr.str ());
271 set_value ((dods_float32 *) &val[0], nelms);
278 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()), &offset32[0], &step32[0], &count32[0], &val[0]);
280 detachfunc (swathid);
283 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
284 throw InternalErr (__FILE__, __LINE__, eherr.str ());
287 set_value ((dods_float64 *) &val[0], nelms);
291 detachfunc (swathid);
293 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
296 r = detachfunc (swathid);
300 eherr <<
"Swath " << datasetname.c_str () <<
" cannot be detached.";
301 throw InternalErr (__FILE__, __LINE__, eherr.str ());
307 r = closefunc (sfid);
310 eherr <<
"Swath " << filename.c_str () <<
" cannot be closed.";
311 throw InternalErr (__FILE__, __LINE__, eherr.str ());
321 HDFEOS2ArraySwathGeoField::format_constraint (
int *offset,
int *step,
int *count)
326 Dim_iter p = dim_begin ();
328 while (p != dim_end ()) {
330 int start = dimension_start (p,
true);
331 int stride = dimension_stride (p,
true);
332 int stop = dimension_stop (p,
true);
336 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
339 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
340 ":" << stride <<
":" << stop <<
"]";
341 throw Error (malformed_expr, oss.str ());
345 if (start == 0 && stop == 0 && stride == 0) {
346 start = dimension_start (p,
false);
347 stride = dimension_stride (p,
false);
348 stop = dimension_stop (p,
false);
353 count[id] = ((stop - start) / stride) + 1;
357 "=format_constraint():"
358 <<
"id=" <<
id <<
" offset=" << offset[
id]
359 <<
" step=" << step[
id]
360 <<
" count=" << count[
id]
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...
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