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

add "require_size" hdf5 functionality

parent 8c6fe88e
Pipeline #13236 passed with stage
in 6 minutes and 4 seconds
......@@ -175,9 +175,12 @@ class _base(object):
def rewrite_par(
self,
group = None,
parameters = None):
parameters = None,
file_name = None):
assert(group != 'parameters')
ofile = h5py.File(os.path.join(self.work_dir, self.simname + '.h5'), 'r+')
if type(file_name) == None:
file_name = os.path.join(self.work_dir, self.simname + '.h5')
ofile = h5py.File(file_name, 'a')
for k in parameters.keys():
if group not in ofile.keys():
ofile.create_group(group)
......
#include "hdf5_tools.hpp"
int hdf5_tools::require_size_single_dataset(hid_t dset, int tsize)
{
int ndims;
hsize_t space;
space = H5Dget_space(dset);
ndims = H5Sget_simple_extent_ndims(space);
hsize_t *dims = new hsize_t[ndims];
H5Sget_simple_extent_dims(space, dims, NULL);
if (dims[0] < tsize)
{
dims[0] = tsize;
H5Dset_extent(dset, dims);
}
H5Sclose(space);
delete[] dims;
return EXIT_SUCCESS;
}
int hdf5_tools::grow_single_dataset(hid_t dset, int tincrement)
{
int ndims;
......@@ -15,6 +33,21 @@ int hdf5_tools::grow_single_dataset(hid_t dset, int tincrement)
return EXIT_SUCCESS;
}
herr_t hdf5_tools::require_size_dataset_visitor(
hid_t o_id,
const char *name,
const H5O_info_t *info,
void *op_data)
{
if (info->type == H5O_TYPE_DATASET)
{
hsize_t dset = H5Dopen(o_id, name, H5P_DEFAULT);
require_size_single_dataset(dset, *((int*)(op_data)));
H5Dclose(dset);
}
return EXIT_SUCCESS;
}
herr_t hdf5_tools::grow_dataset_visitor(
hid_t o_id,
const char *name,
......@@ -50,6 +83,26 @@ int hdf5_tools::grow_file_datasets(
return file_problems;
}
int hdf5_tools::require_size_file_datasets(
const hid_t stat_file,
const std::string group_name,
int tsize)
{
int file_problems = 0;
hid_t group;
group = H5Gopen(stat_file, group_name.c_str(), H5P_DEFAULT);
H5Ovisit(
group,
H5_INDEX_NAME,
H5_ITER_NATIVE,
require_size_dataset_visitor,
&tsize);
H5Gclose(group);
return file_problems;
}
template <typename number>
std::vector<number> hdf5_tools::read_vector(
const hid_t group,
......
......@@ -48,6 +48,21 @@ namespace hdf5_tools
const std::string group_name,
int tincrement);
int require_size_single_dataset(
hid_t dset,
int tincrement);
herr_t require_size_dataset_visitor(
hid_t o_id,
const char *name,
const H5O_info_t *info,
void *op_data);
int require_size_file_datasets(
const hid_t stat_file,
const std::string group_name,
int tincrement);
template <typename number>
std::vector<number> read_vector(
const hid_t group,
......
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