14 #include "InternalErr.h"
18 #include "HDFCFUtil.h"
20 #include "HDF4RequestHandler.h"
25 HDFEOS2CFStr::HDFEOS2CFStr(
const int gsfd,
26 const std::string &filename,
27 const std::string &objname,
28 const std::string &varname,
29 const std::string &varnewname,
31 :Str(varnewname,filename),
36 grid_or_swath(grid_or_swath)
40 HDFEOS2CFStr::~HDFEOS2CFStr()
43 BaseType *HDFEOS2CFStr::ptr_duplicate()
45 return new HDFEOS2CFStr(*
this);
52 BESDEBUG(
"h4",
"Coming to HDFEOS2CFStr read "<<endl);
55 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
56 bool check_pass_fileid_key =
false;
57 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
59 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
62 int32 (*openfunc) (
char *, intn);
63 intn (*closefunc) (int32);
64 int32 (*attachfunc) (int32,
char *);
65 intn (*detachfunc) (int32);
66 intn (*fieldinfofunc) (int32,
char *, int32 *, int32 *, int32 *,
char *);
67 intn (*readfieldfunc) (int32,
char *, int32 *, int32 *, int32 *,
void *);
71 if(grid_or_swath == 0) {
74 attachfunc = GDattach;
75 detachfunc = GDdetach;
76 fieldinfofunc = GDfieldinfo;
77 readfieldfunc = GDreadfield;
83 attachfunc = SWattach;
84 detachfunc = SWdetach;
85 fieldinfofunc = SWfieldinfo;
86 readfieldfunc = SWreadfield;
90 if (
false == check_pass_fileid_key) {
93 gfid = openfunc (
const_cast < char *
>(filename.c_str ()), DFACC_READ);
96 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
97 throw InternalErr (__FILE__, __LINE__, eherr.str ());
104 int32 gsid = attachfunc (gfid,
const_cast < char *
>(objname.c_str ()));
106 if(
false == check_pass_fileid_key)
109 eherr <<
"Grid/Swath " << objname.c_str () <<
" cannot be attached.";
110 throw InternalErr (__FILE__, __LINE__, eherr.str ());
116 char tmp_dimlist[1024];
118 int32 field_dtype = 0;
120 r = fieldinfofunc (gsid,
const_cast < char *
>(varname.c_str ()),
121 &tmp_rank, tmp_dims, &field_dtype, tmp_dimlist);
124 if(
false == check_pass_fileid_key)
127 eherr <<
"Field " << varname.c_str () <<
" information cannot be obtained.";
128 throw InternalErr (__FILE__, __LINE__, eherr.str ());
132 vector<int32>offset32;
134 vector<int32>count32;
139 count32[0] = tmp_dims[0];
143 val.resize(count32[0]);
145 r = readfieldfunc(gsid,
const_cast<char*
>(varname.c_str()),
146 &offset32[0], &step32[0], &count32[0], &val[0]);
150 if(
false == check_pass_fileid_key)
153 eherr <<
"swath or grid readdata failed.";
154 throw InternalErr (__FILE__, __LINE__, eherr.str ());
157 string final_str(val.begin(),val.end());
158 set_value(final_str);
160 if(
false == check_pass_fileid_key)