12 #include "InternalErr.h"
26 BESDEBUG(
"h4",
"Coming to HDFCFStrField read "<<endl);
28 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
29 bool check_pass_fileid_key =
false;
36 vector<int32>offset32;
37 offset32.resize(rank+1);
39 count32.resize(rank+1);
41 step32.resize(rank+1);
58 nelms = format_constraint (&offset[0], &step[0], &count[0]);
62 for (
int i = 0; i < rank; i++) {
63 offset32[i] = (int32) offset[i];
64 count32[i] = (int32) count[i];
65 step32[i] = (int32) step[i];
74 if(
false == is_vdata) {
77 if(
false == check_pass_fileid_key) {
78 sdid = SDstart (const_cast < char *>(filename.c_str ()), DFACC_READ);
81 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
82 throw InternalErr (__FILE__, __LINE__, eherr.str ());
90 int32 sdsindex = SDreftoindex (sdid, fieldref);
94 eherr <<
"SDS index " << sdsindex <<
" is not right.";
95 throw InternalErr (__FILE__, __LINE__, eherr.str ());
99 sdsid = SDselect (sdid, sdsindex);
103 eherr <<
"SDselect failed.";
104 throw InternalErr (__FILE__, __LINE__, eherr.str ());
107 int32 dim_sizes[H4_MAX_VAR_DIMS];
108 int32 sds_rank, data_type, n_attrs;
109 char name[H4_MAX_NC_NAME];
111 r = SDgetinfo (sdsid, name, &sds_rank, dim_sizes,
112 &data_type, &n_attrs);
117 eherr <<
"SDgetinfo failed.";
118 throw InternalErr (__FILE__, __LINE__, eherr.str ());
121 if(sds_rank != (rank+1)) {
125 eherr <<
"The rank of string doesn't match with the rank of character array";
126 throw InternalErr (__FILE__, __LINE__, eherr.str ());
130 count32[rank] = dim_sizes[rank];
132 int32 last_dim_size = dim_sizes[rank];
135 val.resize(nelms*count32[rank]);
137 r = SDreaddata (sdsid, &offset32[0], &step32[0], &count32[0], &val[0]);
142 eherr <<
"SDreaddata failed.";
143 throw InternalErr (__FILE__, __LINE__, eherr.str ());
146 vector<string>final_val;
147 final_val.resize(nelms);
148 vector<char> temp_buf;
149 temp_buf.resize(last_dim_size+1);
154 for (
int i = 0; i<nelms;i++) {
155 strncpy(&temp_buf[0],&val[0]+last_dim_size*i,last_dim_size);
156 temp_buf[last_dim_size]=
'\0';
157 final_val[i] = &temp_buf[0];
159 set_value(&final_val[0],nelms);
168 if(
true == check_pass_fileid_key)
172 file_id = Hopen (filename.c_str (), DFACC_READ, 0);
175 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
176 throw InternalErr (__FILE__, __LINE__, eherr.str ());
181 if (Vstart (file_id) < 0) {
184 eherr <<
"This file cannot be open.";
185 throw InternalErr (__FILE__, __LINE__, eherr.str ());
189 int32 vdata_id = VSattach (file_id, fieldref,
"r");
190 if (vdata_id == -1) {
194 eherr <<
"Vdata cannot be attached.";
195 throw InternalErr (__FILE__, __LINE__, eherr.str ());
201 if (VSseek (vdata_id, (int32) offset32[0]) == -1) {
206 eherr <<
"VSseek failed at " << offset32[0];
207 throw InternalErr (__FILE__, __LINE__, eherr.str ());
211 if (VSsetfields (vdata_id, fieldname.c_str ()) == -1) {
216 eherr <<
"VSsetfields failed with the name " << fieldname;
217 throw InternalErr (__FILE__, __LINE__, eherr.str ());
220 int32 vdfelms = fieldorder * count32[0] * step32[0];
226 r = VSread (vdata_id, (uint8 *) &val[0], 1+(count32[0] -1)* step32[0],
234 eherr <<
"VSread failed.";
235 throw InternalErr (__FILE__, __LINE__, eherr.str ());
238 vector<string>final_val;
239 final_val.resize(nelms);
241 vector<char> temp_buf;
242 temp_buf.resize(fieldorder+1);
243 for (
int i = 0; i<nelms;i++) {
244 strncpy(&temp_buf[0],&val[0]+fieldorder*i*step32[0],fieldorder);
245 temp_buf[fieldorder]=
'\0';
246 final_val[i] = &temp_buf[0];
248 set_value(&final_val[0],nelms);
264 Dim_iter p = dim_begin ();
266 while (p != dim_end ()) {
268 int start = dimension_start (p,
true);
269 int stride = dimension_stride (p,
true);
270 int stop = dimension_stop (p,
true);
274 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
277 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
278 ":" << stride <<
":" << stop <<
"]";
279 throw Error (malformed_expr, oss.str ());
283 if (start == 0 && stop == 0 && stride == 0) {
284 start = dimension_start (p,
false);
285 stride = dimension_stride (p,
false);
286 stop = dimension_stop (p,
false);
291 count[id] = ((stop - start) / stride) + 1;
295 "=format_constraint():"
296 <<
"id=" <<
id <<
" offset=" << offset[
id]
297 <<
" step=" << step[
id]
298 <<
" 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
int format_constraint(int *cor, int *step, int *edg)