HDF5 boost multi array transparent support
This commit is contained in:
parent
1d59f4e93d
commit
47255ea25a
3 changed files with 243 additions and 0 deletions
|
@ -34,6 +34,9 @@ target_link_libraries(testPool ${tolink})
|
|||
if (HDF5_FOUND)
|
||||
add_executable(testReadFlash testReadFlash.cpp)
|
||||
target_link_libraries(testReadFlash ${tolink})
|
||||
|
||||
add_executable(testHDF5 testHDF5.cpp)
|
||||
target_link_libraries(testHDF5 ${tolink})
|
||||
endif (HDF5_FOUND)
|
||||
|
||||
|
||||
|
|
65
sample/testHDF5.cpp
Normal file
65
sample/testHDF5.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include <iostream>
|
||||
#include <H5Cpp.h>
|
||||
#include "hdf5_array.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
typedef boost::multi_array<float, 2> array_type;
|
||||
typedef boost::multi_array<float, 3> array3_type;
|
||||
typedef boost::multi_array<std::complex<double>, 2> arrayc_type;
|
||||
typedef array_type::index index;
|
||||
|
||||
H5::H5File f("test.h5", H5F_ACC_TRUNC);
|
||||
|
||||
H5::Group g = f.createGroup("test_group");
|
||||
|
||||
array_type A(boost::extents[2][3]);
|
||||
array_type B;
|
||||
array3_type C(boost::extents[2][3][4]);
|
||||
arrayc_type D, E;
|
||||
|
||||
int values = 0;
|
||||
for (index i = 0; i != 2; i++)
|
||||
for (index j = 0; j != 3; j++)
|
||||
A[i][j] = values++;
|
||||
|
||||
CosmoTool::hdf5_write_array(g, "test_data", A);
|
||||
|
||||
CosmoTool::hdf5_read_array(g, "test_data", B);
|
||||
|
||||
int verify = 0;
|
||||
for (index i = 0; i != 2; i++)
|
||||
for (index j = 0; j != 3; j++)
|
||||
if (B[i][j] != verify++) {
|
||||
std::cout << "Invalid array content" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CosmoTool::hdf5_read_array(g, "test_data", C);
|
||||
std::cout << "Did not throw InvalidDimensions" << endl;
|
||||
abort();
|
||||
}
|
||||
catch (const CosmoTool::InvalidDimensions&)
|
||||
{}
|
||||
|
||||
D.resize(boost::extents[2][3]);
|
||||
D = A;
|
||||
|
||||
CosmoTool::hdf5_write_array(g, "test_data_c", D);
|
||||
|
||||
CosmoTool::hdf5_read_array(g, "test_data_c", E);
|
||||
|
||||
verify = 0;
|
||||
for (index i = 0; i != 2; i++)
|
||||
for (index j = 0; j != 3; j++)
|
||||
if (E[i][j].real() != verify++) {
|
||||
std::cout << "Invalid array content" << endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue