forked from BlueBrain/HighFive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_write_single_scalar.cpp
More file actions
55 lines (43 loc) · 1.43 KB
/
Copy pathread_write_single_scalar.cpp
File metadata and controls
55 lines (43 loc) · 1.43 KB
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
50
51
52
53
54
55
/*
* 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 <iostream>
#include <string>
#include <vector>
#include <highfive/H5File.hpp>
#include <highfive/H5DataSet.hpp>
#include <highfive/H5DataSpace.hpp>
const std::string FILE_NAME("read_write_scalar.h5");
const std::string DATASET_NAME("single_scalar");
// Create a dataset name "single_scalar"
// which contains only the perfect integer number "42"
//
int main(void) {
using namespace HighFive;
try {
// Create a new file using the default property lists.
File file(FILE_NAME, File::ReadWrite | File::Create | File::Truncate);
int perfect_number = 42;
// Create the dataset
DataSet dataset = file.createDataSet<double>(
DATASET_NAME, DataSpace::From(perfect_number));
// write it
dataset.write(perfect_number);
// flush everything
file.flush();
// let's read it back
int potentially_perfect_number;
dataset.read(potentially_perfect_number);
std::cout << "perfect number: " << potentially_perfect_number
<< std::endl;
} catch (Exception& err) {
// catch and print any HDF5 error
std::cerr << err.what() << std::endl;
}
return 0; // successfully terminated
}