38 #include "InternalErr.h"
50 BESDEBUG(
"h5",
"Coming to HDF5GMSPCFArray read "<<endl);
51 string check_pass_fileid_key_str=
"H5.EnablePassFileID";
52 bool check_pass_fileid_key =
false;
58 vector<hsize_t>hoffset;
59 vector<hsize_t>hcount;
66 throw InternalErr (__FILE__, __LINE__,
67 "The datatype of the special product is not right.");
70 throw InternalErr (__FILE__, __LINE__,
71 "The number of dimension of the variable is negative.");
87 for (
int i = 0; i <rank; i++) {
88 hoffset[i] = (hsize_t) offset[i];
89 hcount[i] = (hsize_t) count[i];
90 hstep[i] = (hsize_t) step[i];
101 if(
false == check_pass_fileid_key) {
102 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
104 eherr <<
"HDF5 File " << filename
105 <<
" cannot be opened. "<<endl;
106 throw InternalErr (__FILE__, __LINE__, eherr.str ());
110 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
114 eherr <<
"HDF5 dataset " << varname
115 <<
" cannot be opened. "<<endl;
116 throw InternalErr (__FILE__, __LINE__, eherr.str ());
119 if ((dspace = H5Dget_space(dsetid))<0) {
124 eherr <<
"Space id of the HDF5 dataset " << varname
125 <<
" cannot be obtained. "<<endl;
126 throw InternalErr (__FILE__, __LINE__, eherr.str ());
131 if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET,
132 &hoffset[0], &hstep[0],
133 &hcount[0],
NULL) < 0) {
139 eherr <<
"The selection of hyperslab of the HDF5 dataset " << varname
141 throw InternalErr (__FILE__, __LINE__, eherr.str ());
144 mspace = H5Screate_simple(rank, (
const hsize_t*)&hcount[0],
NULL);
150 eherr <<
"The creation of the memory space of the HDF5 dataset " << varname
152 throw InternalErr (__FILE__, __LINE__, eherr.str ());
158 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
165 eherr <<
"Obtaining the datatype of the HDF5 dataset " << varname
167 throw InternalErr (__FILE__, __LINE__, eherr.str ());
170 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
179 eherr <<
"Obtaining the memory type of the HDF5 dataset " << varname
181 throw InternalErr (__FILE__, __LINE__, eherr.str ());
185 H5T_class_t ty_class = H5Tget_class(dtypeid);
196 eherr <<
"Obtaining the type class of the HDF5 dataset " << varname
198 throw InternalErr (__FILE__, __LINE__, eherr.str ());
202 if (ty_class !=H5T_INTEGER) {
211 eherr <<
"The type class of the HDF5 dataset " << varname
212 <<
" is not H5T_INTEGER. "<<endl;
213 throw InternalErr (__FILE__, __LINE__, eherr.str ());
216 size_t ty_size = H5Tget_size(dtypeid);
217 if (ty_size != H5Tget_size(H5T_STD_I64LE)) {
226 eherr <<
"The type size of the HDF5 dataset " << varname
227 <<
" is not right. "<<endl;
228 throw InternalErr (__FILE__, __LINE__, eherr.str ());
234 vector<long long>orig_val;
235 orig_val.resize(nelms);
241 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&orig_val[0]);
243 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&orig_val[0]);
254 eherr <<
"Cannot read the HDF5 dataset " << varname
255 <<
" with type of 64-bit integer"<<endl;
256 throw InternalErr (__FILE__, __LINE__, eherr.str ());
262 for (
int i = 0; i <numofdbits; i++)
263 max_num = 10 * max_num;
266 for (
int i = 0; i<(sdbit-1) ; i++)
267 num_cut = 10 *num_cut;
276 for (
int i = 0; i <nelms; i ++)
277 val[i] = (orig_val[i]/num_cut)%max_num;
280 set_value ((dods_int32 *)&val[0],nelms);
302 Dim_iter p = dim_begin ();
304 while (p != dim_end ()) {
306 int start = dimension_start (p,
true);
307 int stride = dimension_stride (p,
true);
308 int stop = dimension_stop (p,
true);
312 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
315 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
316 ":" << stride <<
":" << stop <<
"]";
317 throw Error (malformed_expr, oss.str ());
321 if (start == 0 && stop == 0 && stride == 0) {
322 start = dimension_start (p,
false);
323 stride = dimension_stride (p,
false);
324 stop = dimension_stop (p,
false);
329 count[id] = ((stop - start) / stride) + 1;
333 "=format_constraint():"
334 <<
"id=" <<
id <<
" offset=" << offset[
id]
335 <<
" step=" << step[
id]
336 <<
" count=" << count[
id]
HDF5GMSPCFArray(int rank, const string &filename, const hid_t fileid, H5DataType dtype, const string &varfullpath, H5DataType otype, int sdbit, int numofdbits, const string &n="", BaseType *v=0)
static void close_fileid(hid_t, bool)
virtual BaseType * ptr_duplicate()
static bool check_beskeys(const string key)
int format_constraint(int *cor, int *step, int *edg)
This class specifies the retrieval of data values for special HDF5 products Currently this only appli...
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream