36 #include "InternalErr.h"
39 #include "HDFCFUtil.h"
40 #include "HDF4RequestHandler.h"
44 HDFCFStr::HDFCFStr(
const int this_h4fd, int32 sds_field_ref,
const string &h4_filename,
const string &sds_varname,
const string &sds_varnewname,
bool is_h4_vdata)
45 : Str(sds_varnewname, h4_filename),
46 filename(h4_filename),
49 field_ref(sds_field_ref),
57 BaseType *HDFCFStr::ptr_duplicate()
65 BESDEBUG(
"h4",
"Coming to HDFCFStr read "<<endl);
67 string check_pass_fileid_key_str=
"H4.EnablePassFileID";
68 bool check_pass_fileid_key =
false;
69 check_pass_fileid_key = HDFCFUtil::check_beskeys(check_pass_fileid_key_str);
71 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
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, field_ref);
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];
112 r = SDgetinfo (sdsid, name, &sds_rank, dim_sizes,
113 &data_type, &n_attrs);
118 eherr <<
"SDgetinfo failed.";
119 throw InternalErr (__FILE__, __LINE__, eherr.str ());
126 eherr <<
"The rank of string doesn't match with the rank of character array";
127 throw InternalErr (__FILE__, __LINE__, eherr.str ());
131 vector<int32>offset32;
133 vector<int32>count32;
138 count32[0] = dim_sizes[0];
142 val.resize(count32[0]);
144 r = SDreaddata (sdsid, &offset32[0], &step32[0], &count32[0], &val[0]);
149 eherr <<
"SDreaddata failed.";
150 throw InternalErr (__FILE__, __LINE__, eherr.str ());
153 string final_str(val.begin(),val.end());
154 set_value(final_str);
162 if(
true == check_pass_fileid_key)
166 file_id = Hopen (filename.c_str (), DFACC_READ, 0);
169 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
170 throw InternalErr (__FILE__, __LINE__, eherr.str ());
176 if (Vstart (file_id) < 0) {
179 eherr <<
"This file cannot be open.";
180 throw InternalErr (__FILE__, __LINE__, eherr.str ());
184 int32 vdref = field_ref;
185 int32 vdata_id = VSattach (file_id, vdref,
"r");
186 if (vdata_id == -1) {
190 eherr <<
"Vdata cannot be attached.";
191 throw InternalErr (__FILE__, __LINE__, eherr.str ());
194 int32 num_rec = VSelts(vdata_id);
201 eherr <<
"The number of elements from this vdata cannot be obtained.";
202 throw InternalErr (__FILE__, __LINE__, eherr.str ());
209 if (VSseek (vdata_id, 0) == -1) {
214 eherr <<
"VSseek failed at " << 0;
215 throw InternalErr (__FILE__, __LINE__, eherr.str ());
219 if (VSsetfields (vdata_id, varname.c_str ()) == -1) {
224 eherr <<
"VSsetfields failed with the name " << varname;
225 throw InternalErr (__FILE__, __LINE__, eherr.str ());
231 if(VSread (vdata_id, (uint8 *) &val[0], num_rec,
232 FULL_INTERLACE) == -1) {
237 eherr <<
"VSread failed.";
238 throw InternalErr (__FILE__, __LINE__, eherr.str ());
241 string final_str(val.begin(),val.end());
242 set_value(final_str);
243 if (VSdetach (vdata_id) == -1) {
247 eherr <<
"VSdetach failed.";
248 throw InternalErr (__FILE__, __LINE__, eherr.str ());
251 if (Vend (file_id) == -1) {
254 eherr <<
"VSdetach failed.";
255 throw InternalErr (__FILE__, __LINE__, eherr.str ());