13 #include "InternalErr.h"
17 #include "HDFCFUtil.h"
19 #include "HDF4RequestHandler.h"
27 HDFEOS2CFStrField::read ()
30 BESDEBUG(
"h4",
"Coming to HDFEOS2CFStrField read "<<endl);
36 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
37 bool check_pass_fileid_key =
false;
38 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
41 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
46 vector<int32>offset32;
47 offset32.resize(rank+1);
49 count32.resize(rank+1);
51 step32.resize(rank+1);
68 nelms = format_constraint (&offset[0], &step[0], &count[0]);
72 for (
int i = 0; i < rank; i++) {
73 offset32[i] = (int32) offset[i];
74 count32[i] = (int32) count[i];
75 step32[i] = (int32) step[i];
79 int32 (*openfunc) (
char *, intn);
80 intn (*closefunc) (int32);
81 int32 (*attachfunc) (int32,
char *);
82 intn (*detachfunc) (int32);
83 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
84 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
88 if(grid_or_swath == 0) {
91 attachfunc = GDattach;
92 detachfunc = GDdetach;
93 fieldinfofunc = GDfieldinfo;
94 readfieldfunc = GDreadfield;
100 attachfunc = SWattach;
101 detachfunc = SWdetach;
102 fieldinfofunc = SWfieldinfo;
103 readfieldfunc = SWreadfield;
107 if (
false == check_pass_fileid_key) {
110 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
113 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
114 throw InternalErr (__FILE__, __LINE__, eherr.str ());
121 int32 gsid = attachfunc (gfid,
const_cast < char *
>(objname.c_str ()));
123 if(
false == check_pass_fileid_key)
126 eherr <<
"Grid/Swath " << objname.c_str () <<
" cannot be attached.";
127 throw InternalErr (__FILE__, __LINE__, eherr.str ());
133 char tmp_dimlist[1024];
134 int32 tmp_dims[rank+1];
135 int32 field_dtype = 0;
137 r = fieldinfofunc (gsid,
const_cast < char *
>(varname.c_str ()),
138 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
141 if(
false == check_pass_fileid_key)
144 eherr <<
"Field " << varname.c_str () <<
" information cannot be obtained.";
145 throw InternalErr (__FILE__, __LINE__, eherr.str ());
149 count32[rank] = tmp_dims[rank];
151 int32 last_dim_size = tmp_dims[rank];
154 val.resize(nelms*count32[rank]);
156 r = readfieldfunc(gsid,
const_cast<char*
>(varname.c_str()),
157 &offset32[0], &step32[0], &count32[0], &val[0]);
161 if(
false == check_pass_fileid_key)
164 eherr <<
"swath or grid readdata failed.";
165 throw InternalErr (__FILE__, __LINE__, eherr.str ());
168 vector<string>final_val;
169 final_val.resize(nelms);
170 vector<char> temp_buf;
171 temp_buf.resize(last_dim_size+1);
175 for (
int i = 0; i<nelms;i++) {
176 strncpy(&temp_buf[0],&val[0]+last_dim_size*i,last_dim_size);
177 temp_buf[last_dim_size]=
'\0';
178 final_val[i] = &temp_buf[0];
180 set_value(&final_val[0],nelms);
183 if(
false == check_pass_fileid_key)
190 HDFEOS2CFStrField::format_constraint (
int *offset,
int *step,
int *count)
195 Dim_iter p = dim_begin ();
196 while (p != dim_end ()) {
198 int start = dimension_start (p,
true);
199 int stride = dimension_stride (p,
true);
200 int stop = dimension_stop (p,
true);
205 oss <<
"Array/Grid hyperslab start point "<< start <<
206 " is greater than stop point " << stop <<
".";
207 throw Error(malformed_expr, oss.str());
212 count[id] = ((stop - start) / stride) + 1;
216 "=format_constraint():"
217 <<
"id=" <<
id <<
" offset=" << offset[
id]
218 <<
" step=" << step[
id]
219 <<
" count=" << count[
id]