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

adds method to write vector with particle pairs

parent 1e4ae6ca
No related branches found
No related tags found
No related merge requests found
......@@ -274,6 +274,44 @@ std::string hdf5_tools::read_string(
}
}
template <class partsize_t>
int hdf5_tools::write_particle_ID_pairs_with_single_rank(
const std::vector<partsize_t> v,
const hid_t group,
const std::string dset_name)
{
TIMEZONE("hdf5_tools::write_particle_ID_pairs_with_single_rank");
// the vector contains pair information, so its size must be a multiple of 2
assert((v.size() % 2) == 0);
// file space creation
hid_t fspace;
hsize_t dims[2];
dims[0] = v.size()/2;
dims[1] = 2;
fspace = H5Screate_simple(2, dims, NULL);
// create dataset
hsize_t dset_id = H5Dcreate(
group,
dset_name.c_str(),
hdf5_tools::hdf5_type_id<partsize_t>(),
fspace,
H5P_DEFAULT,
H5P_DEFAULT,
H5P_DEFAULT);
// write data
H5Dwrite(
dset_id,
hdf5_tools::hdf5_type_id<partsize_t>(),
H5S_ALL,
H5S_ALL,
H5P_DEFAULT,
&v.front());
// clean up
H5Dclose(dset_id);
H5Sclose(fspace);
return EXIT_SUCCESS;
}
template
std::vector<int> hdf5_tools::read_vector<int>(
const hid_t,
......
......@@ -33,6 +33,65 @@
namespace hdf5_tools
{
// see https://support.hdfgroup.org/HDF5/doc/H5.user/Datatypes.html
template <typename data_type> hid_t hdf5_type_id();
template <> hid_t hdf5_type_id<char>()
{
return H5T_NATIVE_CHAR;
}
template <> hid_t hdf5_type_id<signed char>()
{
return H5T_NATIVE_SCHAR;
}
template <> hid_t hdf5_type_id<unsigned char>()
{
return H5T_NATIVE_UCHAR;
}
template <> hid_t hdf5_type_id<short>()
{
return H5T_NATIVE_SHORT;
}
template <> hid_t hdf5_type_id<unsigned short>()
{
return H5T_NATIVE_USHORT;
}
template <> hid_t hdf5_type_id<int>()
{
return H5T_NATIVE_INT;
}
template <> hid_t hdf5_type_id<unsigned>()
{
return H5T_NATIVE_UINT;
}
template <> hid_t hdf5_type_id<long>()
{
return H5T_NATIVE_LONG;
}
template <> hid_t hdf5_type_id<unsigned long>()
{
return H5T_NATIVE_ULONG;
}
template <> hid_t hdf5_type_id<long long>()
{
return H5T_NATIVE_LLONG;
}
template <> hid_t hdf5_type_id<unsigned long long>()
{
return H5T_NATIVE_ULLONG;
}
template <> hid_t hdf5_type_id<float>()
{
return H5T_NATIVE_FLOAT;
}
template <> hid_t hdf5_type_id<double>()
{
return H5T_NATIVE_DOUBLE;
}
template <> hid_t hdf5_type_id<long double>()
{
return H5T_NATIVE_LDOUBLE;
}
int grow_single_dataset(
hid_t dset,
int tincrement);
......@@ -90,6 +149,12 @@ namespace hdf5_tools
const hid_t group,
const std::string dset_name,
const number value);
template <class partsize_t>
int write_particle_ID_pairs_with_single_rank(
const std::vector<partsize_t> v,
const hid_t group,
const std::string dset_name);
}
#endif//HDF5_TOOLS_HPP
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment