9 #ifndef H5EASY_BITS_SCALAR_HPP
10 #define H5EASY_BITS_SCALAR_HPP
12 #include "../H5Easy.hpp"
23 template <
typename T,
typename =
void>
26 inline static DataSet
dump(File& file,
27 const std::string& path,
29 const DumpOptions& options) {
30 DataSet dataset = initScalarDataset(file, path, data, options);
32 if (options.flush()) {
38 inline static T
load(
const File& file,
const std::string& path) {
39 DataSet dataset = file.getDataSet(path);
46 const std::string& path,
47 const std::string& key,
49 const DumpOptions& options) {
50 Attribute attribute = initScalarAttribute(file, path, key, data, options);
51 attribute.write(data);
52 if (options.flush()) {
59 const std::string& path,
60 const std::string& key) {
61 DataSet dataset = file.getDataSet(path);
62 Attribute attribute = dataset.getAttribute(key);
68 inline static DataSet dump_extend(File& file,
69 const std::string& path,
71 const std::vector<size_t>& idx,
72 const DumpOptions& options) {
73 std::vector<size_t> ones(idx.size(), 1);
75 if (file.exist(path)) {
76 DataSet dataset = file.getDataSet(path);
77 std::vector<size_t> dims = dataset.getDimensions();
78 std::vector<size_t> shape = dims;
79 if (dims.size() != idx.size()) {
80 throw detail::error(file, path,
81 "H5Easy::dump: Dimension of the index and the existing field do not match");
83 for (
size_t i = 0; i < dims.size(); ++i) {
84 shape[i] = std::max(dims[i], idx[i] + 1);
87 dataset.resize(shape);
89 dataset.select(idx, ones).write(data);
90 if (options.flush()) {
96 detail::createGroupsToDataSet(file, path);
97 std::vector<size_t> shape = idx;
99 std::vector<size_t> unlim_shape(idx.size(), unlim);
100 std::vector<hsize_t> chunks(idx.size(), 10);
101 if (options.isChunked()) {
102 chunks = options.getChunkSize();
103 if (chunks.size() != idx.size()) {
104 throw error(file, path,
"H5Easy::dump: Incorrect dimension ChunkSize");
107 for (
size_t& i : shape) {
112 props.add(Chunking(chunks));
113 DataSet dataset = file.createDataSet(path, dataspace, AtomicType<T>(), props);
114 dataset.select(idx, ones).write(data);
115 if (options.flush()) {
121 inline static T load_part(
const File& file,
122 const std::string& path,
123 const std::vector<size_t>& idx) {
124 std::vector<size_t> ones(idx.size(), 1);
125 DataSet dataset = file.getDataSet(path);
127 dataset.select(idx, ones).read(data);
static const size_t UNLIMITED
Definition: H5DataSpace.hpp:42
Definition: H5Easy.hpp:51
DataSet dump(File &file, const std::string &path, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) DataSet in an open HDF5 file.
Definition: H5Easy_public.hpp:115
T loadAttribute(const File &file, const std::string &path, const std::string &key)
Load a Attribute in an open HDF5 file to an object (templated).
Definition: H5Easy_public.hpp:185
Attribute dumpAttribute(File &file, const std::string &path, const std::string &key, const T &data, DumpMode mode=DumpMode::Create)
Write object (templated) to a (new) Attribute in an open HDF5 file.
Definition: H5Easy_public.hpp:167
T load(const File &file, const std::string &path, const std::vector< size_t > &idx)
Load entry "(i,j)" from a rank-two DataSet in an open HDF5 file to a scalar.
Definition: H5Easy_public.hpp:157
PropertyList< PropertyType::DATASET_CREATE > DataSetCreateProps
Definition: H5PropertyList.hpp:79