38#include <libdap/InternalErr.h>
46BaseType *HDF5GMSPCFArray::ptr_duplicate()
48 auto HDF5GMSPCFArray_unique = make_unique<HDF5GMSPCFArray>(*
this);
49 return HDF5GMSPCFArray_unique.release();
52bool HDF5GMSPCFArray::read()
54 BESDEBUG(
"h5",
"Coming to HDF5GMSPCFArray read "<<endl);
58 read_data_NOT_from_mem_cache(
false,
nullptr);
63void HDF5GMSPCFArray::read_data_NOT_from_mem_cache(
bool ,
void*) {
65 BESDEBUG(
"h5",
"Coming to HDF5GMSPCFArray: read_data_NOT_from_mem_cache "<<endl);
67 bool check_pass_fileid_key = HDF5RequestHandler::get_pass_fileid();
69 vector<int64_t>offset;
72 vector<hsize_t>hoffset;
73 vector<hsize_t>hcount;
78 if((otype != H5INT64 && otype !=H5UINT64)
80 throw InternalErr (__FILE__, __LINE__,
81 "The datatype of the special product is not right.");
84 throw InternalErr (__FILE__, __LINE__,
85 "The number of dimension of the variable is <=0 for this array.");
96 nelms = format_constraint (offset.data(), step.data(), count.data());
98 for (int64_t i = 0; i <rank; i++) {
99 hoffset[i] = (hsize_t) offset[i];
100 hcount[i] = (hsize_t) count[i];
101 hstep[i] = (hsize_t) step[i];
111 if(
false == check_pass_fileid_key) {
112 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
114 eherr <<
"HDF5 File " << filename
115 <<
" cannot be opened. "<<endl;
116 throw InternalErr (__FILE__, __LINE__, eherr.str ());
120 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
122 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
124 eherr <<
"HDF5 dataset " << varname
125 <<
" cannot be opened. "<<endl;
126 throw InternalErr (__FILE__, __LINE__, eherr.str ());
129 if ((dspace = H5Dget_space(dsetid))<0) {
132 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
134 eherr <<
"Space id of the HDF5 dataset " << varname
135 <<
" cannot be obtained. "<<endl;
136 throw InternalErr (__FILE__, __LINE__, eherr.str ());
140 if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET,
141 hoffset.data(), hstep.data(),
142 hcount.data(),
nullptr) < 0) {
146 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
148 eherr <<
"The selection of hyperslab of the HDF5 dataset " << varname
150 throw InternalErr (__FILE__, __LINE__, eherr.str ());
153 mspace = H5Screate_simple(rank, (
const hsize_t*)hcount.data(),
nullptr);
157 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
159 eherr <<
"The creation of the memory space of the HDF5 dataset " << varname
161 throw InternalErr (__FILE__, __LINE__, eherr.str ());
165 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
169 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
171 eherr <<
"Obtaining the datatype of the HDF5 dataset " << varname
173 throw InternalErr (__FILE__, __LINE__, eherr.str ());
176 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
182 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
184 eherr <<
"Obtaining the memory type of the HDF5 dataset " << varname
186 throw InternalErr (__FILE__, __LINE__, eherr.str ());
190 H5T_class_t ty_class = H5Tget_class(dtypeid);
198 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
200 eherr <<
"Obtaining the type class of the HDF5 dataset " << varname
202 throw InternalErr (__FILE__, __LINE__, eherr.str ());
206 if (ty_class !=H5T_INTEGER) {
212 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
214 eherr <<
"The type class of the HDF5 dataset " << varname
215 <<
" is not H5T_INTEGER. "<<endl;
216 throw InternalErr (__FILE__, __LINE__, eherr.str ());
219 size_t ty_size = H5Tget_size(dtypeid);
220 if (ty_size != H5Tget_size(H5T_STD_I64LE)) {
226 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
228 eherr <<
"The type size of the HDF5 dataset " << varname
229 <<
" is not right. "<<endl;
230 throw InternalErr (__FILE__, __LINE__, eherr.str ());
236 vector<long long>orig_val;
237 orig_val.resize(nelms);
242 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,orig_val.data());
249 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
251 eherr <<
"Cannot read the HDF5 dataset " << varname
252 <<
" with type of 64-bit integer"<<endl;
253 throw InternalErr (__FILE__, __LINE__, eherr.str ());
259 for (
int i = 0; i <numofdbits; i++)
260 max_num = 10 * max_num;
263 for (
int i = 0; i<(sdbit-1) ; i++)
264 num_cut = 10 *num_cut;
273 for (int64_t i = 0; i <nelms; i ++)
274 val[i] = (orig_val[i]/num_cut)%max_num;
277 set_value_ll ((dods_int32 *)val.data(),nelms);
284 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
292HDF5GMSPCFArray::format_constraint (
int *offset,
int *step,
int *count)
297 Dim_iter p = dim_begin ();
299 while (p != dim_end ()) {
301 int start = dimension_start (p,
true);
302 int stride = dimension_stride (p,
true);
303 int stop = dimension_stop (p,
true);
309 oss <<
"Array/Grid hyperslab start point "<< start <<
310 " is greater than stop point " << stop <<
".";
311 throw Error(malformed_expr, oss.str());
317 count[id] = ((stop - start) / stride) + 1;
321 "=format_constraint():"
322 <<
"id=" <<
id <<
" offset=" << offset[
id]
323 <<
" step=" << step[
id]
324 <<
" count=" << count[
id]
This class specifies the retrieval of data values for special HDF5 products Currently this only appli...
include the entry functions to execute the handlers