Do not auto-resize if it is not what we want
This commit is contained in:
parent
48bdd03947
commit
188af485c9
@ -213,20 +213,27 @@ namespace CosmoTool {
|
||||
);
|
||||
}
|
||||
|
||||
template<typename ArrayType>
|
||||
void hdf5_check_array(ArrayType& data, std::vector<hsize_t>& dims) {
|
||||
for (long i = 0; i < data.num_dimensions(); i++) {
|
||||
if (data.shape()[i] != dims[i]) {
|
||||
throw InvalidDimensions();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename ArrayType>
|
||||
typename boost::disable_if<
|
||||
array_has_resize<ArrayType>
|
||||
>::type
|
||||
hdf5_resize_array(ArrayType& data, std::vector<hsize_t>& dims) {
|
||||
for (long i = 0; i < data.num_dimensions(); i++) {
|
||||
assert (data.shape()[i] == dims[i]);
|
||||
}
|
||||
hdf5_check_array(data, dims);
|
||||
}
|
||||
|
||||
template<typename ArrayType, typename hdf5_data_type>
|
||||
void hdf5_read_array(H5::CommonFG& fg, const std::string& data_set_name,
|
||||
void hdf5_read_array_typed(H5::CommonFG& fg, const std::string& data_set_name,
|
||||
ArrayType& data,
|
||||
const hdf5_data_type& datatype)
|
||||
const hdf5_data_type& datatype, bool auto_resize = true)
|
||||
{
|
||||
H5::DataSet dataset = fg.openDataSet(data_set_name);
|
||||
H5::DataSpace dataspace = dataset.getSpace();
|
||||
@ -238,17 +245,21 @@ namespace CosmoTool {
|
||||
}
|
||||
|
||||
dataspace.getSimpleExtentDims(dimensions.data());
|
||||
hdf5_resize_array(data, dimensions);
|
||||
if (auto_resize)
|
||||
hdf5_resize_array(data, dimensions);
|
||||
else
|
||||
hdf5_check_array(data, dimensions);
|
||||
|
||||
dataset.read(data.data(), datatype);
|
||||
}
|
||||
|
||||
template<typename ArrayType>
|
||||
void hdf5_read_array(H5::CommonFG& fg, const std::string& data_set_name, ArrayType& data )
|
||||
void hdf5_read_array(H5::CommonFG& fg, const std::string& data_set_name, ArrayType& data, bool auto_resize = true )
|
||||
{
|
||||
typedef typename ArrayType::element T;
|
||||
|
||||
get_hdf5_data_type<T> hdf_data_type;
|
||||
hdf5_read_array(fg, data_set_name, data, hdf_data_type.type());
|
||||
hdf5_read_array_typed(fg, data_set_name, data, hdf_data_type.type(), auto_resize);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user