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 }
H5File.hpp
DATASET_NAME
const std::string DATASET_NAME("single_scalar")
HighFive::SliceTraits::read
void read(T &array) const
Definition: H5Slice_traits_misc.hpp:149
HighFive::DataSpace::From
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:130
H5DataSet.hpp
H5DataSpace.hpp
HighFive::SliceTraits::write
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:210
HighFive::File::Create
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40
HighFive::File
File class.
Definition: H5File.hpp:25
file
FILE * file
Definition: arithmeticencoder.cpp:77
HighFive::Exception::what
const char * what() const override
get the current exception error message
Definition: H5Exception.hpp:34
FILE_NAME
const std::string FILE_NAME("read_write_scalar.h5")
HighFive::Exception
Basic HighFive Exception class.
Definition: H5Exception.hpp:23
HighFive::File::ReadWrite
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
main
int main(void)
Definition: read_write_single_scalar.cpp:23
HighFive::DataSet
Definition: H5DataSet.hpp:27
HighFive::File::Truncate
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
HighFive
Definition: H5Annotate_traits.hpp:14


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 Wed Mar 2 2022 00:37:24