Skip to content
Snippets Groups Projects
Commit 302b8e47 authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

use hdf5_tools::hdf5_type_id to simplify code

parent 1ae9d5ba
No related branches found
No related tags found
2 merge requests!48merge develop,!46Feature/warning free
Pipeline #138759 failed
...@@ -208,13 +208,7 @@ std::vector<number> hdf5_tools::read_vector( ...@@ -208,13 +208,7 @@ std::vector<number> hdf5_tools::read_vector(
hsize_t vector_length; hsize_t vector_length;
// first, read size of array // first, read size of array
hid_t dset, dspace; hid_t dset, dspace;
hid_t mem_dtype; hid_t mem_dtype = H5Tcopy(hdf5_tools::hdf5_type_id<number>());
if (typeid(number) == typeid(int))
mem_dtype = H5Tcopy(H5T_NATIVE_INT);
else if (typeid(number) == typeid(double))
mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE);
else
return result;
dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT);
dspace = H5Dget_space(dset); dspace = H5Dget_space(dset);
assert(H5Sget_simple_extent_ndims(dspace) == 1); assert(H5Sget_simple_extent_ndims(dspace) == 1);
...@@ -235,15 +229,7 @@ number hdf5_tools::read_value( ...@@ -235,15 +229,7 @@ number hdf5_tools::read_value(
TIMEZONE("hdf5_tools::read_value"); TIMEZONE("hdf5_tools::read_value");
number result; number result;
hid_t dset; hid_t dset;
hid_t mem_dtype; hid_t mem_dtype = H5Tcopy(hdf5_tools::hdf5_type_id<number>());
if (typeid(number) == typeid(int))
mem_dtype = H5Tcopy(H5T_NATIVE_INT);
else if (typeid(number) == typeid(long long int))
mem_dtype = H5Tcopy(H5T_NATIVE_LLONG);
else if (typeid(number) == typeid(double))
mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE);
else
return result;
if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT)) if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT))
{ {
dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT);
...@@ -270,13 +256,10 @@ int hdf5_tools::write_value_with_single_rank( ...@@ -270,13 +256,10 @@ int hdf5_tools::write_value_with_single_rank(
const std::string dset_name, const std::string dset_name,
const number value) const number value)
{ {
assert(typeid(number) == typeid(int) ||
typeid(number) == typeid(double));
hid_t dset, mem_dtype; hid_t dset, mem_dtype;
if (typeid(number) == typeid(int)) mem_dtype = H5Tcopy(hdf5_tools::hdf5_type_id<number>());
mem_dtype = H5Tcopy(H5T_NATIVE_INT);
else if (typeid(number) == typeid(double))
mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE);
else
return EXIT_FAILURE;
if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT)) if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT))
{ {
dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT); dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment