39 #include "InternalErr.h"
45 : Str(n, d), varname(varname)
60 BESDEBUG(
"h5",
"Coming to HDF5CFStr read "<<endl);
67 if ((fileid = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
69 eherr <<
"HDF5 File " << dataset()
70 <<
" cannot be opened. "<<endl;
71 throw InternalErr (__FILE__, __LINE__, eherr.str ());
74 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
77 eherr <<
"HDF5 dataset " << name()
78 <<
" cannot be opened. "<<endl;
79 throw InternalErr (__FILE__, __LINE__, eherr.str ());
82 if ((dspace = H5Dget_space(dsetid))<0) {
87 eherr <<
"Space id of the HDF5 dataset " << name()
88 <<
" cannot be obtained. "<<endl;
89 throw InternalErr (__FILE__, __LINE__, eherr.str ());
92 if (H5S_SCALAR != H5Sget_simple_extent_type(dspace)) {
97 eherr <<
" The HDF5 dataset " << name()
98 <<
" is not scalar. "<<endl;
99 throw InternalErr (__FILE__, __LINE__, eherr.str ());
104 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
110 eherr <<
"Obtaining the datatype of the HDF5 dataset " << name()
112 throw InternalErr (__FILE__, __LINE__, eherr.str ());
116 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
123 eherr <<
"Obtaining the memory type of the HDF5 dataset " << name()
125 throw InternalErr (__FILE__, __LINE__, eherr.str ());
130 string check_droplongstr_key =
"H5.EnableDropLongString";
131 bool is_droplongstr =
false;
134 htri_t is_vlen_str = H5Tis_variable_str(dtypeid);
135 if (is_vlen_str > 0) {
136 size_t ty_size = H5Tget_size(memtype);
144 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
146 throw InternalErr (__FILE__, __LINE__, eherr.str ());
148 vector <char> strval;
149 strval.resize(ty_size);
151 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)&strval[0]);
160 eherr <<
"Cannot read the HDF5 dataset " << name()
161 <<
" with the type of the HDF5 variable length string "<<endl;
162 throw InternalErr (__FILE__, __LINE__, eherr.str ());
165 char*temp_bp = &strval[0];
166 char*onestring =
NULL;
167 string final_str =
"";
169 onestring = *(
char**)temp_bp;
171 final_str =string(onestring);
177 herr_t ret_vlen_claim = 0;
178 ret_vlen_claim = H5Dvlen_reclaim(memtype,dspace,H5P_DEFAULT,(
void*)&strval[0]);
179 if (ret_vlen_claim < 0){
186 eherr <<
"Cannot reclaim the memory buffer of the HDF5 variable length string of the dataset "
188 throw InternalErr (__FILE__, __LINE__, eherr.str ());
196 if (
true == is_droplongstr) {
200 set_value(final_str);
203 else if (0 == is_vlen_str) {
204 size_t ty_size = H5Tget_size(dtypeid);
212 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
214 throw InternalErr (__FILE__, __LINE__, eherr.str ());
217 vector <char> strval;
218 strval.resize(1+ty_size);
220 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)&strval[0]);
229 eherr <<
"Cannot read the HDF5 dataset " << name()
230 <<
" with the type of the fixed size HDF5 string "<<endl;
231 throw InternalErr (__FILE__, __LINE__, eherr.str ());
234 string total_string(strval.begin(),strval.end());
239 if (H5Tget_strpad(dtypeid) == H5T_STR_NULLTERM)
240 temp_pos = total_string.find_first_of(
'\0');
241 else if (H5Tget_strpad(dtypeid) == H5T_STR_SPACEPAD)
242 temp_pos = total_string.find_last_not_of(
' ')+1;
244 temp_pos = total_string.find_last_not_of(
'0')+1;
246 string trim_string = total_string.substr(0,temp_pos);
251 if (
true == is_droplongstr) {
255 set_value(trim_string);
265 throw InternalErr (__FILE__, __LINE__,
"H5Tis_variable_str returns negative value" );
This class provides a way to map HDF5 Str to DAP Str for the CF option.
HDF5CFStr(const string &n, const string &d, const string &varname)
#define NC_JAVA_STR_SIZE_LIMIT
static bool check_beskeys(const string key)
virtual BaseType * ptr_duplicate()
Helper functions for generating DAS attributes and a function to check BES Key.
#define BESDEBUG(x, y)
macro used to send debug information to the debug stream