H5CPP  v1.14.0
Modern C++ templates for HDF5 serial and parallel I/O
Loading...
Searching...
No Matches
reference.cpp
#include <armadillo>
#include <vector>
#include <h5cpp/all>
int main(){
h5::fd_t fd = h5::create("ref.h5", H5F_ACC_TRUNC);
{
h5::ds_t ds = h5::create<float>(fd,"01",
h5::current_dims{10,20}, h5::chunk{2,2} | h5::fill_value<float>{1} );
h5::reference_t ref = h5::reference(fd, "01", h5::offset{2,2}, h5::count{4,4});
h5::write(fd, "single reference", ref);
/* you can factor out `count` this way : h5::count count{2,2}; */
// The HDF5 CAPI reqires fd + dataset name, instead of hid_t to ds: wishy-washy
h5::reference(fd, "01", h5::offset{2,2}, h5::count{4,4}),
h5::reference(fd, "01", h5::offset{4,8}, h5::count{1,1}),
h5::reference(fd, "01", h5::offset{6,12}, h5::count{3,3}),
h5::reference(fd, "01", h5::offset{8,16}, h5::count{2,1})
};
// datset shape can be controlled with dimensions, in this case is 2x2
// and is not related to the selected regions!!!
// data type is H5R_DATASET_REGION when dataspace is provided, otherwise OBJECT
h5::write(fd, "index", idx, h5::current_dims{2,2}, h5::max_dims{H5S_UNLIMITED, 2});
}
{ // we going to update the regions referenced by the set of region-references
// stored in "index"
h5::ds_t ds = h5::open(fd, "index");
std::vector color(50, 9);
// this is to read from selection
h5::exp::write(ds, ref, color.data());
}
{ // we are reading back data from the regions, now they all must be 'color' value '9'
h5::ds_t ds = h5::open(fd, "index");
// this is to read from selection
arma::fmat mat = h5::exp::read<arma::fmat>(ds, ref);
std::cout << mat << "\n";
}
}
{ // for verification
std::cout << h5::read<arma::fmat>(fd, "01") << "\n\n";
}
}
T data(T... args)
h5::at_t create(const hid_t &parent, const std::string &path, args_t &&... args)
Create a new attribute of element type T on a parent HDF5 object.
Definition H5Acreate.hpp:100
T aread(const hid_t &ds, const std::string &name, const h5::acpl_t &acpl=h5::default_acpl)
Read an attribute by name and return its value as type T.
Definition H5Aread.hpp:76
h5::at_t open(const hid_t &parent, const std::string &path, const h5::acpl_t &acpl=h5::default_acpl)
Open an existing attribute by name on a parent HDF5 object.
Definition H5Aopen.hpp:56
h5::gr_t write(const LOC &parent, const std::string &path, const T &src)
Write a sparse matrix or vector as a CSC group.
Definition H5Dsparse.hpp:185