40 #include <InternalErr.h>
42 #include <mime_util.h>
84 bool depth_first(hid_t pid,
char *gname, DDS & dds,
const char *fname)
89 <<
" gname: " << gname
90 <<
" fname: " << fname
97 if(H5Gget_info(pid,&g_info) <0) {
99 "h5_dds handler: counting hdf5 group elements error for ";
101 throw InternalErr(__FILE__, __LINE__, msg);
104 nelems = g_info.nlinks;
108 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);
128 oname.resize((
size_t) oname_size + 1);
131 if (H5Lget_name_by_idx(pid,
".",H5_INDEX_NAME,H5_ITER_NATIVE,i,&oname[0],
132 (
size_t)(oname_size+1), H5P_DEFAULT) < 0){
134 "h5_dds handler: Error getting the hdf5 object name from the group: ";
136 throw InternalErr(__FILE__, __LINE__, msg);
142 if (H5Lget_info(pid,&oname[0],&linfo,H5P_DEFAULT)<0) {
143 string msg =
"hdf5 link name error from: ";
145 throw InternalErr(__FILE__, __LINE__, msg);
149 if(linfo.type == H5L_TYPE_SOFT || linfo.type == H5L_TYPE_EXTERNAL)
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";
159 msg += string(oname.begin(),oname.end());
160 throw InternalErr(__FILE__, __LINE__, msg);
163 H5O_type_t obj_type = oinfo.type;
167 case H5O_TYPE_GROUP: {
170 string full_path_name =
171 string(gname) + string(oname.begin(),oname.end()-1) +
"/";
174 DBG(cerr <<
"=depth_first():H5G_GROUP " << full_path_name
181 t_fpn.resize(full_path_name.length()+1);
182 copy(full_path_name.begin(),full_path_name.end(),t_fpn.begin());
186 t_fpn[full_path_name.length()] =
'\0';
188 hid_t cgroup = H5Gopen(pid, &t_fpn[0],H5P_DEFAULT);
190 throw InternalErr(__FILE__, __LINE__,
"h5_dds handler: H5Gopen() failed.");
201 if (H5Gclose(cgroup) < 0){
202 throw InternalErr(__FILE__, __LINE__,
"Could not close the group.");
208 case H5O_TYPE_DATASET:{
212 string full_path_name = string(gname) + string(oname.begin(),oname.end()-1);
225 case H5O_TYPE_NAMED_DATATYPE:
241 DBG(cerr <<
"<depth_first() " << endl);
259 static BaseType *Get_bt(
const string &vname,
260 const string &dataset,
263 BaseType *btp =
NULL;
267 DBG(cerr <<
">Get_bt varname=" << vname <<
" datatype=" << datatype
272 switch (H5Tget_class(datatype)) {
275 size = H5Tget_size(datatype);
276 sign = H5Tget_sign(datatype);
277 DBG(cerr <<
"=Get_bt() H5T_INTEGER size = " << size <<
" sign = "
280 if (sign == H5T_SGN_ERROR) {
281 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the sign type of the integer");
284 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
286 else if (size == 1) {
288 if (sign == H5T_SGN_2)
293 else if (size == 2) {
294 if (sign == H5T_SGN_2)
299 else if (size == 4) {
300 if (sign == H5T_SGN_2)
305 else if (size == 8) {
307 InternalErr(__FILE__, __LINE__,
308 string(
"Unsupported HDF5 64-bit Integer type:")
314 size = H5Tget_size(datatype);
315 DBG(cerr <<
"=Get_bt() H5T_FLOAT size = " << size << endl);
318 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
320 else if (size == 4) {
323 else if (size == 8) {
329 btp =
new HDF5Str(vname, dataset);
338 "=Get_bt() H5T_ARRAY datatype = " << datatype
342 hid_t dtype_base = H5Tget_super(datatype);
343 ar_bt = Get_bt(vname, dataset, dtype_base);
344 btp =
new HDF5Array(vname, dataset, ar_bt);
345 delete ar_bt; ar_bt = 0;
348 int ndim = H5Tget_array_ndims(datatype);
349 size = H5Tget_size(datatype);
352 if (dtype_base < 0) {
353 throw InternalErr(__FILE__, __LINE__,
"cannot return the base datatype");
356 throw InternalErr(__FILE__, __LINE__,
"cannot return the rank of the array datatype");
359 throw InternalErr(__FILE__, __LINE__,
"cannot return the size of the datatype");
362 <<
"=Get_bt()" <<
" Dim = " << ndim
363 <<
" Size = " << size
367 if(H5Tget_array_dims(datatype, size2) < 0){
369 InternalErr(__FILE__, __LINE__,
370 string(
"Could not get array dims for: ")
376 for (
int dim_index = 0; dim_index < ndim; dim_index++) {
377 h5_ar.append_dim(size2[dim_index]);
378 DBG(cerr <<
"=Get_bt() " << size2[dim_index] << endl);
379 nelement = nelement * size2[dim_index];
388 h5_ar.set_length(nelement);
389 h5_ar.
d_type = H5Tget_class(dtype_base);
390 if (h5_ar.
d_type == H5T_NO_CLASS){
391 throw InternalErr(__FILE__, __LINE__,
"cannot return the datatype class identifier");
395 if( ar_bt )
delete ar_bt;
396 if( btp )
delete btp;
404 btp =
new HDF5Url(vname, dataset);
408 throw InternalErr(__FILE__, __LINE__,
409 string(
"Unsupported HDF5 type: ") + vname);
413 if( btp )
delete btp;
418 throw InternalErr(__FILE__, __LINE__,
419 string(
"Could not make a DAP variable for: ")
423 switch (btp->type()) {
441 case dods_uint16_c: {
453 case dods_uint32_c: {
459 case dods_float32_c: {
465 case dods_float64_c: {
488 throw InternalErr(__FILE__, __LINE__,
489 string(
"error counting hdf5 group elements for ")
492 DBG(cerr <<
"<Get_bt()" << endl);
512 static Structure *Get_structure(
const string &varname,
513 const string &dataset,
518 DBG(cerr <<
">Get_structure()" << datatype << endl);
520 if (H5Tget_class(datatype) != H5T_COMPOUND)
521 throw InternalErr(__FILE__, __LINE__,
522 string(
"Compound-to-structure mapping error for ")
531 int nmembs = H5Tget_nmembers(datatype);
532 DBG(cerr <<
"=Get_structure() has " << nmembs << endl);
534 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the number of elements");
536 for (
int i = 0; i < nmembs; i++) {
537 char *memb_name = H5Tget_member_name(datatype, i);
538 H5T_class_t memb_cls = H5Tget_member_class(datatype, i);
539 hid_t memb_type = H5Tget_member_type(datatype, i);
540 if (memb_name ==
NULL){
541 throw InternalErr(__FILE__, __LINE__,
"cannot retrieve the name of the member");
543 if ((memb_cls < 0) | (memb_type < 0)) {
549 throw InternalErr(__FILE__, __LINE__,
550 string(
"Type mapping error for ")
551 +
string(memb_name) );
555 if (memb_cls == H5T_COMPOUND) {
556 Structure *s = Get_structure(memb_name, dataset, memb_type);
557 structure_ptr->add_var(s);
561 BaseType *bt = Get_bt(memb_name, dataset, memb_type);
562 structure_ptr->add_var(bt);
573 if( structure_ptr )
delete structure_ptr;
577 DBG(cerr <<
"<Get_structure()" << endl);
579 return structure_ptr;
606 const string & filename)
609 dds_table.set_dataset_name(name_path(filename));
615 hid_t *dimids =
NULL;
617 dimids =
new hid_t[dt_inst.
ndims];
630 BaseType *bt = Get_bt(varname, filename, dt_inst.
type);
637 InternalErr(__FILE__, __LINE__,
638 "Unable to convert hdf5 datatype to dods basetype");
642 if (dt_inst.
ndims == 0) {
643 dds_table.add_var(bt);
659 for (
int dim_index = 0; dim_index < dt_inst.
ndims; dim_index++)
660 ar->append_dim(dt_inst.
size[dim_index]);
661 dds_table.add_var(ar);
665 DBG(cerr <<
"<read_objects_base_type(dds)" << endl);
681 const string & filename)
683 dds_table.set_dataset_name(name_path(filename));
685 Structure *structure = Get_structure(varname, filename, dt_inst.
type);
688 DBG(cerr <<
"=read_objects_structure(): Dimension is "
689 << dt_inst.
ndims << endl);
691 if (dt_inst.
ndims != 0) {
693 DBG(cerr <<
"=read_objects_structure(): array of size " <<
695 DBG(cerr <<
"=read_objects_structure(): memory needed = " <<
696 dt_inst.
need << endl);
698 delete structure; structure = 0;
705 ar->set_length((
int) (dt_inst.
nelmts));
707 for (dim_index = 0; dim_index < dt_inst.
ndims; dim_index++) {
708 ar->append_dim(dt_inst.
size[dim_index]);
709 DBG(cerr <<
"=read_objects_structure(): append_dim = " <<
710 dt_inst.
size[dim_index] << endl);
713 dds_table.add_var(ar);
723 dds_table.add_var(structure);
724 delete structure; structure = 0;
746 read_objects(DDS & dds_table,
const string &varname,
const string &filename)
749 switch (H5Tget_class(dt_inst.
type)) {
void set_tid(hid_t type)
remembers HDF5 datatype id.
This class generates DAP URL type for the default option.
void set_tid(hid_t type)
remembers HDF5 datatype id.
A structure for DDS generation.
A class for HDF5 signed 16 bit integer type.
void set_tid(hid_t type)
remembers HDF5 datatype id.
void set_memneed(size_t need)
remembers memory size needed.
void set_tid(hid_t type)
remembers HDF5 datatype id.
hid_t dset
HDF5 data set id.
void set_did(hid_t dset)
remembers HDF5 dataset id.
bool depth_first(hid_t pid, char *gname, DDS &dds, const char *fname)
will fill DDS table.
This class converts HDF5 compound type into DAP structure for the default option. ...
This class provides a way to map HDF5 32 bit integer to DAP Int32 for the default option...
void get_dataset(hid_t pid, const string &dname, DS_t *dt_inst_ptr)
obtain data information in a dataset datatype, dataspace(dimension sizes) and number of dimensions an...
H5T_class_t d_type
HDF5 data type class.
#define DODS_MAX_RANK
Maximum number of dimensions in an array(default option only).
void set_numelm(int nelms)
remembers number of elements in this array.
void set_did(hid_t dset)
remembers HDF5 dataset id.
Data structure and retrieval processing header for the default option.
void read_objects(DDS &dds_table, const string &varname, const string &filename)
fills in information of a dataset (name, data type, data space) into one DDS table.
string get_hardlink(hid_t, const string &)
#define DODS_NAMELEN
Maximum length of variable or attribute name(default option only).
void set_did(hid_t dset)
remembers HDF5 dataset id.
void read_objects_base_type(DDS &dds_table, const string &varname, const string &filename)
fills in information of a dataset (name, data type, data space) into one DDS table.
void read_objects_structure(DDS &dds_table, const string &varname, const string &filename)
fills in information of a structure dataset (name, data type, data space) into a DDS table...
void set_did(hid_t dset)
remembers HDF5 dataset id.
void set_numdim(int ndims)
remembers number of dimensions of this array.
int size[DODS_MAX_RANK]
Size of each dimension.
A class for mapping HDF5 64-bit float to DAP for the default option.
void set_tid(hid_t type)
remembers HDF5 datatype id.
void set_tid(hid_t type)
remembers HDF5 datatype id.
This class that translates HDF5 string into DAP string for the default option.
void set_did(hid_t dset)
remembers HDF5 dataset id.
void set_tid(hid_t type)
remembers HDF5 datatype id.
void set_did(hid_t dset)
remembers HDF5 dataset id.
This class provides a way to map unsigned HDF5 16 bit integer to DAP UInt16 for the default option...
void set_did(hid_t dset)
remembers HDF5 dataset id.
void set_did(hid_t dset)
remembers HDF5 dataset id.
void set_did(hid_t dset)
remembers HDF5 dataset id.
void set_did(hid_t dset)
remembers HDF5 dataset id.
This class provides a way to map HDF5 byte to DAP Byte for the default option.
void set_did(hid_t dset)
remembers HDF5 datatype id.
This class provides a way to map unsigned HDF5 32 bit integer to DAP UInt32.
hid_t type
HDF5 data type id.
hsize_t nelmts
Number of elements.
void set_tid(hid_t type)
remembers HDF5 datatype id.
void set_tid(hid_t type)
remembers HDF5 datatype id.
A class for handling all types of array in HDF5 for the default option.
Helper functions to generate DDS/DAS/DODS for the default option.
int ndims
Number of dimensions.
void set_tid(hid_t type)
remembers HDF5 datatype id.
A class for mapping HDF5 32-bit float to DAP for the default option.
void set_tid(hid_t type)
remembers HDF5 datatype id.