38 #include "config_hdf5.h"
40 #include <InternalErr.h>
43 #include <mime_util.h>
89 bool depth_first(hid_t pid,
char *gname, DDS & dds,
const char *fname)
94 <<
" gname: " << gname
95 <<
" fname: " << fname
101 if(H5Gget_info(pid,&g_info) <0) {
103 "h5_dds handler: counting hdf5 group elements error for ";
105 throw InternalErr(__FILE__, __LINE__, msg);
108 nelems = g_info.nlinks;
111 for (hsize_t i = 0; i < nelems; i++) {
117 H5Lget_name_by_idx(pid,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,NULL,
119 if (oname_size <= 0) {
120 string msg =
"h5_dds handler: Error getting the size of the hdf5 object from the group: ";
122 throw InternalErr(__FILE__, __LINE__, msg);
126 oname.resize((
size_t) oname_size + 1);
128 if (H5Lget_name_by_idx(pid,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
129 (
size_t)(oname_size+1), H5P_DEFAULT) < 0){
131 "h5_dds handler: Error getting the hdf5 object name from the group: ";
133 throw InternalErr(__FILE__, __LINE__, msg);
138 if (H5Lget_info(pid,&oname[0],&linfo,H5P_DEFAULT)<0) {
139 string msg =
"hdf5 link name error from: ";
141 throw InternalErr(__FILE__, __LINE__, msg);
145 if(linfo.type == H5L_TYPE_EXTERNAL)
149 if(linfo.type == H5L_TYPE_SOFT)
155 if (H5Oget_info_by_idx(pid,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
156 i, &oinfo, H5P_DEFAULT)<0) {
157 string msg =
"h5_dds handler: Error obtaining the info for the object";
158 msg += string(oname.begin(),oname.end());
159 throw InternalErr(__FILE__, __LINE__, msg);
162 H5O_type_t obj_type = oinfo.type;
169 string full_path_name =
170 string(gname) + string(oname.begin(),oname.end()-1) +
"/";
172 BESDEBUG(
"h5",
"=depth_first():H5G_GROUP " << full_path_name
176 t_fpn.resize(full_path_name.length()+1);
177 copy(full_path_name.begin(),full_path_name.end(),t_fpn.begin());
179 t_fpn[full_path_name.length()] =
'\0';
181 hid_t cgroup = H5Gopen(pid, &t_fpn[0],H5P_DEFAULT);
183 throw InternalErr(__FILE__, __LINE__,
"h5_dds handler: H5Gopen() failed.");
199 if (H5Gclose(cgroup) < 0){
200 throw InternalErr(__FILE__, __LINE__,
"Could not close the group.");
205 case H5O_TYPE_DATASET:
209 string full_path_name = string(gname) + string(oname.begin(),oname.end()-1);
214 get_dataset(pid, full_path_name, &dt_inst,
false);
221 case H5O_TYPE_NAMED_DATATYPE:
230 BESDEBUG(
"h5",
"<depth_first() " << endl);
257 const string & filename)
260 dds_table.set_dataset_name(name_path(filename));
264 BaseType *bt = Get_bt(varname, varname,filename, dt_inst.
type,
false);
271 InternalErr(__FILE__, __LINE__,
272 "Unable to convert hdf5 datatype to dods basetype");
276 if (dt_inst.
ndims == 0) {
277 dds_table.add_var(bt);
289 for (
int dim_index = 0; dim_index < dt_inst.
ndims; dim_index++)
290 ar->append_dim(dt_inst.
size[dim_index]);
291 dds_table.add_var(ar);
295 BESDEBUG(
"h5",
"<read_objects_base_type(dds)" << endl);
311 const string & filename)
313 dds_table.set_dataset_name(name_path(filename));
315 Structure *structure = Get_structure(varname, varname,filename, dt_inst.
type,
false);
319 BESDEBUG(
"h5",
"=read_objects_structure(): Dimension is "
320 << dt_inst.
ndims << endl);
322 if (dt_inst.
ndims != 0) {
323 BESDEBUG(
"h5",
"=read_objects_structure(): array of size " <<
325 BESDEBUG(
"h5",
"=read_objects_structure(): memory needed = " <<
326 dt_inst.
need << endl);
328 delete structure; structure = 0;
333 ar->set_length((
int) (dt_inst.
nelmts));
335 for (
int dim_index = 0; dim_index < dt_inst.
ndims; dim_index++) {
336 ar->append_dim(dt_inst.
size[dim_index]);
337 BESDEBUG(
"h5",
"=read_objects_structure(): append_dim = " <<
338 dt_inst.
size[dim_index] << endl);
341 dds_table.add_var(ar);
351 dds_table.add_var(structure);
352 delete structure; structure = 0;
374 read_objects(DDS & dds_table,
const string &varname,
const string &filename)
377 switch (H5Tget_class(dt_inst.
type)) {
386 H5Tclose(dt_inst.
type);
387 throw InternalErr(__FILE__, __LINE__,
"Currently don't support accessing data of Array datatype when array datatype is not inside the compound.");
394 if(H5Tclose(dt_inst.
type)<0) {
395 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 datatype.");
A class for handling all types of array in HDF5 for the default option.
This class provides a way to map HDF5 byte to DAP Byte for the default option.
This file includes several helper functions for translating HDF5 to CF-compliant.
A class for mapping HDF5 32-bit float to DAP for the default option.
A class for mapping HDF5 64-bit float to DAP for the default option.
A class for HDF5 signed 16 bit integer type.
This class provides a way to map HDF5 32 bit integer to DAP Int32 for the default option.
This class that translates HDF5 string into DAP string for the default option.
This class converts HDF5 compound type into DAP structure for the default option.
This class provides a way to map unsigned HDF5 16 bit integer to DAP UInt16 for the default option.
This class provides a way to map unsigned HDF5 32 bit integer to DAP UInt32.
This class generates DAP URL type for the default option.
void set_numdim(int ndims)
remembers number of dimensions of this array.
void set_numelm(int nelms)
remembers number of elements in this array.
void set_memneed(size_t need)
remembers memory size needed.
string get_hardlink(hid_t pgroup, const string &oname)
void read_objects_base_type(DDS &dds_table, const string &varname, const string &filename)
bool depth_first(hid_t pid, char *gname, DDS &dds, const char *fname)
void read_objects(DDS &dds_table, const string &varname, const string &filename)
void read_objects_structure(DDS &dds_table, const string &varname, const string &filename)
The main header of the HDF5 OPeNDAP handler.
const int DODS_NAMELEN
Maximum length of variable or attribute name(default option only).
A structure for DDS generation.
hsize_t nelmts
Number of elements.
hsize_t need
Space needed.
hid_t type
HDF5 data set id.
int size[DODS_MAX_RANK]
Size of each dimension.
int ndims
HDF5 data space id.