will fix this later, you can download the project from this github page
#include <iostream>
#include <vector>
#include "struct.h"
#include <h5cpp/core>
// generated file must be sandwiched between core and io
// to satisfy template dependencies in <h5cpp/io>
#include "generated.h"
#include <h5cpp/io>
int main(){
h5::fd_t fd = h5::create("test.h5", H5F_ACC_TRUNC);
{ // this is to create the dataset
h5::ds_t ds = h5::create<sn::record_t>(fd, "/path/dataset", h5::max_dims{H5S_UNLIMITED} );
// vector of strings as attribute:
ds["attribute"] = {"first","second","...","last"};
h5::pt_t pt = ds; // convert to packet table, you could go straight from vector as well
for(int i=0; i<3; i++)
h5::append(pt,
// this is your pod struct
sn::record_t{1.0 * i, 2.0 *i ,{1,2,3,4,5},{11,12,13,14,15}});
}
{ // read entire dataset back
h5::ds_t ds = h5::open(fd, "/path/dataset");
std::vector<std::string> attribute = h5::aread<
std::vector<std::string>>(ds, "attribute");
std::cout << attribute <<std::endl;
// dump data
for( auto rec: h5::read<std::vector<sn::record_t>>(ds, "/path/dataset")) // this is your HPC loop
std::cerr << rec.A <<" ";
std::cerr << std::endl;
}
}
the generated type descriptor:
/* Copyright (c) 2018 vargaconsulting, Toronto,ON Canada
* Author: Varga, Steven <steven@vargaconsulting.ca>
*/
#ifndef H5CPP_GUARD_NKohX
#define H5CPP_GUARD_NKohX
namespace h5{
//template specialization of sn::record_t to create HDF5 COMPOUND type
template<> hid_t inline register_struct<sn::record_t>(){
hsize_t at_00_[] ={5}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_00_);
hsize_t at_01_[] ={5}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_);
hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::record_t));
H5Tinsert(ct_00, "A", HOFFSET(sn::record_t,A),H5T_NATIVE_DOUBLE);
H5Tinsert(ct_00, "B", HOFFSET(sn::record_t,B),H5T_NATIVE_DOUBLE);
H5Tinsert(ct_00, "array_00", HOFFSET(sn::record_t,array_00),at_00);
H5Tinsert(ct_00, "array_01", HOFFSET(sn::record_t,array_01),at_01);
//closing all hid_t allocations to prevent resource leakage
H5Tclose(at_00); H5Tclose(at_01);
//if not used with h5cpp framework, but as a standalone code generator then
//the returned 'hid_t ct_00' must be closed: H5Tclose(ct_00);
return ct_00;
};
}
H5CPP_REGISTER_STRUCT(sn::record_t);
#endif
And here is the example dataset:
HDF5 "test.h5" {
GROUP "/" {
GROUP "path" {
DATASET "dataset" {
DATATYPE H5T_COMPOUND {
H5T_IEEE_F64LE "A";
H5T_IEEE_F64LE "B";
H5T_ARRAY { [5] H5T_IEEE_F64LE } "array_00";
H5T_ARRAY { [5] H5T_IEEE_F64LE } "array_01";
}
DATASPACE SIMPLE { ( 3 ) / ( H5S_UNLIMITED ) }
DATA {
(0): {
0,
0,
[ 1, 2, 3, 4, 5 ],
[ 11, 12, 13, 14, 15 ]
},
(1): {
1,
2,
[ 1, 2, 3, 4, 5 ],
[ 11, 12, 13, 14, 15 ]
},
(2): {
2,
4,
[ 1, 2, 3, 4, 5 ],
[ 11, 12, 13, 14, 15 ]
}
}
ATTRIBUTE "attribute" {
DATATYPE H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_UTF8;
CTYPE H5T_C_S1;
}
DATASPACE SIMPLE { ( 4 ) / ( 4 ) }
DATA {
(0): "first", "second", "...", "last"
}
}
}
}
}
}