Commit b1b5a27f authored by Cristian Lalescu's avatar Cristian Lalescu
Browse files

add read_value method

very simple functionality, but I gain two lines per value in the useful
file, which I consider a big deal.
parent 7124c815
#include "hdf5_tools.hpp"
#include <cfloat>
#include <climits>
int hdf5_tools::require_size_single_dataset(hid_t dset, int tsize)
{
......@@ -136,6 +138,37 @@ std::vector<number> hdf5_tools::read_vector(
return result;
}
template <typename number>
std::vector<number> hdf5_tools::read_value(
const hid_t group,
const std::string dset_name)
{
number result;
hid_t dset;
hid_t 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);
H5Dread(dset, mem_dtype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &result);
H5Dclose(dset);
}
else
{
DEBUG_MSG("attempted to read dataset %s which does not exist.\n",
dset_name.c_str());
if (typeid(number) == typeid(int))
result = INT_MAX;
else if (typeid(number) == typeid(double))
result = DBL_MAX;
}
H5Tclose(mem_dtype);
return result;
}
template <typename dtype>
std::vector<dtype> hdf5_tools::read_vector_with_single_rank(
const int myrank,
......
......@@ -79,6 +79,11 @@ namespace hdf5_tools
std::string read_string(
const hid_t group,
const std::string dset_name);
template <typename number>
number read_value(
const hid_t group,
const std::string dset_name);
}
#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