-
Notifications
You must be signed in to change notification settings - Fork 163
/
select_partial_dataset_cpp11.cpp
49 lines (40 loc) · 1.39 KB
/
select_partial_dataset_cpp11.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
44
45
46
47
48
49
/*
* Copyright (c), 2017, Adrien Devresse
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
*/
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#include <highfive/highfive.hpp>
const std::string file_name("select_partial_example.h5");
const std::string dataset_name("dset");
// Create a dataset name "dset" of double 4x6
//
int main(void) {
using namespace HighFive;
// Create a new file using the default property lists.
File file(file_name, File::ReadWrite | File::Create | File::Truncate);
// we have some example values in a 2D vector 2x5
std::vector<std::vector<double>> values = {{1.0, 2.0, 4.0, 8.0, 16.0},
{32.0, 64.0, 128.0, 256.0, 512.0}};
// let's create a dataset of this size
DataSet dataset = file.createDataSet<double>(dataset_name, DataSpace::From(values));
// and write them
dataset.write(values);
// now we read back 2x2 values after an offset of 0x2
std::vector<std::vector<double>> result;
dataset.select({0, 2}, {2, 2}).read(result);
// we print out 4 values
for (auto i: result) {
for (auto j: i) {
std::cout << " " << j;
}
std::cout << "\n";
}
return 0; // successfully terminated
}