32#include "config_hdf5.h"
39#include <libdap/InternalErr.h>
48HDF5CFStr::HDF5CFStr(
const string &n,
const string &d,
const string &h5_varname)
49 :
Str(n, d), varname(h5_varname)
53BaseType *HDF5CFStr::ptr_duplicate()
61 BESDEBUG(
"h5",
"Coming to HDF5CFStr read "<<endl);
68 if ((fileid = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
70 eherr <<
"HDF5 File " << dataset()
71 <<
" cannot be opened. "<<endl;
72 throw InternalErr (__FILE__, __LINE__, eherr.str ());
75 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
78 eherr <<
"HDF5 dataset " << name()
79 <<
" cannot be opened. "<<endl;
80 throw InternalErr (__FILE__, __LINE__, eherr.str ());
83 if ((dspace = H5Dget_space(dsetid))<0) {
88 eherr <<
"Space id of the HDF5 dataset " << name()
89 <<
" cannot be obtained. "<<endl;
90 throw InternalErr (__FILE__, __LINE__, eherr.str ());
93 if (H5S_SCALAR != H5Sget_simple_extent_type(dspace)) {
98 eherr <<
" The HDF5 dataset " << name()
99 <<
" is not scalar. "<<endl;
100 throw InternalErr (__FILE__, __LINE__, eherr.str ());
105 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
111 eherr <<
"Obtaining the datatype of the HDF5 dataset " << name()
113 throw InternalErr (__FILE__, __LINE__, eherr.str ());
117 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
124 eherr <<
"Obtaining the memory type of the HDF5 dataset " << name()
126 throw InternalErr (__FILE__, __LINE__, eherr.str ());
130 htri_t is_vlen_str = H5Tis_variable_str(dtypeid);
131 if (is_vlen_str > 0) {
132 size_t ty_size = H5Tget_size(memtype);
140 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
142 throw InternalErr (__FILE__, __LINE__, eherr.str ());
144 vector <char> strval;
145 strval.resize(ty_size);
147 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)strval.data());
156 eherr <<
"Cannot read the HDF5 dataset " << name()
157 <<
" with the type of the HDF5 variable length string "<<endl;
158 throw InternalErr (__FILE__, __LINE__, eherr.str ());
161 char*temp_bp = strval.data();
162 char*onestring =
nullptr;
163 string final_str =
"";
165 onestring = *(
char**)temp_bp;
166 if(onestring!=
nullptr )
167 final_str =string(onestring);
173 herr_t ret_vlen_claim = 0;
174 ret_vlen_claim = H5Dvlen_reclaim(memtype,dspace,H5P_DEFAULT,(
void*)strval.data());
175 if (ret_vlen_claim < 0){
182 eherr <<
"Cannot reclaim the memory buffer of the HDF5 variable length string of the dataset "
184 throw InternalErr (__FILE__, __LINE__, eherr.str ());
192 if (
true == HDF5RequestHandler::get_drop_long_string()) {
193 if( final_str.size() > NC_JAVA_STR_SIZE_LIMIT)
196 set_value(final_str);
199 else if (0 == is_vlen_str) {
200 size_t ty_size = H5Tget_size(dtypeid);
208 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
210 throw InternalErr (__FILE__, __LINE__, eherr.str ());
213 vector <char> strval;
214 strval.resize(1+ty_size);
216 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)strval.data());
225 eherr <<
"Cannot read the HDF5 dataset " << name()
226 <<
" with the type of the fixed size HDF5 string "<<endl;
227 throw InternalErr (__FILE__, __LINE__, eherr.str ());
230 string total_string(strval.begin(),strval.end());
235 if (H5Tget_strpad(dtypeid) == H5T_STR_NULLTERM)
236 temp_pos = total_string.find_first_of(
'\0');
237 else if (H5Tget_strpad(dtypeid) == H5T_STR_SPACEPAD)
238 temp_pos = total_string.find_last_not_of(
' ')+1;
240 temp_pos = total_string.find_last_not_of(
'0')+1;
242 string trim_string = total_string.substr(0,temp_pos);
247 if (
true == HDF5RequestHandler::get_drop_long_string()) {
248 if( trim_string.size() > NC_JAVA_STR_SIZE_LIMIT)
251 set_value(trim_string);
261 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.
include the entry functions to execute the handlers
Helper functions for generating DAS attributes and a function to check BES Key.