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()
55 auto HDF5CFStr_unique = make_unique<HDF5CFStr>(*
this);
56 return HDF5CFStr_unique.release();
62 BESDEBUG(
"h5",
"Coming to HDF5CFStr read "<<endl);
69 if ((fileid = H5Fopen(dataset().c_str(),H5F_ACC_RDONLY,H5P_DEFAULT))<0) {
71 eherr <<
"HDF5 File " << dataset()
72 <<
" cannot be opened. "<<endl;
73 throw InternalErr (__FILE__, __LINE__, eherr.str ());
76 if ((dsetid = H5Dopen(fileid,varname.c_str(),H5P_DEFAULT))<0) {
79 eherr <<
"HDF5 dataset " << name()
80 <<
" cannot be opened. "<<endl;
81 throw InternalErr (__FILE__, __LINE__, eherr.str ());
84 if ((dspace = H5Dget_space(dsetid))<0) {
89 eherr <<
"Space id of the HDF5 dataset " << name()
90 <<
" cannot be obtained. "<<endl;
91 throw InternalErr (__FILE__, __LINE__, eherr.str ());
94 if (H5S_SCALAR != H5Sget_simple_extent_type(dspace)) {
99 eherr <<
" The HDF5 dataset " << name()
100 <<
" is not scalar. "<<endl;
101 throw InternalErr (__FILE__, __LINE__, eherr.str ());
106 if ((dtypeid = H5Dget_type(dsetid)) < 0) {
112 eherr <<
"Obtaining the datatype of the HDF5 dataset " << name()
114 throw InternalErr (__FILE__, __LINE__, eherr.str ());
118 if ((memtype = H5Tget_native_type(dtypeid, H5T_DIR_ASCEND))<0) {
125 eherr <<
"Obtaining the memory type of the HDF5 dataset " << name()
127 throw InternalErr (__FILE__, __LINE__, eherr.str ());
131 htri_t is_vlen_str = H5Tis_variable_str(dtypeid);
132 if (is_vlen_str > 0) {
133 size_t ty_size = H5Tget_size(memtype);
141 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
143 throw InternalErr (__FILE__, __LINE__, eherr.str ());
145 vector <char> strval;
146 strval.resize(ty_size);
148 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)strval.data());
157 eherr <<
"Cannot read the HDF5 dataset " << name()
158 <<
" with the type of the HDF5 variable length string "<<endl;
159 throw InternalErr (__FILE__, __LINE__, eherr.str ());
162 char*temp_bp = strval.data();
163 char*onestring =
nullptr;
164 string final_str =
"";
166 onestring = *(
char**)temp_bp;
167 if(onestring!=
nullptr )
168 final_str =string(onestring);
174 herr_t ret_vlen_claim = 0;
175 ret_vlen_claim = H5Dvlen_reclaim(memtype,dspace,H5P_DEFAULT,(
void*)strval.data());
176 if (ret_vlen_claim < 0){
183 eherr <<
"Cannot reclaim the memory buffer of the HDF5 variable length string of the dataset "
185 throw InternalErr (__FILE__, __LINE__, eherr.str ());
193 if (
true == HDF5RequestHandler::get_drop_long_string()) {
194 if( final_str.size() > NC_JAVA_STR_SIZE_LIMIT)
197 set_value(final_str);
200 else if (0 == is_vlen_str) {
201 size_t ty_size = H5Tget_size(dtypeid);
209 eherr <<
"Cannot obtain the size of the fixed size HDF5 string of the dataset "
211 throw InternalErr (__FILE__, __LINE__, eherr.str ());
214 vector <char> strval;
215 strval.resize(1+ty_size);
217 read_ret = H5Dread(dsetid,memtype,H5S_ALL,H5S_ALL,H5P_DEFAULT,(
void*)strval.data());
226 eherr <<
"Cannot read the HDF5 dataset " << name()
227 <<
" with the type of the fixed size HDF5 string "<<endl;
228 throw InternalErr (__FILE__, __LINE__, eherr.str ());
231 string total_string(strval.begin(),strval.end());
236 if (H5Tget_strpad(dtypeid) == H5T_STR_NULLTERM)
237 temp_pos = total_string.find_first_of(
'\0');
238 else if (H5Tget_strpad(dtypeid) == H5T_STR_SPACEPAD)
239 temp_pos = total_string.find_last_not_of(
' ')+1;
241 temp_pos = total_string.find_last_not_of(
'0')+1;
243 string trim_string = total_string.substr(0,temp_pos);
248 if (
true == HDF5RequestHandler::get_drop_long_string()) {
249 if( trim_string.size() > NC_JAVA_STR_SIZE_LIMIT)
252 set_value(trim_string);
262 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.