-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_ex4_hdf5.cpp
36 lines (29 loc) · 1001 Bytes
/
read_ex4_hdf5.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
// read_ex4_hdf5.cpp
#include <iostream>
#include <vector>
#include "H5Cpp.h"
using namespace H5;
#include "PhastH5File.h"
int main (void)
{
PhastH5File file("ex4.h5", H5F_ACC_RDONLY);
std::vector<std::string> steps = file.getTimeSteps();
std::vector<std::string> scalars = file.getScalars();
file.getActiveArray(0);
std::vector< std::string > cs = { "/Grid/X", "/Grid/Y" , "/Grid/Z" };
std::vector< std::vector<double> > coords;
for (size_t i = 0; i < cs.size(); ++i) {
DataSet dataset = file.openDataSet(cs[i]);
DataSpace dataspace = dataset.getSpace();
hsize_t dims[2], maxdims[2];
int ndims = dataspace.getSimpleExtentDims(dims, maxdims);
std::vector<double> coord(dims[0], 0.0);
dataset.read(coord.data(), PredType::NATIVE_DOUBLE);
std::cout << cs[i] << std::endl;
for (auto c : coord) {
std::cout << c << std::endl;
}
coords.push_back(coord);
}
file.close();
}