Added test for compound type in HDF5

This commit is contained in:
Guilhem Lavaux 2015-01-31 15:52:20 +01:00
parent 44756de2a9
commit 39fe5f5f7a

View File

@ -45,17 +45,30 @@ struct MyStruct
char c;
};
struct MyStruct2
{
MyStruct base;
int d;
};
CTOOL_STRUCT_TYPE(MyStruct, hdf5t_MyStruct,
((int, a))
((double, b))
((char, c))
)
CTOOL_STRUCT_TYPE(MyStruct2, hdf5t_MyStruct2,
((MyStruct, base))
((int, d))
)
int main()
{
typedef boost::multi_array<float, 2> array_type;
typedef boost::multi_array<float, 3> array3_type;
typedef boost::multi_array<MyStruct, 1> array_mys_type;
typedef boost::multi_array<MyStruct2, 1> array_mys2_type;
typedef boost::multi_array<std::complex<double>, 2> arrayc_type;
typedef array_type::index index;
@ -68,6 +81,7 @@ int main()
array3_type C(boost::extents[2][3][4]);
arrayc_type D, E;
array_mys_type F(boost::extents[10]), G;
array_mys2_type H(boost::extents[10]);
int values = 0;
for (index i = 0; i != 2; i++)
@ -79,11 +93,14 @@ int main()
F[i].a = i;
F[i].b = double(i)/4.;
F[i].c = 'r'+i;
H[i].base = F[i];
H[i].d = 2*i;
}
std::cout << " c = " << ((char *)&F[1])[offsetof(MyStruct, c)] << endl;
CosmoTool::hdf5_write_array(g, "test_data", A);
CosmoTool::hdf5_write_array(g, "test_struct", F);
CosmoTool::hdf5_write_array(g, "test_struct2", H);
CosmoTool::hdf5_read_array(g, "test_data", B);