33#include "config_hdf5.h"
38#include <libdap/InternalErr.h>
46BaseType *HDF5GMSPCFArray::ptr_duplicate()
51bool HDF5GMSPCFArray::read()
53 BESDEBUG(
"h5",
"Coming to HDF5GMSPCFArray read "<<endl);
57 read_data_NOT_from_mem_cache(
false,
nullptr);
62void HDF5GMSPCFArray::read_data_NOT_from_mem_cache(
bool ,
void*) {
64 BESDEBUG(
"h5",
"Coming to HDF5GMSPCFArray: read_data_NOT_from_mem_cache "<<endl);
66 bool check_pass_fileid_key = HDF5RequestHandler::get_pass_fileid();
71 vector<hsize_t>hoffset;
72 vector<hsize_t>hcount;
77 if((otype != H5INT64 && otype !=H5UINT64)
79 throw InternalErr (__FILE__, __LINE__,
80 "The datatype of the special product is not right.");
83 throw InternalErr (__FILE__, __LINE__,
84 "The number of dimension of the variable is <=0 for this array.");
95 nelms = format_constraint (offset.data(), step.data(), count.data());
97 for (
int i = 0; i <rank; i++) {
98 hoffset[i] = (hsize_t) offset[i];
99 hcount[i] = (hsize_t) count[i];
100 hstep[i] = (hsize_t) step[i];
110 if(
false == check_pass_fileid_key) {
111 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
113 eherr <<
"HDF5 File " << filename
114 <<
" cannot be opened. "<<endl;
115 throw InternalErr (__FILE__, __LINE__, eherr.str ());
119 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
121 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
123 eherr <<
"HDF5 dataset " << varname
124 <<
" cannot be opened. "<<endl;
125 throw InternalErr (__FILE__, __LINE__, eherr.str ());
128 if ((dspace = H5Dget_space(dsetid))<0) {
131 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
133 eherr <<
"Space id of the HDF5 dataset " << varname
134 <<
" cannot be obtained. "<<endl;
135 throw InternalErr (__FILE__, __LINE__, eherr.str ());
139 if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET,
140 hoffset.data(), hstep.data(),
141 hcount.data(),
nullptr) < 0) {
145 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
147 eherr <<
"The selection of hyperslab of the HDF5 dataset " << varname
149 throw InternalErr (__FILE__, __LINE__, eherr.str ());
152 mspace = H5Screate_simple(rank, (
const hsize_t*)hcount.data(),
nullptr);
156 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
158 eherr <<
"The creation of the memory space of the HDF5 dataset " << varname
160 throw InternalErr (__FILE__, __LINE__, eherr.str ());
164 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
168 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
170 eherr <<
"Obtaining the datatype of the HDF5 dataset " << varname
172 throw InternalErr (__FILE__, __LINE__, eherr.str ());
175 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
181 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
183 eherr <<
"Obtaining the memory type of the HDF5 dataset " << varname
185 throw InternalErr (__FILE__, __LINE__, eherr.str ());
189 H5T_class_t ty_class = H5Tget_class(dtypeid);
197 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
199 eherr <<
"Obtaining the type class of the HDF5 dataset " << varname
201 throw InternalErr (__FILE__, __LINE__, eherr.str ());
205 if (ty_class !=H5T_INTEGER) {
211 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
213 eherr <<
"The type class of the HDF5 dataset " << varname
214 <<
" is not H5T_INTEGER. "<<endl;
215 throw InternalErr (__FILE__, __LINE__, eherr.str ());
218 size_t ty_size = H5Tget_size(dtypeid);
219 if (ty_size != H5Tget_size(H5T_STD_I64LE)) {
225 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
227 eherr <<
"The type size of the HDF5 dataset " << varname
228 <<
" is not right. "<<endl;
229 throw InternalErr (__FILE__, __LINE__, eherr.str ());
235 vector<long long>orig_val;
236 orig_val.resize(nelms);
241 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,orig_val.data());
248 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
250 eherr <<
"Cannot read the HDF5 dataset " << varname
251 <<
" with type of 64-bit integer"<<endl;
252 throw InternalErr (__FILE__, __LINE__, eherr.str ());
258 for (
int i = 0; i <numofdbits; i++)
259 max_num = 10 * max_num;
262 for (
int i = 0; i<(sdbit-1) ; i++)
263 num_cut = 10 *num_cut;
272 for (
int i = 0; i <nelms; i ++)
273 val[i] = (orig_val[i]/num_cut)%max_num;
276 set_value ((dods_int32 *)val.data(),nelms);
283 HDF5CFUtil::close_fileid(fileid,check_pass_fileid_key);
291HDF5GMSPCFArray::format_constraint (
int *offset,
int *step,
int *count)
296 Dim_iter p = dim_begin ();
298 while (p != dim_end ()) {
300 int start = dimension_start (p,
true);
301 int stride = dimension_stride (p,
true);
302 int stop = dimension_stop (p,
true);
308 oss <<
"Array/Grid hyperslab start point "<< start <<
309 " is greater than stop point " << stop <<
".";
310 throw Error(malformed_expr, oss.str());
316 count[id] = ((stop - start) / stride) + 1;
320 "=format_constraint():"
321 <<
"id=" <<
id <<
" offset=" << offset[
id]
322 <<
" step=" << step[
id]
323 <<
" 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