read_write_single_scalar.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c), 2017, Adrien Devresse
3  *
4  * Distributed under the Boost Software License, Version 1.0.
5  * (See accompanying file LICENSE_1_0.txt or copy at
6  * http://www.boost.org/LICENSE_1_0.txt)
7  *
8  */
9 #include <iostream>
10 #include <string>
11 #include <vector>
12 
13 #include <highfive/H5File.hpp>
14 #include <highfive/H5DataSet.hpp>
15 #include <highfive/H5DataSpace.hpp>
16 
17 const std::string FILE_NAME("read_write_scalar.h5");
18 const std::string DATASET_NAME("single_scalar");
19 
20 // Create a dataset name "single_scalar"
21 // which contains only the perfect integer number "42"
22 //
23 int main(void) {
24  using namespace HighFive;
25  try {
26  // Create a new file using the default property lists.
28 
29  int perfect_number = 42;
30 
31  // Create the dataset
32  DataSet dataset = file.createDataSet<double>(
33  DATASET_NAME, DataSpace::From(perfect_number));
34 
35  // write it
36  dataset.write(perfect_number);
37 
38  // flush everything
39  file.flush();
40 
41  // let's read it back
42  int potentially_perfect_number;
43 
44  dataset.read(potentially_perfect_number);
45 
46  std::cout << "perfect number: " << potentially_perfect_number
47  << std::endl;
48 
49  } catch (Exception& err) {
50  // catch and print any HDF5 error
51  std::cerr << err.what() << std::endl;
52  }
53 
54  return 0; // successfully terminated
55 }
void read(T &array) const
void flush()
flush
Definition: H5File_misc.hpp:83
static DataSpace From(const ScalarValue &scalar_value)
const std::string FILE_NAME("read_write_scalar.h5")
void write(const T &buffer)
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
File class.
Definition: H5File.hpp:25
const std::string DATASET_NAME("single_scalar")
const char * what() const override
get the current exception error message
Definition: H5Exception.hpp:34
FILE * file
Basic HighFive Exception class.
Definition: H5Exception.hpp:23
int main(void)
DataSet createDataSet(const std::string &dataset_name, const DataSpace &space, const DataType &type, const DataSetCreateProps &createProps=DataSetCreateProps(), const DataSetAccessProps &accessProps=DataSetAccessProps())
createDataSet Create a new dataset in the current file of datatype type and of size space ...
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:09