10#include "config_hdf.h"
15#include <libdap/debug.h>
16#include <libdap/InternalErr.h>
22#include "HDF4RequestHandler.h"
30HDFEOS2CFStrField::read ()
33 BESDEBUG(
"h4",
"Coming to HDFEOS2CFStrField read "<<endl);
38 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
44 offset32.resize(rank+1);
46 count32.resize(rank+1);
48 step32.resize(rank+1);
65 nelms = format_constraint (offset.data(), step.data(), count.data());
69 for (
int i = 0; i < rank; i++) {
70 offset32[i] = (int32) offset[i];
71 count32[i] = (int32) count[i];
72 step32[i] = (int32) step[i];
76 int32 (*openfunc) (
char *, intn);
77 intn (*closefunc) (int32);
78 int32 (*attachfunc) (int32,
char *);
79 intn (*detachfunc) (int32);
80 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
81 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
85 if (grid_or_swath == 0) {
88 attachfunc = GDattach;
89 detachfunc = GDdetach;
90 fieldinfofunc = GDfieldinfo;
91 readfieldfunc = GDreadfield;
97 attachfunc = SWattach;
98 detachfunc = SWdetach;
99 fieldinfofunc = SWfieldinfo;
100 readfieldfunc = SWreadfield;
104 if (
false == check_pass_fileid_key) {
107 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
110 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
111 throw InternalErr (__FILE__, __LINE__, eherr.str ());
118 int32 gsid = attachfunc (gfid,
const_cast < char *
>(objname.c_str ()));
120 if (
false == check_pass_fileid_key)
123 eherr <<
"Grid/Swath " << objname.c_str () <<
" cannot be attached.";
124 throw InternalErr (__FILE__, __LINE__, eherr.str ());
130 char tmp_dimlist[1024];
131 int32 tmp_dims[rank+1];
132 int32 field_dtype = 0;
134 r = fieldinfofunc (gsid,
const_cast < char *
>(varname.c_str ()),
135 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
138 if (
false == check_pass_fileid_key)
141 eherr <<
"Field " << varname.c_str () <<
" information cannot be obtained.";
142 throw InternalErr (__FILE__, __LINE__, eherr.str ());
146 count32[rank] = tmp_dims[rank];
148 int32 last_dim_size = tmp_dims[rank];
151 val.resize(nelms*count32[rank]);
153 r = readfieldfunc(gsid,
const_cast<char*
>(varname.c_str()),
154 offset32.data(), step32.data(), count32.data(), val.data());
158 if (
false == check_pass_fileid_key)
161 eherr <<
"swath or grid readdata failed.";
162 throw InternalErr (__FILE__, __LINE__, eherr.str ());
166 final_val.resize(nelms);
168 temp_buf.resize(last_dim_size+1);
172 for (
int i = 0; i<nelms;i++) {
173 strncpy(temp_buf.data(),val.data()+last_dim_size*i,last_dim_size);
174 temp_buf[last_dim_size]=
'\0';
175 final_val[i] = temp_buf.data();
177 set_value(final_val.data(),nelms);
180 if (
false == check_pass_fileid_key)
187HDFEOS2CFStrField::format_constraint (
int *offset,
int *step,
int *count)
192 Dim_iter p = dim_begin ();
193 while (p != dim_end ()) {
195 int start = dimension_start (p,
true);
196 int stride = dimension_stride (p,
true);
197 int stop = dimension_stop (p,
true);
202 oss <<
"Array/Grid hyperslab start point "<< start <<
203 " is greater than stop point " << stop <<
".";
204 throw Error(malformed_expr, oss.str());
209 count[id] = ((stop - start) / stride) + 1;
213 "=format_constraint():"
214 <<
"id=" <<
id <<
" offset=" << offset[
id]
215 <<
" step=" << step[
id]
216 <<
" count=" << count[
id]
This class provides a way to map HDFEOS2 character >1D array to DAP Str array for the CF option.