/* This is actually an extension of H5Tget_precision to handle complex types */ size_t get_complex_precision(hid_t type_id) { hid_t real_type; size_t result; real_type = H5Tget_member_type(type_id, 0); result = H5Tget_precision(real_type); H5Tclose(real_type); return result; }
/// Type translation: hdf5->nd static nd_type_id_t hdf5_to_nd_type(hid_t tid) { size_t p=H5Tget_precision(tid); switch(H5Tget_class(tid)) { case H5T_INTEGER: { H5T_sign_t sign=H5Tget_sign(tid); switch(p) { #define CASE(n) case n: return (sign==H5T_SGN_NONE)?nd_u##n:nd_i##n CASE(8); CASE(16); CASE(32); CASE(64); #undef CASE default:; } } return nd_id_unknown; case H5T_FLOAT: if (p==32) return nd_f32; else if(p==64) return nd_f64; default: return nd_id_unknown; } }
int hdf5read(char *name, struct descriptor_xd *xd) { hid_t obj,type; H5G_stat_t statbuf; int item_type; int idx = 0; int status = FindItem(name, &obj, &item_type); if (status & 1) { if (item_type == H5G_DATASET) { int size; char dtype; int htype = 42; int is_signed; hsize_t ds_dims[64]; hid_t space = H5Dget_space(obj); int n_ds_dims = H5Sget_simple_extent_dims(space,ds_dims,0); size_t precision; H5Sclose(space); type = H5Dget_type(obj); switch (H5Tget_class(type)) { case H5T_COMPOUND: { printf("Compound data is not supported, skipping\n"); break; } case H5T_INTEGER: precision = H5Tget_precision(type); is_signed = (H5Tget_sign(type) != H5T_SGN_NONE); size = precision/8; switch (precision) { case 8: dtype = is_signed ? DTYPE_B : DTYPE_BU; htype = is_signed ? H5T_NATIVE_CHAR : H5T_NATIVE_UCHAR; break; case 16: dtype = is_signed ? DTYPE_W : DTYPE_WU; htype = is_signed ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT; break; case 32: dtype = is_signed ? DTYPE_L : DTYPE_LU; htype = is_signed ? H5T_NATIVE_INT : H5T_NATIVE_UINT; break; case 64: dtype = is_signed ? DTYPE_Q : DTYPE_QU; htype = is_signed ? H5T_NATIVE_LLONG : H5T_NATIVE_ULLONG; break; default: dtype = 0; break; } PutData(obj, dtype, htype, size, n_ds_dims, ds_dims,0,xd); break; case H5T_FLOAT: precision = H5Tget_precision(type); size = precision/8; switch (precision) { case 32: dtype = DTYPE_NATIVE_FLOAT; htype = H5T_NATIVE_FLOAT; break; case 64: dtype = DTYPE_NATIVE_DOUBLE; htype = H5T_NATIVE_DOUBLE; break; default: dtype = 0; break; } PutData(obj, dtype, htype, size, n_ds_dims, ds_dims,0,xd); break; case H5T_TIME: printf("dataset is time ---- UNSUPPORTED\n"); break; case H5T_STRING: { int slen = H5Tget_size(type); hid_t st_id; if (slen < 0) { printf("Badly formed string attribute\n"); return; } #if H5_VERS_MAJOR>=1&&H5_VERS_MINOR>=6&&H5_VERS_RELEASE>=1 if(H5Tis_variable_str(type)) { st_id = H5Tcopy (H5T_C_S1); H5Tset_size(st_id, H5T_VARIABLE); } else { #endif st_id = H5Tcopy (type); H5Tset_cset(st_id, H5T_CSET_ASCII); #if H5_VERS_MAJOR>=1&&H5_VERS_MINOR>=6&&H5_VERS_RELEASE>=1 } #endif if (H5Tget_size(st_id) > slen) { slen = H5Tget_size(st_id); } H5Tset_size (st_id, slen); PutData(obj, DTYPE_T, st_id, slen, n_ds_dims, ds_dims, 0, xd); } /* printf("dataset is string\n"); */ /* dtype = DTYPE_T; */ /* htype = H5T_STRING; */ /* PutData(obj, dtype, htype, 0, 0, 0, 1, xd); */ break; case H5T_BITFIELD: printf("dataset is bitfield ---- UNSUPPORTED\n"); break; case H5T_OPAQUE: printf("dataset is opaque ---- UNSUPPORTED\n"); break; case H5T_ARRAY: printf("dataset is array ---- UNSUPPORTED\n"); break; case H5T_VLEN: printf("dataset is vlen ---- UNSUPPORTED\n"); break; } H5Tclose(type); } else { int size; char dtype; int htype = 42; int is_signed; hsize_t ds_dims[64]; hid_t space = H5Aget_space(obj); int n_ds_dims = H5Sget_simple_extent_dims(space,ds_dims,0); size_t precision; H5Sclose(space); type = H5Aget_type(obj); switch (H5Tget_class(type)) { case H5T_COMPOUND: { printf("Compound data is not supported, skipping\n"); break; } case H5T_INTEGER: precision = H5Tget_precision(type); is_signed = (H5Tget_sign(type) != H5T_SGN_NONE); size = precision/8; switch (precision) { case 8: dtype = is_signed ? DTYPE_B : DTYPE_BU; htype = is_signed ? H5T_NATIVE_CHAR : H5T_NATIVE_UCHAR; break; case 16: dtype = is_signed ? DTYPE_W : DTYPE_WU; htype = is_signed ? H5T_NATIVE_SHORT : H5T_NATIVE_USHORT; break; case 32: dtype = is_signed ? DTYPE_L : DTYPE_LU; htype = is_signed ? H5T_NATIVE_INT : H5T_NATIVE_UINT; break; case 64: dtype = is_signed ? DTYPE_Q : DTYPE_QU; htype = is_signed ? H5T_NATIVE_LLONG : H5T_NATIVE_ULLONG; break; default: dtype = 0; break; } PutData(obj, dtype, htype, size, n_ds_dims, ds_dims, 1, xd); break; case H5T_FLOAT: precision = H5Tget_precision(type); size = precision/8; switch (precision) { case 32: dtype = DTYPE_NATIVE_FLOAT; htype = H5T_NATIVE_FLOAT; break; case 64: dtype = DTYPE_NATIVE_DOUBLE; htype = H5T_NATIVE_DOUBLE; break; default: dtype = 0; break; } PutData(obj, dtype, htype, size, n_ds_dims, ds_dims,1, xd); break; case H5T_TIME: printf("dataset is time ---- UNSUPPORTED\n"); break; case H5T_STRING: { int slen = H5Tget_size(type); hid_t st_id; if (slen < 0) { printf("Badly formed string attribute\n"); return; } #if H5_VERS_MAJOR>=1&&H5_VERS_MINOR>=6&&H5_VERS_RELEASE>=1 if(H5Tis_variable_str(type)) { st_id = H5Tcopy (H5T_C_S1); H5Tset_size(st_id, H5T_VARIABLE); } else { #endif st_id = H5Tcopy (type); H5Tset_cset(st_id, H5T_CSET_ASCII); #if H5_VERS_MAJOR>=1&&H5_VERS_MINOR>=6&&H5_VERS_RELEASE>=1 } #endif if (H5Tget_size(st_id) > slen) { slen = H5Tget_size(st_id); } H5Tset_size (st_id, slen); PutData(obj, DTYPE_T, st_id, slen, n_ds_dims, ds_dims, 1, xd); } /* dtype = DTYPE_T; */ /* htype = H5T_STRING; */ /* PutData(obj, dtype, htype, 0, 0, 0, 1, xd); */ break; case H5T_BITFIELD: printf("dataset is bitfield ---- UNSUPPORTED\n"); break; case H5T_OPAQUE: printf("dataset is opaque ---- UNSUPPORTED\n"); break; case H5T_ARRAY: printf("dataset is array ---- UNSUPPORTED\n"); break; case H5T_VLEN: printf("dataset is vlen ---- UNSUPPORTED\n"); break; } H5Tclose(type); } } return status; }
Object::TypeName Object::getStlType(hid_t hType) const { H5T_class_t attrType = H5Tget_class(hType); // parsing type info stringstream typeName; switch(attrType) { case H5T_INTEGER: { size_t precision = H5Tget_precision(hType); H5T_sign_t sign = H5Tget_sign(hType); switch (sign) { case H5T_SGN_NONE: typeName << "u"; break; case H5T_SGN_2: break; case H5T_NSGN: break; case H5T_SGN_ERROR: break; } typeName << "int" << dec << precision << "_t"; } break; case H5T_FLOAT: { size_t precision = H5Tget_precision(hType); if (precision == 32) { typeName << "float"; } else if (precision == 64) { typeName << "double"; } else { stringstream ss; ss << "Object::getStlType: H5T_FLOAT with unkown precision " << precision << "bits"; throw Exception(ss); } } break; case H5T_STRING: { H5T_cset_t charSet = H5Tget_cset(hType); if (charSet != 0) { stringstream ss; ss << "Object::getStlType: Unknown character encoding type '" << charSet << "'. Currently only US-ASCII is supported."; throw Exception(ss); } typeName << "string"; } break; case H5T_BITFIELD: throw Exception("Object::getStlType: Unknown type H5T_BITFIELD"); break; case H5T_OPAQUE: throw Exception("Object::getStlType: Unknown type H5T_OPAQUE"); break; case H5T_COMPOUND: throw Exception("Object::getStlType: Unknown type H5T_COMPOUND"); break; case H5T_REFERENCE: throw Exception("Object::getStlType: Unknown type H5T_REFERENCE"); break; case H5T_ENUM: throw Exception("Object::getStlType: Unknown type H5T_ENUM"); break; case H5T_VLEN: throw Exception("Object::getStlType: Unknown type H5T_VLEN"); break; case H5T_ARRAY: throw Exception("Object::getStlType: Unknown type H5T_ARRAY"); break; case H5T_NO_CLASS: throw Exception("Object::getStlType: Unknown type H5T_NO_CLASS"); break; case H5T_TIME: throw Exception("Object::getStlType: Unknown type H5T_TIME"); break; case H5T_NCLASSES: throw Exception("Object::getStlType: Unknown type H5T_NCLASSES"); break; } return typeName.str(); }