Commit d947f51c authored by gsell's avatar gsell
Browse files

src/h5core/...:

- introduce/implement new H5hut types
parent f5729f6f
......@@ -985,7 +985,7 @@ h5b_get_field_info_by_name (
*elem_rank = (h5_size_t) _elem_rank;
}
if (type) {
TRY (*type = h5priv_get_native_dataset_type (dataset_id));
TRY (*type = h5priv_get_normalized_dataset_type (dataset_id));
TRY (*type = h5priv_map_hdf5_type_to_enum(*type));
}
TRY (hdf5_close_dataspace (dataspace_id));
......
......@@ -129,21 +129,21 @@ write_vertices (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_vertices__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_glb_vertices,
m->num_leaf_levels,
1));
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_b_vertices__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_b_vtx,
m->num_leaf_levels,
1));
TRY (h5priv_write_attrib (
m->mesh_gid,
"__first_b_vertices__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->first_b_vtx,
m->num_leaf_levels,
1));
......@@ -492,21 +492,21 @@ write_vertices_chk (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_vertices__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_glb_vertices,
m->num_leaf_levels,
1));
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_b_vertices__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_b_vtx,
m->num_leaf_levels,
1));
TRY (h5priv_write_attrib (
m->mesh_gid,
"__first_b_vertices__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->first_b_vtx,
m->num_leaf_levels,
1));
......@@ -557,7 +557,7 @@ write_elems (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_elems__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_glb_elems,
m->num_leaf_levels,
1));
......@@ -565,7 +565,7 @@ write_elems (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_leaf_elems__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_glb_leaf_elems,
m->num_leaf_levels,
1));
......@@ -573,7 +573,7 @@ write_elems (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_leaf_levels__",
H5T_NATIVE_INT16,
H5_INT16_T,
&m->num_leaf_levels,
1,
1));
......@@ -581,14 +581,14 @@ write_elems (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__is_chunked__",
H5T_NATIVE_INT16,
H5_INT16_T,
&m->is_chunked,
1,
1));
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_weights__",
H5T_NATIVE_INT32,
H5_INT32_T,
&m->num_weights,
1,
1));
......@@ -678,7 +678,7 @@ write_elems_chk (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_elems__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_glb_elems,
m->num_leaf_levels,
1));
......@@ -686,7 +686,7 @@ write_elems_chk (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_leaf_elems__",
H5T_NATIVE_INT64,
H5_INT64_T,
m->num_glb_leaf_elems,
m->num_leaf_levels,
1));
......@@ -694,7 +694,7 @@ write_elems_chk (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__num_leaf_levels__",
H5T_NATIVE_INT16,
H5_INT16_T,
&m->num_leaf_levels,
1,
1));
......@@ -702,7 +702,7 @@ write_elems_chk (
TRY (h5priv_write_attrib (
m->mesh_gid,
"__is_chunked__",
H5T_NATIVE_INT16,
H5_INT16_T,
&m->is_chunked,
1,
1));
......
......@@ -116,7 +116,7 @@ get_tagset_info (
TRY (tag_id = hdf5_open_group (tags_id, name));
// determine type of dataset with values
TRY (dset_id = hdf5_open_dataset_by_name (tag_id, "values"));
TRY (*type = h5priv_get_native_dataset_type (dset_id));
TRY (*type = h5priv_get_normalized_dataset_type (dset_id));
TRY (hdf5_close_dataset (dset_id));
TRY (hdf5_close_group (tag_id));
......@@ -450,7 +450,7 @@ read_tagset (
TRY (dset_id = hdf5_open_dataset_by_name (loc_id, "values"));
TRY (num_vals = hdf5_get_npoints_of_dataset (dset_id));
TRY (vals = h5_calloc (num_vals, sizeof (*vals)));
TRY (dsinfo.type_id = h5priv_get_native_dataset_type (dset_id));
TRY (dsinfo.type_id = h5priv_get_normalized_dataset_type (dset_id));
TRY (read_dataset (
tagset->m,
tagset->m->f,
......@@ -656,9 +656,9 @@ write_tagset (
open_space_all, open_space_all,
values));
h5_int64_t scope = tagset->scope.min_level;
TRY (h5priv_write_attrib (group_id, "__scope_min__", H5_INT64, &scope, 1, 1));
TRY (h5priv_write_attrib (group_id, "__scope_min__", H5_INT64_T, &scope, 1, 1));
scope = tagset->scope.max_level;
TRY (h5priv_write_attrib (group_id, "__scope_max__", H5_INT64, &scope, 1, 1));
TRY (h5priv_write_attrib (group_id, "__scope_max__", H5_INT64_T, &scope, 1, 1));
TRY (hdf5_close_group (group_id));
TRY (h5_free (elems));
......
......@@ -80,7 +80,7 @@ h5u_read_data (
const h5_file_t fh, /*!< [in] Handle to open file */
const char* name, /*!< [in] Name to associate dataset with */
void* data, /*!< [out] Array of data */
const hid_t type
const h5_types_t type
) {
h5_file_p f = (h5_file_p)fh;
H5_CORE_API_ENTER (h5_err_t,
......@@ -88,6 +88,9 @@ h5u_read_data (
f, name, data, (long long int)type);
CHECK_TIMEGROUP (f);
hid_t hdf5_type;
TRY (hdf5_type = h5priv_map_enum_to_normalized_type (type));
struct h5u_fdata *u = f->u;
hid_t dataset_id;
hid_t space_id;
......@@ -157,7 +160,7 @@ h5u_read_data (
TRY (h5priv_start_throttle (f));
TRY (hdf5_read_dataset (
dataset_id,
type,
hdf5_type,
memspace_id,
space_id,
f->props->xfer_prop,
......@@ -177,7 +180,7 @@ h5u_write_data (
const h5_file_t fh, /*!< IN: Handle to open file */
const char *name, /*!< IN: Name to associate array with */
const void *data, /*!< IN: Array to commit to disk */
const hid_t type /*!< IN: Type of data */
const h5_types_t type /*!< IN: Type of data */
) {
h5_file_p f = (h5_file_p)fh;
H5_CORE_API_ENTER (h5_err_t,
......@@ -185,7 +188,9 @@ h5u_write_data (
f, name, data, (long long int)type);
CHECK_TIMEGROUP( f );
CHECK_WRITABLE_MODE( f );
hid_t hdf5_type;
TRY (hdf5_type = h5priv_map_enum_to_normalized_type (type));
struct h5u_fdata *u = f->u;
hid_t dset_id;
......@@ -207,7 +212,7 @@ h5u_write_data (
TRY (dset_id = hdf5_create_dataset (
f->step_gid,
name2,
type,
hdf5_type,
u->shape,
H5P_DEFAULT));
}
......@@ -217,7 +222,7 @@ h5u_write_data (
hdf5_get_objname(f->step_gid), name2);
TRY (hdf5_write_dataset (
dset_id,
type,
hdf5_type,
u->memshape,
u->diskshape,
f->props->xfer_prop,
......
......@@ -611,7 +611,7 @@ get_dataset_info (
H5_INLINE_FUNC_ENTER (h5_err_t);
if (dataset_type) {
h5_int64_t type_;
TRY (type_ = h5priv_get_native_dataset_type (dataset_id));
TRY (type_ = h5priv_get_normalized_dataset_type (dataset_id));
TRY (*dataset_type = h5priv_map_hdf5_type_to_enum (type_));
}
if (dataset_nelem) {
......
......@@ -16,7 +16,7 @@
static inline hid_t
h5priv_get_native_attribute_type (
h5priv_get_normalized_attribute_type (
hid_t attr_id
) {
H5_PRIV_FUNC_ENTER (
......@@ -24,7 +24,7 @@ h5priv_get_native_attribute_type (
"attr_id=%lld (%s)",
(long long int)attr_id, hdf5_get_objname (attr_id));
TRY (ret_value = hdf5_get_attribute_type (attr_id));
TRY (ret_value = h5priv_get_native_type (ret_value));
TRY (ret_value = h5priv_normalize_type (ret_value));
H5_PRIV_FUNC_RETURN (ret_value);
}
......@@ -32,7 +32,7 @@ static inline h5_err_t
h5priv_read_attrib (
const hid_t id, /*!< HDF5 object ID */
const char* attrib_name, /*!< name of HDF5 attribute to read */
const hid_t attrib_type, /*!< HDF5 type of attribute */
const h5_int64_t attrib_type, /*!< H5hut enum type of attribute */
void* const attrib_value /*!< OUT: attribute value */
) {
H5_PRIV_API_ENTER (h5_err_t,
......@@ -43,20 +43,41 @@ h5priv_read_attrib (
(long long int)attrib_type,
attrib_value);
hid_t attrib_id;
TRY (attrib_id = hdf5_open_attribute_by_name (id, attrib_name));
hid_t mem_type;
hid_t space_id;
TRY (attrib_id = hdf5_open_attribute_by_name (id, attrib_name));
TRY (mem_type = h5priv_get_native_attribute_type (attrib_id));
if (mem_type != attrib_type)
/*
attrib_type -> normalized HDF5 type
determine file type of attribute
compare normalized types
if not equal:
error
if attribute type is string:
set mem type to file type
else
set mem type to normalized attrib_type
*/
hid_t normalized_type;
TRY (normalized_type = h5priv_map_enum_to_normalized_type (attrib_type));
hid_t file_type;
TRY (file_type = hdf5_get_attribute_type (attrib_id));
hid_t normalized_file_type;
TRY (normalized_file_type = h5priv_normalize_type (file_type));
if (normalized_file_type != normalized_type)
H5_PRIV_API_LEAVE (
h5_error (
H5_ERR_HDF5,
"Attribute '%s' has type '%s' but "
"was requested as '%s'.",
attrib_name,
hdf5_get_type_name (mem_type),
hdf5_get_type_name (attrib_type)));
hdf5_get_type_name (normalized_file_type),
hdf5_get_type_name (normalized_type)));
if (normalized_type == H5_STRING) {
mem_type = file_type;
} else {
mem_type = normalized_type;
}
TRY (space_id = hdf5_get_attribute_dataspace (attrib_id));
TRY (hdf5_read_attribute (attrib_id, mem_type, attrib_value));
TRY (hdf5_close_dataspace(space_id));
......@@ -68,7 +89,7 @@ static inline h5_err_t
h5priv_write_attrib (
const hid_t id, /*!< HDF5 object ID */
const char* attrib_name, /*!< name of HDF5 attribute to write */
const hid_t attrib_type, /*!< HDF5 type of attribute */
const h5_types_t attrib_type, /*!< type of attribute */
const void* attrib_value, /*!< value of attribute */
const hsize_t attrib_nelem, /*!< number of elements (dimension) */
const int overwrite
......@@ -84,12 +105,13 @@ h5priv_write_attrib (
overwrite);
hid_t space_id;
hid_t attrib_id;
hid_t type_id;
if ( attrib_type == H5T_NATIVE_CHAR ) {
TRY (type_id = hdf5_create_string_type (attrib_nelem));
hid_t hdf5_type;
if (attrib_type == H5_STRING_T) {
// :FIXME: we have to close this new type!
TRY (hdf5_type = hdf5_create_string_type (attrib_nelem));
TRY (space_id = hdf5_create_dataspace_scalar ());
} else {
type_id = attrib_type;
hdf5_type = h5priv_map_enum_to_normalized_type (attrib_type);
TRY (space_id = hdf5_create_dataspace (1, &attrib_nelem, NULL));
}
h5_err_t exists;
......@@ -107,11 +129,11 @@ h5priv_write_attrib (
TRY (attrib_id = hdf5_create_attribute (
id,
attrib_name,
type_id,
hdf5_type,
space_id,
H5P_DEFAULT, H5P_DEFAULT));
TRY (hdf5_write_attribute (attrib_id, type_id, attrib_value));
TRY (hdf5_write_attribute (attrib_id, hdf5_type, attrib_value));
TRY (hdf5_close_attribute (attrib_id));
TRY (hdf5_close_dataspace (space_id));
......@@ -132,8 +154,7 @@ get_attrib_info (
) {
H5_INLINE_FUNC_ENTER (h5_err_t);
hid_t datatype_id;
TRY (datatype_id = h5priv_get_native_attribute_type (attrib_id));
TRY (datatype_id = h5priv_get_normalized_attribute_type (attrib_id));
if (attrib_nelem) {
if (datatype_id == H5_STRING) {
*attrib_nelem = H5Tget_size (datatype_id);
......
......@@ -738,21 +738,40 @@ hdf5_get_native_type (
*/
static inline char_p
hdf5_get_type_name (
hid_t type_id
hid_t type
) {
if (type_id == H5_INT32)
return "H5_INT32_T";
if (type_id == H5_INT64)
return "H5_INT64_T";
if (type_id == H5_FLOAT32)
return "H5_FLOAT32_T";
if (type_id == H5_FLOAT64)
return "H5_FLOAT64_T";
if (type_id == H5_STRING)
return "H5_STRING_T";
HDF5_WRAPPER_ENTER (char_p,
"type=%lld",
(long long int)type);
H5T_class_t tclass;
int size;
TRY (tclass = H5Tget_class (type));
TRY (size = H5Tget_size (type));
h5_warn ("Unknown type id %lld", (long long int)type_id);
return "[unknown]";
switch (tclass){
case H5T_INTEGER:
if (size==8) {
ret_value = "H5_INT64_T";
} else if (size==4) {
ret_value = "H5_INT32_T";
} else if (size==2) {
ret_value = "H5_INT16_T";
}
break;
case H5T_FLOAT:
if (size==8) {
ret_value = "H5_FLOAT64_T";
} else if (size==4) {
ret_value = "H5_FLOAT32_T";
}
break;
case H5T_STRING:
ret_value = "H5_STRING_T";
break;
default:
ret_value = "unknown";
}
HDF5_WRAPPER_RETURN (ret_value);
}
static inline const char*
......@@ -827,14 +846,14 @@ hdf5_create_string_type(
const hsize_t len
) {
HDF5_WRAPPER_ENTER (hid_t, "len = %llu", len);
hid_t type_id = H5Tcopy ( H5T_C_S1 );
hid_t type_id = H5Tcopy (H5T_C_S1);
if (type_id < 0)
HDF5_WRAPPER_LEAVE (
h5_error(
H5_ERR_HDF5,
"Can't duplicate C string type."));
herr_t herr = H5Tset_size ( type_id, len );
herr_t herr = H5Tset_size (type_id, len);
if (herr < 0)
HDF5_WRAPPER_LEAVE (
h5_error(
......
......@@ -119,38 +119,69 @@ h5priv_close_step (
const h5_file_p f
);
static inline h5_int64_t
h5priv_map_hdf5_type_to_enum (
hid_t hdf5_type_id
#define H5_STRING H5T_NATIVE_CHAR
#define H5_INT16 H5T_NATIVE_INT16
#define H5_UINT16 H5T_NATIVE_UINT16
#define H5_INT32 H5T_NATIVE_INT32
#define H5_UINT32 H5T_NATIVE_UINT32
#define H5_INT64 H5T_NATIVE_INT64
#define H5_UINT64 H5T_NATIVE_UINT64
#define H5_FLOAT32 H5T_NATIVE_FLOAT
#define H5_FLOAT64 H5T_NATIVE_DOUBLE
/*
Map given enumeration type to corresponding HDF5 type. We use this HDF5
type for reading and writing datasets and attributes.
*/
static inline hid_t
h5priv_map_enum_to_normalized_type (
h5_types_t type
) {
if (hdf5_type_id == H5_STRING) {
return H5_STRING_T;
} else if (hdf5_type_id == H5_INT16) {
return H5_INT16_T;
} else if (hdf5_type_id == H5_UINT16) {
return H5_UINT16_T;
} else if (hdf5_type_id == H5_INT32) {
return H5_INT32_T;
} else if (hdf5_type_id == H5_UINT32) {
return H5_UINT32_T;
} else if (hdf5_type_id == H5_INT64) {
return H5_INT64_T;
} else if (hdf5_type_id == H5_UINT64) {
return H5_UINT64_T;
} else if (hdf5_type_id == H5_FLOAT32) {
return H5_FLOAT32_T;
} else if (hdf5_type_id == H5_FLOAT64) {
return H5_FLOAT64_T;
} else if (hdf5_type_id == H5_ID) {
return H5_ID_T;
} else if (hdf5_type_id == H5_COMPOUND) {
return H5_COMPOUND_T;
H5_PRIV_API_ENTER (hid_t,
"type=%lld",
(long long int)type);
switch (type) {
case H5_STRING_T:
ret_value = H5_STRING;
break;
case H5_INT16_T:
ret_value = H5_INT16;
break;
case H5_UINT16_T:
ret_value = H5_UINT16;
break;
case H5_INT32_T:
ret_value = H5_INT32;
break;
case H5_UINT32_T:
ret_value = H5_UINT32;
break;
case H5_INT64_T:
ret_value = H5_INT64;
break;
case H5_UINT64_T:
ret_value = H5_UINT64;
break;
case H5_FLOAT32_T:
ret_value = H5_FLOAT32;
break;
case H5_FLOAT64_T:
ret_value = H5_FLOAT64;
break;
default:
H5_PRIV_API_LEAVE (
h5_error (
H5_ERR_INVAL,
"Unknown type %d", (int)type));
}
return H5_FAILURE;
H5_PRIV_API_RETURN (ret_value);
}
/*
Get H5hut type from corresponding HDF5 type.
*/
static inline hid_t
h5priv_get_native_type (
h5priv_normalize_type (
hid_t type
) {
H5_PRIV_API_ENTER (h5_int64_t,
......@@ -166,55 +197,112 @@ h5priv_get_native_type (
case H5T_INTEGER:
if (tsize==8) {
if (tsign == H5T_SGN_2) {
ret_value = H5T_NATIVE_INT64;
ret_value = H5_INT64;
} else {
ret_value = H5T_NATIVE_UINT64;
ret_value = H5_UINT64;
}
} else if (tsize==4) {
if (tsign == H5T_SGN_2) {
ret_value = H5T_NATIVE_INT32;
ret_value = H5_INT32;
} else {
ret_value = H5T_NATIVE_UINT32;
ret_value = H5_UINT32;
}
} else if (tsize==2) {
if (tsign == H5T_SGN_2) {
ret_value = H5T_NATIVE_INT16;
ret_value = H5_INT16;
} else {
ret_value = H5T_NATIVE_UINT16;
ret_value = H5_UINT16;
}
}
break;
case H5T_FLOAT:
if (tsize==8) {
ret_value = H5T_NATIVE_DOUBLE;
ret_value = H5_FLOAT64;
}
else if (tsize==4) {
ret_value = H5T_NATIVE_FLOAT;
ret_value = H5_FLOAT32;
}
break;
case H5T_STRING:
ret_value = H5T_C_S1;
ret_value = H5_STRING;
break;
default:
break;
H5_PRIV_API_LEAVE (
h5_error (
H5_ERR_INVAL,
"Unknown type %d", (int)type));
}
if (ret_value < 0)
H5_CORE_API_RETURN (ret_value);
}
/*
Map HDF5 type to H5hut type enumeration.
*/
static inline h5_int64_t
h5priv_map_hdf5_type_to_enum (
hid_t type
) {
H5_PRIV_API_ENTER (h5_int64_t,
"type=%lld",
(long long int)type);
H5T_class_t tclass;
TRY (tclass = H5Tget_class (type));
int tsize;
TRY (tsize = H5Tget_size (type));
H5T_sign_t tsign;
TRY (tsign = H5Tget_sign (type));
switch (tclass){
case H5T_INTEGER:
if (tsize==8) {
if (tsign == H5T_SGN_2) {
ret_value = H5_INT64_T;
} else {
ret_value = H5_UINT64_T;
}
} else if (tsize==4) {
if (tsign == H5T_SGN_2) {
ret_value = H5_INT32_T;
} else {
ret_value = H5_UINT32_T;
}
} else if (tsize==2) {
if (tsign == H5T_SGN_2) {
ret_value = H5_INT16_T;
} else {
ret_value = H5_UINT16_T;
}
}
break;
case H5T_FLOAT:
if (tsize==8) {
ret_value = H5_FLOAT64_T;
}
else if (tsize==4) {
ret_value = H5_FLOAT32_T;
}
break;