36 #include "InternalErr.h"
54 BESDEBUG(
"h5",
"Coming to HDF5CFArray read "<<endl);
55 string check_pass_fileid_key_str=
"H5.EnablePassFileID";
56 bool check_pass_fileid_key =
false;
62 vector<hsize_t> hoffset;
63 vector<hsize_t>hcount;
69 throw InternalErr (__FILE__, __LINE__,
70 "The number of dimension of the variable is negative.");
82 for (
int i = 0; i <rank; i++) {
83 hoffset[i] = (hsize_t) offset[i];
84 hcount[i] = (hsize_t) count[i];
85 hstep[i] = (hsize_t) step[i];
98 if(
false == check_pass_fileid_key) {
99 if ((fileid = H5Fopen(filename.c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
101 eherr <<
"HDF5 File " << filename
102 <<
" cannot be opened. "<<endl;
103 throw InternalErr (__FILE__, __LINE__, eherr.str ());
108 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
113 eherr <<
"HDF5 dataset " << varname
114 <<
" cannot be opened. "<<endl;
115 throw InternalErr (__FILE__, __LINE__, eherr.str ());
118 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 ());
130 if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET,
131 &hoffset[0], &hstep[0],
132 &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, &hcount[0],
NULL);
151 eherr <<
"The creation of the memory space of the HDF5 dataset " << varname
153 throw InternalErr (__FILE__, __LINE__, eherr.str ());
158 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
167 eherr <<
"Obtaining the datatype of the HDF5 dataset " << varname
169 throw InternalErr (__FILE__, __LINE__, eherr.str ());
173 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
183 eherr <<
"Obtaining the memory type of the HDF5 dataset " << varname
185 throw InternalErr (__FILE__, __LINE__, eherr.str ());
199 vector<unsigned char> val;
204 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
206 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
218 eherr <<
"Cannot read the HDF5 dataset " << varname
219 <<
" with the type of H5T_NATIVE_UCHAR "<<endl;
220 throw InternalErr (__FILE__, __LINE__, eherr.str ());
223 set_value ((dods_byte *) &val[0], nelms);
235 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
237 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
250 eherr <<
"Cannot read the HDF5 dataset " << varname
251 <<
" with the type of H5T_NATIVE_CHAR "<<endl;
252 throw InternalErr (__FILE__, __LINE__, eherr.str ());
257 newval.resize(nelms);
259 for (
int counter = 0; counter < nelms; counter++)
260 newval[counter] = (
short) (val[counter]);
262 set_value ((dods_int16 *) &newval[0], nelms);
273 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
275 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
288 eherr <<
"Cannot read the HDF5 dataset " << varname
289 <<
" with the type of H5T_NATIVE_SHORT "<<endl;
290 throw InternalErr (__FILE__, __LINE__, eherr.str ());
293 set_value ((dods_int16 *) &val[0], nelms);
300 vector<unsigned short> val;
303 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
305 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
309 if (rank > 0) H5Sclose(mspace);
317 eherr <<
"Cannot read the HDF5 dataset " << varname
318 <<
" with the type of H5T_NATIVE_USHORT "<<endl;
319 throw InternalErr (__FILE__, __LINE__, eherr.str ());
322 set_value ((dods_uint16 *) &val[0], nelms);
332 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
334 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
346 eherr <<
"Cannot read the HDF5 dataset " << varname
347 <<
" with the type of H5T_NATIVE_INT "<<endl;
348 throw InternalErr (__FILE__, __LINE__, eherr.str ());
351 set_value ((dods_int32 *) &val[0], nelms);
357 vector<unsigned int>val;
360 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
362 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
375 eherr <<
"Cannot read the HDF5 dataset " << varname
376 <<
" with the type of H5T_NATIVE_UINT "<<endl;
377 throw InternalErr (__FILE__, __LINE__, eherr.str ());
380 set_value ((dods_uint32 *) &val[0], nelms);
391 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
393 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
405 eherr <<
"Cannot read the HDF5 dataset " << varname
406 <<
" with the type of H5T_NATIVE_FLOAT "<<endl;
407 throw InternalErr (__FILE__, __LINE__, eherr.str ());
410 set_value ((dods_float32 *) &val[0], nelms);
421 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,&val[0]);
423 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,&val[0]);
435 eherr <<
"Cannot read the HDF5 dataset " << varname
436 <<
" with the type of H5T_NATIVE_DOUBLE "<<endl;
437 throw InternalErr (__FILE__, __LINE__, eherr.str ());
440 set_value ((dods_float64 *) &val[0], nelms);
447 size_t ty_size = H5Tget_size(dtypeid);
458 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
460 throw InternalErr (__FILE__, __LINE__, eherr.str ());
463 vector <char> strval;
464 strval.resize(nelms*ty_size);
466 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)&strval[0]);
468 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,(
void*)&strval[0]);
480 eherr <<
"Cannot read the HDF5 dataset " << varname
481 <<
" with the type of the fixed size HDF5 string "<<endl;
482 throw InternalErr (__FILE__, __LINE__, eherr.str ());
485 string total_string(strval.begin(),strval.end());
487 vector <string> finstrval;
488 finstrval.resize(nelms);
489 for (
int i = 0; i<nelms; i++)
490 finstrval[i] = total_string.substr(i*ty_size,ty_size);
493 string check_droplongstr_key =
"H5.EnableDropLongString";
494 bool is_droplongstr =
false;
501 if (
true == is_droplongstr &&
503 for (
int i = 0; i<nelms; i++)
506 set_value(finstrval,nelms);
507 total_string.clear();
514 size_t ty_size = H5Tget_size(memtype);
525 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
527 throw InternalErr (__FILE__, __LINE__, eherr.str ());
529 vector <char> strval;
530 strval.resize(nelms*ty_size);
532 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)&strval[0]);
534 read_ret = H5Dread(dsetid,memtype,mspace,dspace,H5P_DEFAULT,(
void*)&strval[0]);
546 eherr <<
"Cannot read the HDF5 dataset " << varname
547 <<
" with the type of the HDF5 variable length string "<<endl;
548 throw InternalErr (__FILE__, __LINE__, eherr.str ());
551 vector<string>finstrval;
552 finstrval.resize(nelms);
553 char*temp_bp = &strval[0];
554 char*onestring =
NULL;
555 for (
int i =0;i<nelms;i++) {
556 onestring = *(
char**)temp_bp;
558 finstrval[i] =string(onestring);
565 if (
false == strval.empty()) {
566 herr_t ret_vlen_claim;
568 ret_vlen_claim = H5Dvlen_reclaim(memtype,dspace,H5P_DEFAULT,(
void*)&strval[0]);
570 ret_vlen_claim = H5Dvlen_reclaim(memtype,mspace,H5P_DEFAULT,(
void*)&strval[0]);
571 if (ret_vlen_claim < 0){
581 eherr <<
"Cannot reclaim the memory buffer of the HDF5 variable length string of the dataset "
583 throw InternalErr (__FILE__, __LINE__, eherr.str ());
589 string check_droplongstr_key =
"H5.EnableDropLongString";
590 bool is_droplongstr =
false;
597 if (
true == is_droplongstr) {
598 size_t total_str_size = 0;
599 for (
int i =0;i<nelms;i++)
600 total_str_size += finstrval[i].size();
602 for (
int i =0;i<nelms;i++)
606 set_value(finstrval,nelms);
622 eherr <<
"Cannot read the HDF5 dataset " << varname
623 <<
" with the unsupported HDF5 datatype"<<endl;
624 throw InternalErr (__FILE__, __LINE__, eherr.str ());
649 Dim_iter p = dim_begin ();
651 while (p != dim_end ()) {
653 int start = dimension_start (p,
true);
654 int stride = dimension_stride (p,
true);
655 int stop = dimension_stop (p,
true);
659 if (stride < 0 || start < 0 || stop < 0 || start > stop) {
662 oss <<
"Array/Grid hyperslab indices are bad: [" << start <<
663 ":" << stride <<
":" << stop <<
"]";
664 throw Error (malformed_expr, oss.str ());
668 if (start == 0 && stop == 0 && stride == 0) {
669 start = dimension_start (p,
false);
670 stride = dimension_stride (p,
false);
671 stop = dimension_stop (p,
false);
676 count[id] = ((stop - start) / stride) + 1;
680 "=format_constraint():"
681 <<
"id=" <<
id <<
" offset=" << offset[
id]
682 <<
" step=" << step[
id]
683 <<
" count=" << count[
id]
static void close_fileid(hid_t, bool)
#define NC_JAVA_STR_SIZE_LIMIT
static bool check_beskeys(const string key)
int format_constraint(int *cor, int *step, int *edg)
HDF5CFArray(int rank, const hid_t file_id, const string &filename, H5DataType dtype, const string &varfullpath, const string &n="", BaseType *v=0)
This class includes the methods to read data array into DAP buffer from an HDF5 dataset for the CF op...
virtual BaseType * ptr_duplicate()
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream