18 #include "InternalErr.h"
23 #define SIGNED_BYTE_TO_INT32 1
30 BESDEBUG(
"h4",
"Coming to HDFSPArray_VDField read "<<endl);
32 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
33 bool check_pass_fileid_key =
false;
45 int nelms = format_constraint(&offset[0],&step[0],&count[0]);
49 if(
true == check_pass_fileid_key)
54 file_id = Hopen (filename.c_str (), DFACC_READ, 0);
57 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
58 throw InternalErr (__FILE__, __LINE__, eherr.str ());
64 if (Vstart (file_id) < 0) {
67 eherr <<
"This file cannot be open.";
68 throw InternalErr (__FILE__, __LINE__, eherr.str ());
72 vdata_id = VSattach (file_id, vdref,
"r");
77 eherr <<
"Vdata cannot be attached.";
78 throw InternalErr (__FILE__, __LINE__, eherr.str ());
85 if (VSseek (vdata_id, (int32) offset[0]) == -1) {
87 eherr <<
"VSseek failed at " << offset[0];
88 throw InternalErr (__FILE__, __LINE__, eherr.str ());
92 if (VSsetfields (vdata_id, fdname.c_str ()) == -1) {
94 eherr <<
"VSsetfields failed with the name " << fdname;
95 throw InternalErr (__FILE__, __LINE__, eherr.str ());
98 int32 vdfelms = fdorder * count[0] * step[0];
108 orival.resize(vdfelms);
111 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
116 eherr <<
"VSread failed.";
117 throw InternalErr (__FILE__, __LINE__, eherr.str ());
122 for (
int i = 0; i < count[0]; i++)
123 for (
int j = 0; j < count[1]; j++)
124 val[i * count[1] + j] =
125 orival[i * fdorder * step[0] + offset[1] + j * step[1]];
128 for (
int i = 0; i < count[0]; i++)
129 val[i] = orival[i * step[0]];
133 #ifndef SIGNED_BYTE_TO_INT32
134 set_value ((dods_byte *) &val[0], nelms);
137 newval.resize(nelms);
139 for (
int counter = 0; counter < nelms; counter++)
140 newval[counter] = (int32) (val[counter]);
142 set_value ((dods_int32 *) &newval[0], nelms);
156 orival.resize(vdfelms);
158 r = VSread (vdata_id, &orival[0], 1+(count[0] -1)* step[0], FULL_INTERLACE);
161 eherr <<
"VSread failed.";
162 throw InternalErr (__FILE__, __LINE__, eherr.str ());
166 for (
int i = 0; i < count[0]; i++)
167 for (
int j = 0; j < count[1]; j++)
168 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
171 for (
int i = 0; i < count[0]; i++)
172 val[i] = orival[i * step[0]];
175 set_value ((dods_byte *) &val[0], nelms);
185 orival.resize(vdfelms);
187 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
191 eherr <<
"VSread failed.";
192 throw InternalErr (__FILE__, __LINE__, eherr.str ());
196 for (
int i = 0; i < count[0]; i++)
197 for (
int j = 0; j < count[1]; j++)
198 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
201 for (
int i = 0; i < count[0]; i++)
202 val[i] = orival[i * step[0]];
205 set_value ((dods_int16 *) &val[0], nelms);
215 vector<uint16>orival;
216 orival.resize(vdfelms);
218 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
222 eherr <<
"VSread failed.";
223 throw InternalErr (__FILE__, __LINE__, eherr.str ());
227 for (
int i = 0; i < count[0]; i++)
228 for (
int j = 0; j < count[1]; j++)
229 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
232 for (
int i = 0; i < count[0]; i++)
233 val[i] = orival[i * step[0]];
236 set_value ((dods_uint16 *) &val[0], nelms);
244 orival.resize(vdfelms);
246 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
250 eherr <<
"VSread failed.";
251 throw InternalErr (__FILE__, __LINE__, eherr.str ());
255 for (
int i = 0; i < count[0]; i++)
256 for (
int j = 0; j < count[1]; j++)
257 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
260 for (
int i = 0; i < count[0]; i++)
261 val[i] = orival[i * step[0]];
264 set_value ((dods_int32 *) &val[0], nelms);
274 vector<uint32>orival;
275 orival.resize(vdfelms);
277 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
281 eherr <<
"VSread failed.";
282 throw InternalErr (__FILE__, __LINE__, eherr.str ());
286 for (
int i = 0; i < count[0]; i++)
287 for (
int j = 0; j < count[1]; j++)
288 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
291 for (
int i = 0; i < count[0]; i++)
292 val[i] = orival[i * step[0]];
295 set_value ((dods_uint32 *) &val[0], nelms);
302 vector<float32>orival;
303 orival.resize(vdfelms);
305 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
309 eherr <<
"VSread failed.";
310 throw InternalErr (__FILE__, __LINE__, eherr.str ());
314 for (
int i = 0; i < count[0]; i++)
315 for (
int j = 0; j < count[1]; j++)
316 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
319 for (
int i = 0; i < count[0]; i++)
320 val[i] = orival[i * step[0]];
323 set_value ((dods_float32 *) &val[0], nelms);
332 vector<float64>orival;
333 orival.resize(vdfelms);
335 r = VSread (vdata_id, (uint8 *) &orival[0], 1+(count[0] -1)* step[0],
339 eherr <<
"VSread failed.";
340 throw InternalErr (__FILE__, __LINE__, eherr.str ());
344 for (
int i = 0; i < count[0]; i++)
345 for (
int j = 0; j < count[1]; j++)
346 val[i * count[1] + j] = orival[i * fdorder * step[0] + offset[1] + j * step[1]];
349 for (
int i = 0; i < count[0]; i++)
350 val[i] = orival[i * step[0]];
353 set_value ((dods_float64 *) &val[0], nelms);
357 InternalErr (__FILE__, __LINE__,
"unsupported data type.");
360 if (VSdetach (vdata_id) == -1) {
362 eherr <<
"VSdetach failed.";
363 throw InternalErr (__FILE__, __LINE__, eherr.str ());
366 if (Vend (file_id) == -1) {
369 eherr <<
"VSdetach failed.";
370 throw InternalErr (__FILE__, __LINE__, eherr.str ());
383 if (Hclose (file_id) == -1) {
387 eherr <<
"VSdetach failed.";
388 throw InternalErr (__FILE__, __LINE__, eherr.str ());
403 Dim_iter p = dim_begin ();
405 while (p != dim_end ()) {
407 int start = dimension_start (p,
true);
408 int stride = dimension_stride (p,
true);
409 int stop = dimension_stop (p,
true);
413 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
416 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
417 ":" << stride <<
":" << stop <<
"]";
418 throw Error (malformed_expr, oss.str ());
422 if (start == 0 && stop == 0 && stride == 0) {
423 start = dimension_start (p,
false);
424 stride = dimension_stride (p,
false);
425 stop = dimension_stop (p,
false);
430 count[id] = ((stop - start) / stride) + 1;
434 "=format_constraint():"
435 <<
"id=" <<
id <<
" offset=" << offset[
id]
436 <<
" step=" << step[
id]
437 <<
" count=" << count[
id]
int format_constraint(int *cor, int *step, int *edg)
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