-
Notifications
You must be signed in to change notification settings - Fork 31
/
hdfdata.cpp
43 lines (37 loc) · 1.16 KB
/
hdfdata.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* This example shows you how to write simulation data out using HdfData
*
* Author: Seb James
* Date: September 2021
*/
#include <morph/HdfData.h>
#include <vector>
#include <deque>
#include <iostream>
#include <morph/vvec.h>
int main()
{
// Write data into the file test.h5
std::vector<double> vd = { 10.0, 12.0, 13.0, 14.0 };
{
morph::HdfData data("test.h5"); // Default file access is FileAccess::TruncateWrite
data.add_contained_vals ("/testvectordouble", vd);
} // data closes when out of scope
// Read data from test.h5 into the container vdread.
std::deque<double> vdread;
{
morph::HdfData data("test.h5", morph::FileAccess::ReadOnly);
data.read_contained_vals ("/testvectordouble", vdread);
}
for (auto d : vdread) {
std::cout << "Read the number " << d << " from test.h5...\n";
}
// Create a file containing a sequence of floating point numbers
{
morph::HdfData dseq("dseq.h5");
morph::vvec<float> theseq (256, 0.0f);
for (int i = 0; i < 256; i++) { theseq[i] = 1.0f * i; }
dseq.add_contained_vals ("/theseq", theseq);
}
return 0;
}