From bf0be4fb6124e7147627774c74aeb4123cf4b1b3 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Mon, 9 Mar 2015 15:31:11 +0100 Subject: [PATCH] Added another layer for hdf5_write_array --- src/hdf5_array.hpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/hdf5_array.hpp b/src/hdf5_array.hpp index c3052b1..64eab5f 100644 --- a/src/hdf5_array.hpp +++ b/src/hdf5_array.hpp @@ -21,7 +21,7 @@ liability. In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or reproducing the software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also +sthat may mean that it is complicated to manipulate, and that also therefore means that it is reserved for developers and experienced professionals having in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their @@ -100,15 +100,38 @@ namespace CosmoTool { template void hdf5_write_array(H5::CommonFG& fg, const std::string& data_set_name, const ArrayType& data, - const hdf5_data_type& datatype) + const hdf5_data_type& datatype, + const std::vector& dimensions, + bool doCreate = true, + bool useBases = false) { - std::vector dimensions(data.shape(), data.shape() + data.num_dimensions()); H5::DataSpace dataspace(data.num_dimensions(), dimensions.data()); - H5::DataSet dataset = fg.createDataSet(data_set_name, datatype, dataspace); + if (useBases) { + std::vector offsets(data.index_bases(), data.index_bases() + data.num_dimensions()); + dataspace.offsetSimple(offsets.data()); + } + + H5::DataSet dataset; + if (doCreate) + dataset = fg.createDataSet(data_set_name, datatype, dataspace); + else + dataset = fg.openDataSet(data_set_name); dataset.write(data.data(), datatype); } + + + template + void hdf5_write_array(H5::CommonFG& fg, const std::string& data_set_name, + const ArrayType& data, + const hdf5_data_type& datatype, + bool doCreate = true, + bool useBases = false) + { + std::vector dimensions(data.shape(), data.shape() + data.num_dimensions()); + hdf5_write_array(fg, data_set_name, data, datatype, dimensions, doCreate, useBases); + } /* HDF5 complex type */ template