36#include <libdap/InternalErr.h>
40#include "HDF4RequestHandler.h"
44HDFCFStr::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),
54BaseType *HDFCFStr::ptr_duplicate()
56 return new HDFCFStr(*
this);
62 BESDEBUG(
"h4",
"Coming to HDFCFStr read "<<endl);
63 bool check_pass_fileid_key = HDF4RequestHandler::get_pass_fileid();
66 if(
false == is_vdata) {
69 if(
false == check_pass_fileid_key) {
70 sdid = SDstart (filename.c_str (), DFACC_READ);
73 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
74 throw InternalErr (__FILE__, __LINE__, eherr.str ());
82 int32 sdsindex = SDreftoindex (sdid, field_ref);
86 eherr <<
"SDS index " << sdsindex <<
" is not right.";
87 throw InternalErr (__FILE__, __LINE__, eherr.str ());
91 sdsid = SDselect (sdid, sdsindex);
95 eherr <<
"SDselect failed.";
96 throw InternalErr (__FILE__, __LINE__, eherr.str ());
99 vector<int32> dim_sizes(H4_MAX_VAR_DIMS);
103 vector<char> name(H4_MAX_NC_NAME);
106 r = SDgetinfo (sdsid, name.data(), &sds_rank, dim_sizes.data(),
107 &data_type, &n_attrs);
112 eherr <<
"SDgetinfo failed.";
113 throw InternalErr (__FILE__, __LINE__, eherr.str ());
120 eherr <<
"The rank of string doesn't match with the rank of character array";
121 throw InternalErr (__FILE__, __LINE__, eherr.str ());
125 vector<int32>offset32;
127 vector<int32>count32;
132 count32[0] = dim_sizes[0];
136 val.resize(count32[0]);
138 r = SDreaddata (sdsid, offset32.data(), step32.data(), count32.data(), val.data());
143 eherr <<
"SDreaddata failed.";
144 throw InternalErr (__FILE__, __LINE__, eherr.str ());
147 string final_str(val.begin(),val.end());
148 set_value(final_str);
156 if(
true == check_pass_fileid_key)
160 file_id = Hopen (filename.c_str (), DFACC_READ, 0);
163 eherr <<
"File " << filename.c_str () <<
" cannot be open.";
164 throw InternalErr (__FILE__, __LINE__, eherr.str ());
170 if (Vstart (file_id) < 0) {
173 eherr <<
"This file cannot be open.";
174 throw InternalErr (__FILE__, __LINE__, eherr.str ());
178 int32 vdref = field_ref;
179 int32 vdata_id = VSattach (file_id, vdref,
"r");
180 if (vdata_id == -1) {
184 eherr <<
"Vdata cannot be attached.";
185 throw InternalErr (__FILE__, __LINE__, eherr.str ());
188 int32 num_rec = VSelts(vdata_id);
195 eherr <<
"The number of elements from this vdata cannot be obtained.";
196 throw InternalErr (__FILE__, __LINE__, eherr.str ());
203 if (VSseek (vdata_id, 0) == -1) {
208 eherr <<
"VSseek failed at " << 0;
209 throw InternalErr (__FILE__, __LINE__, eherr.str ());
213 if (VSsetfields (vdata_id, varname.c_str ()) == -1) {
218 eherr <<
"VSsetfields failed with the name " << varname;
219 throw InternalErr (__FILE__, __LINE__, eherr.str ());
225 if(VSread (vdata_id, (uint8 *) val.data(), num_rec,
226 FULL_INTERLACE) == -1) {
231 eherr <<
"VSread failed.";
232 throw InternalErr (__FILE__, __LINE__, eherr.str ());
235 string final_str(val.begin(),val.end());
236 set_value(final_str);
237 if (VSdetach (vdata_id) == -1) {
241 eherr <<
"VSdetach failed.";
242 throw InternalErr (__FILE__, __LINE__, eherr.str ());
245 if (Vend (file_id) == -1) {
248 eherr <<
"VSdetach failed.";
249 throw InternalErr (__FILE__, __LINE__, eherr.str ());
This class provides a way to map HDF4 1-D character array to DAP Str for the CF option.
static void close_fileid(int32 sdfd, int32 file_id, int32 gridfd, int32 swathfd, bool pass_fileid_key)