Commit 395528bd authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

adds hdf5 single value write method

parent 630e7e8a
......@@ -169,6 +169,36 @@ number hdf5_tools::read_value(
return result;
}
template <typename number>
int hdf5_tools::write_value_with_single_rank(
const hid_t group,
const std::string dset_name,
const number value)
{
hid_t dset, mem_dtype;
if (typeid(number) == typeid(int))
mem_dtype = H5Tcopy(H5T_NATIVE_INT);
else if (typeid(number) == typeid(double))
mem_dtype = H5Tcopy(H5T_NATIVE_DOUBLE);
if (H5Lexists(group, dset_name.c_str(), H5P_DEFAULT))
{
dset = H5Dopen(group, dset_name.c_str(), H5P_DEFAULT);
}
else
{
hid_t fspace;
hsize_t count[1];
count[0] = 1;
fspace = H5Screate_simple(1, count, NULL);
dset = H5Dcreate(group, dset_name.c_str(), mem_dtype, fspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Sclose(fspace);
}
H5Dwrite(dset, mem_dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
H5Dclose(dset);
H5Tclose(mem_dtype);
return EXIT_SUCCESS;
}
template <typename dtype>
std::vector<dtype> hdf5_tools::read_vector_with_single_rank(
const int myrank,
......@@ -269,3 +299,15 @@ double hdf5_tools::read_value<double>(
const hid_t,
const std::string);
template
int hdf5_tools::write_value_with_single_rank<int>(
const hid_t group,
const std::string dset_name,
const int value);
template
int hdf5_tools::write_value_with_single_rank<double>(
const hid_t group,
const std::string dset_name,
const double value);
......@@ -84,6 +84,12 @@ namespace hdf5_tools
number read_value(
const hid_t group,
const std::string dset_name);
template <typename number>
int write_value_with_single_rank(
const hid_t group,
const std::string dset_name,
const number value);
}
#endif//HDF5_TOOLS_HPP
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment