14 #ifdef USE_HDFEOS2_LIB
22 #include "InternalErr.h"
26 #define SIGNED_BYTE_TO_INT32 1
30 HDFEOS2ArraySwathGeoDimMapExtraField::read ()
33 BESDEBUG(
"h4",
"Coming to HDFEOS2ArraySwathGeoDimMapExtraField read "<<endl);
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 *);
66 int32 (*inqfunc) (
char *,
char *, int32 *);
72 attachfunc = SWattach;
73 detachfunc = SWdetach;
74 fieldinfofunc = SWfieldinfo;
75 readfieldfunc = SWreadfield;
81 int32 fileid = -1, swathid = -1;
83 fileid = 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 ());
92 int32 swathnamesize = 0;
93 numswath = inqfunc (const_cast < char *>(filename.c_str ()),
NULL,
99 eherr <<
"File " << filename.c_str () <<
" cannot obtain the swath list.";
100 throw InternalErr (__FILE__, __LINE__, eherr.str ());
106 eherr <<
" Currently we only support reading geo-location fields from one swath."
107 <<
" This file has more than one swath. ";
108 throw InternalErr (__FILE__, __LINE__, eherr.str ());
111 char *swathname =
new char[swathnamesize + 1];
112 numswath = inqfunc (const_cast < char *>(filename.c_str ()), swathname,
114 if (numswath == -1) {
118 eherr <<
"File " << filename.c_str () <<
" cannot obtain the swath list.";
119 throw InternalErr (__FILE__, __LINE__, eherr.str ());
122 swathid = attachfunc (fileid, swathname);
126 eherr <<
"Grid/Swath " << swathname <<
" cannot be attached.";
128 throw InternalErr (__FILE__, __LINE__, eherr.str ());
133 int32 tmp_rank = 0, tmp_dims[rank];
134 char tmp_dimlist[1024];
137 r = fieldinfofunc (swathid, const_cast < char *>(fieldname.c_str ()),
138 &tmp_rank, tmp_dims, &type, tmp_dimlist);
140 detachfunc (swathid);
143 eherr <<
"Field " << fieldname.c_str () <<
" information cannot be obtained.";
144 throw InternalErr (__FILE__, __LINE__, eherr.str ());
154 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
155 &offset32[0], &step32[0], &count32[0], &val[0]);
157 detachfunc (swathid);
160 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
161 throw InternalErr (__FILE__, __LINE__, eherr.str ());
164 #ifndef SIGNED_BYTE_TO_INT32
165 set_value ((dods_byte *) &val[0], nelms);
169 newval.resize(nelms);
170 for (
int counter = 0; counter < nelms; counter++)
171 newval[counter] = (int32) (val[counter]);
173 set_value ((dods_int32 *) &newval[0], nelms);
184 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
185 &offset32[0], &step32[0], &count32[0], &val[0]);
187 detachfunc (swathid);
190 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
191 throw InternalErr (__FILE__, __LINE__, eherr.str ());
194 set_value ((dods_byte *) &val[0], nelms);
202 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
203 &offset32[0], &step32[0], &count32[0], &val[0]);
205 detachfunc (swathid);
208 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
209 throw InternalErr (__FILE__, __LINE__, eherr.str ());
212 set_value ((dods_int16 *) &val[0], nelms);
219 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
220 &offset32[0], &step32[0], &count32[0], &val[0]);
222 detachfunc (swathid);
225 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
226 throw InternalErr (__FILE__, __LINE__, eherr.str ());
229 set_value ((dods_uint16 *) &val[0], nelms);
236 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
237 &offset32[0], &step32[0], &count32[0], &val[0]);
239 detachfunc (swathid);
242 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
243 throw InternalErr (__FILE__, __LINE__, eherr.str ());
246 set_value ((dods_int32 *) &val[0], nelms);
253 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
254 &offset32[0], &step32[0], &count32[0], &val[0]);
256 detachfunc (swathid);
259 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
260 throw InternalErr (__FILE__, __LINE__, eherr.str ());
263 set_value ((dods_uint32 *) &val[0], nelms);
270 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
271 &offset32[0], &step32[0], &count32[0], &val[0]);
273 detachfunc (swathid);
276 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
277 throw InternalErr (__FILE__, __LINE__, eherr.str ());
280 set_value ((dods_float32 *) &val[0], nelms);
287 r = readfieldfunc (swathid, const_cast < char *>(fieldname.c_str ()),
288 &offset32[0], &step32[0], &count32[0], &val[0]);
290 detachfunc (swathid);
293 eherr <<
"field " << fieldname.c_str () <<
"cannot be read.";
294 throw InternalErr (__FILE__, __LINE__, eherr.str ());
296 set_value ((dods_float64 *) &val[0], nelms);
303 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
307 r = detachfunc (swathid);
310 throw InternalErr (__FILE__, __LINE__,
"The swath cannot be detached.");
314 r = closefunc (fileid);
318 eherr <<
"Grid/Swath " << filename.c_str () <<
" cannot be closed.";
319 throw InternalErr (__FILE__, __LINE__, eherr.str ());
328 HDFEOS2ArraySwathGeoDimMapExtraField::format_constraint (
int *offset,
int *step,
int *count)
333 Dim_iter p = dim_begin ();
335 while (p != dim_end ()) {
337 int start = dimension_start (p,
true);
338 int stride = dimension_stride (p,
true);
339 int stop = dimension_stop (p,
true);
343 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
346 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
347 ":" << stride <<
":" << stop <<
"]";
348 throw Error (malformed_expr, oss.str ());
352 if (start == 0 && stop == 0 && stride == 0) {
353 start = dimension_start (p,
false);
354 stride = dimension_stride (p,
false);
355 stop = dimension_stop (p,
false);
360 count[id] = ((stop - start) / stride) + 1;
364 "=format_constraint():"
365 <<
"id=" <<
id <<
" offset=" << offset[
id]
366 <<
" step=" << step[
id]
367 <<
" count=" << count[
id]
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream