86bool depth_first(hid_t pid,
const char *gname, DDS & dds,
const char *fname)
91 <<
" gname: " << gname
92 <<
" fname: " << fname
98 if(H5Gget_info(pid,&g_info) <0) {
100 "h5_dds handler: counting hdf5 group elements error for ";
102 throw InternalErr(__FILE__, __LINE__, msg);
105 nelems = g_info.nlinks;
108 for (hsize_t i = 0; i < nelems; i++) {
114 H5Lget_name_by_idx(pid,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,
nullptr,
116 if (oname_size <= 0) {
117 string msg =
"h5_dds handler: Error getting the size of the hdf5 object from the group: ";
119 throw InternalErr(__FILE__, __LINE__, msg);
123 oname.resize((
size_t) oname_size + 1);
125 if (H5Lget_name_by_idx(pid,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,oname.data(),
126 (
size_t)(oname_size+1), H5P_DEFAULT) < 0){
128 "h5_dds handler: Error getting the hdf5 object name from the group: ";
130 throw InternalErr(__FILE__, __LINE__, msg);
135 if (H5Lget_info(pid,oname.data(),&linfo,H5P_DEFAULT)<0) {
136 string msg =
"hdf5 link name error from: ";
138 throw InternalErr(__FILE__, __LINE__, msg);
142 if(linfo.type == H5L_TYPE_EXTERNAL)
146 if(linfo.type == H5L_TYPE_SOFT)
152 if (H5OGET_INFO_BY_IDX(pid,
".", H5_INDEX_NAME, H5_ITER_NATIVE,
153 i, &oinfo, H5P_DEFAULT)<0) {
154 string msg =
"h5_dds handler: Error obtaining the info for the object";
155 msg += string(oname.begin(),oname.end());
156 throw InternalErr(__FILE__, __LINE__, msg);
159 H5O_type_t obj_type = oinfo.type;
166 string full_path_name =
167 string(gname) + string(oname.begin(),oname.end()-1) +
"/";
169 BESDEBUG(
"h5",
"=depth_first():H5G_GROUP " << full_path_name
173 t_fpn.resize(full_path_name.size()+1);
174 copy(full_path_name.begin(),full_path_name.end(),t_fpn.begin());
176 t_fpn[full_path_name.size()] =
'\0';
178 hid_t cgroup = H5Gopen(pid, t_fpn.data(),H5P_DEFAULT);
180 throw InternalErr(__FILE__, __LINE__,
"h5_dds handler: H5Gopen() failed.");
196 if (H5Gclose(cgroup) < 0){
197 throw InternalErr(__FILE__, __LINE__,
"Could not close the group.");
202 case H5O_TYPE_DATASET:
206 string full_path_name = string(gname) + string(oname.begin(),oname.end()-1);
214 get_dataset(pid, full_path_name, &dt_inst);
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);
284 auto ar_unique = make_unique<HDF5Array>(varname, filename, bt);
285 auto ar = ar_unique.get();
287 ar->set_memneed(dt_inst.need);
288 ar->set_numdim(dt_inst.ndims);
289 ar->set_numelm((
int) (dt_inst.nelmts));
290 for (
int dim_index = 0; dim_index < dt_inst.ndims; dim_index++)
291 ar->append_dim(dt_inst.size[dim_index]);
292 dds_table.add_var(ar);
294 BESDEBUG(
"h5",
"<read_objects_base_type(dds)" << endl);
310 const string & filename)
312 dds_table.set_dataset_name(name_path(filename));
314 Structure *structure = Get_structure(varname, varname,filename, dt_inst.type,
false);
318 BESDEBUG(
"h5",
"=read_objects_structure(): Dimension is "
319 << dt_inst.ndims << endl);
321 if (dt_inst.ndims != 0) {
322 BESDEBUG(
"h5",
"=read_objects_structure(): array of size " <<
323 dt_inst.nelmts << endl);
324 BESDEBUG(
"h5",
"=read_objects_structure(): memory needed = " <<
325 dt_inst.need << endl);
326 auto ar_unique = make_unique<HDF5Array>(varname, filename, structure);
327 auto ar = ar_unique.get();
328 delete structure; structure =
nullptr;
330 ar->set_memneed(dt_inst.need);
331 ar->set_numdim(dt_inst.ndims);
332 ar->set_numelm((
int) (dt_inst.nelmts));
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);
346 dds_table.add_var(structure);
347 delete structure; structure =
nullptr;
369read_objects(DDS & dds_table,
const string &varname,
const string &filename)
372 switch (H5Tget_class(dt_inst.type)) {
381 H5Tclose(dt_inst.type);
382 throw InternalErr(__FILE__, __LINE__,
"Currently don't support accessing data of Array datatype when array datatype is not inside the compound.");
389 if(H5Tclose(dt_inst.type)<0) {
390 throw InternalErr(__FILE__, __LINE__,
"Cannot close the HDF5 datatype.");