10 #include "config_hdf.h"
15 #include <libdap/debug.h>
16 #include <libdap/InternalErr.h>
20 #include "HDFCFUtil.h"
22 #include "HDF4RequestHandler.h"
30 HDFEOS2CFStrField::read ()
33 BESDEBUG(
"h4",
"Coming to HDFEOS2CFStrField read "<<endl);
39 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
40 bool check_pass_fileid_key =
false;
41 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
44 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
49 vector<int32>offset32;
50 offset32.resize(rank+1);
52 count32.resize(rank+1);
54 step32.resize(rank+1);
71 nelms = format_constraint (&offset[0], &step[0], &count[0]);
75 for (
int i = 0; i < rank; i++) {
76 offset32[i] = (int32) offset[i];
77 count32[i] = (int32) count[i];
78 step32[i] = (int32) step[i];
82 int32 (*openfunc) (
char *, intn);
83 intn (*closefunc) (int32);
84 int32 (*attachfunc) (int32,
char *);
85 intn (*detachfunc) (int32);
86 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
87 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
91 if(grid_or_swath == 0) {
94 attachfunc = GDattach;
95 detachfunc = GDdetach;
96 fieldinfofunc = GDfieldinfo;
97 readfieldfunc = GDreadfield;
103 attachfunc = SWattach;
104 detachfunc = SWdetach;
105 fieldinfofunc = SWfieldinfo;
106 readfieldfunc = SWreadfield;
110 if (
false == check_pass_fileid_key) {
113 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
116 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
117 throw InternalErr (__FILE__, __LINE__, eherr.str ());
124 int32 gsid = attachfunc (gfid,
const_cast < char *
>(objname.c_str ()));
126 if(
false == check_pass_fileid_key)
129 eherr <<
"Grid/Swath " << objname.c_str () <<
" cannot be attached.";
130 throw InternalErr (__FILE__, __LINE__, eherr.str ());
136 char tmp_dimlist[1024];
137 int32 tmp_dims[rank+1];
138 int32 field_dtype = 0;
140 r = fieldinfofunc (gsid,
const_cast < char *
>(varname.c_str ()),
141 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
144 if(
false == check_pass_fileid_key)
147 eherr <<
"Field " << varname.c_str () <<
" information cannot be obtained.";
148 throw InternalErr (__FILE__, __LINE__, eherr.str ());
152 count32[rank] = tmp_dims[rank];
154 int32 last_dim_size = tmp_dims[rank];
157 val.resize(nelms*count32[rank]);
159 r = readfieldfunc(gsid,
const_cast<char*
>(varname.c_str()),
160 &offset32[0], &step32[0], &count32[0], &val[0]);
164 if(
false == check_pass_fileid_key)
167 eherr <<
"swath or grid readdata failed.";
168 throw InternalErr (__FILE__, __LINE__, eherr.str ());
171 vector<string>final_val;
172 final_val.resize(nelms);
173 vector<char> temp_buf;
174 temp_buf.resize(last_dim_size+1);
178 for (
int i = 0; i<nelms;i++) {
179 strncpy(&temp_buf[0],&val[0]+last_dim_size*i,last_dim_size);
180 temp_buf[last_dim_size]=
'\0';
181 final_val[i] = &temp_buf[0];
183 set_value(&final_val[0],nelms);
186 if(
false == check_pass_fileid_key)
193 HDFEOS2CFStrField::format_constraint (
int *offset,
int *step,
int *count)
198 Dim_iter p = dim_begin ();
199 while (p != dim_end ()) {
201 int start = dimension_start (p,
true);
202 int stride = dimension_stride (p,
true);
203 int stop = dimension_stop (p,
true);
208 oss <<
"Array/Grid hyperslab start point "<< start <<
209 " is greater than stop point " << stop <<
".";
210 throw Error(malformed_expr, oss.str());
215 count[id] = ((stop - start) / stride) + 1;
219 "=format_constraint():"
220 <<
"id=" <<
id <<
" offset=" << offset[
id]
221 <<
" step=" << step[
id]
222 <<
" count=" << count[
id]
This class provides a way to map HDFEOS2 character >1D array to DAP Str array for the CF option.