boost_ublas_double.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 
11 #undef H5_USE_BOOST
12 #define H5_USE_BOOST
13 
14 #include <boost/numeric/ublas/io.hpp>
15 #include <boost/numeric/ublas/matrix.hpp>
16 #include <highfive/H5File.hpp>
17 
18 using namespace HighFive;
19 
20 const std::string FILE_NAME("boost_ublas_double.h5");
21 const std::string DATASET_NAME("dset");
22 
23 const size_t size_x = 10;
24 const size_t size_y = 10;
25 
26 int main(void) {
27 
28  try {
29  typedef typename boost::numeric::ublas::matrix<double> Matrix;
30 
31  // create a 10x10 matrix
32  Matrix mat(size_x, size_y);
33 
34  // fill it
35  for (std::size_t i = 0; i < size_x; ++i) {
36  mat(i, i) = i;
37  }
38 
39  // Create a new HDF5 file
41 
42  // create a new dataset with the 10x10 Matrix dimension
43  DataSet dataset =
44  file.createDataSet<double>(DATASET_NAME, DataSpace::From(mat));
45 
46  // write it
47  dataset.write(mat);
48 
49  // now, let read it back
50  Matrix result;
51  dataset.read(result);
52 
53  // print what we read
54  std::cout << "Matrix result:\n" << result << std::endl;
55 
56  } catch (Exception& err) {
57  // catch and print any HDF5 error
58  std::cerr << err.what() << std::endl;
59  }
60 
61  return 0; // successfully terminated
62 }
const size_t size_x
void read(T &array) const
const size_t size_y
static DataSpace From(const ScalarValue &scalar_value)
void write(const T &buffer)
static const int ReadWrite
Open flag: Read Write access.
Definition: H5File.hpp:32
int main(void)
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
const std::string FILE_NAME("boost_ublas_double.h5")
File class.
Definition: H5File.hpp:25
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
const std::string DATASET_NAME("dset")
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:06