#include <Eigen/Dense>
#include <armadillo>
#include <h5cpp/all>
#include "generated.h"
#include <iostream>
#include <numeric>
#include <vector>
template <class T> using RowMajor = Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
int main() {
auto fd =
h5::create(
"packettable.h5", H5F_ACC_TRUNC);
auto check = [](const char* label, bool ok) {
std::cout << (ok ?
"✔ ok " :
"✘ failed") <<
" " << label <<
"\n";
};
{
{
h5::max_dims{H5S_UNLIMITED},
for (int x : stream) h5::append(pt, x);
}
check("stream<int> -> 1D unlimited dataset (80 elements)",
back.size() == stream.
size() && back == stream);
}
{
{
h5::max_dims{H5S_UNLIMITED, 3, 5},
for (int x : stream) h5::append(pt, x);
}
check("stream<int> -> 3D unlimited dataset (4 x 3 x 5)",
back.size() == stream.
size() && back == stream);
}
{
for (size_t i = 0; i < stream.size(); ++i) stream[i].idx = i;
{
h5::max_dims{H5S_UNLIMITED},
for (const auto& r : stream) h5::append(pt, r);
}
bool size_ok = back.size() == stream.size();
bool idx_ok = size_ok;
for (size_t i = 0; idx_ok && i < back.size(); ++i)
idx_ok = (back[i].idx == stream[i].idx);
check("stream<POD struct> -> 1D unlimited (128 records, idx)",
size_ok && idx_ok);
}
{
constexpr size_t nrows = 2, ncols = 256, nframes = 20;
RowMajor<float> frame(nrows, ncols);
for (size_t i = 0; i < nrows; ++i)
for (size_t j = 0; j < ncols; ++j)
frame(i, j) = static_cast<float>(i * ncols + j);
{
h5::max_dims{H5S_UNLIMITED, nrows, ncols},
for (size_t f = 0; f < nframes; ++f) h5::append(pt, frame);
}
bool size_ok = back.size() == nframes * nrows * ncols;
bool values_ok = size_ok;
for (size_t k = 0; values_ok && k < nrows * ncols; ++k)
values_ok = (back[k] == static_cast<float>(k));
check("stream<Eigen frame> -> 3D unlimited (20 x 2 x 256)",
size_ok && values_ok);
}
return 0;
}
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