boost_multi_array_2D.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/multi_array.hpp>
15 #include <highfive/H5File.hpp>
16 
17 using namespace HighFive;
18 
19 const std::string FILE_NAME("boost_multiarray_example.h5");
20 const std::string DATASET_NAME("dset");
21 const size_t size_x = 10;
22 const size_t size_y = 3;
23 
24 // Create a 2D dataset 10x3 of double with boost multi array
25 // and write it to a file
26 int main(void) {
27 
28  try {
29 
30  boost::multi_array<double, 2> my_array(boost::extents[size_x][size_y]);
31 
32  for (size_t i = 0; i < size_x; ++i) {
33  for (size_t j = 0; j < size_y; ++j) {
34  my_array[i][j] = double(j + i * size_y);
35  }
36  }
37 
38  // we create a new hdf5 file
40 
41  // let's create our dataset of the size of the boost::multi_array
42  DataSet dataset =
43  file.createDataSet<double>(DATASET_NAME, DataSpace::From(my_array));
44 
45  // we fill it
46  dataset.write(my_array);
47 
48  } catch (Exception& err) {
49  // catch and print any HDF5 error
50  std::cerr << err.what() << std::endl;
51  }
52 
53  return 0; // successfully terminated
54 }
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
static const int Truncate
Open flag: Truncate a file if already existing.
Definition: H5File.hpp:34
int main(void)
const std::string FILE_NAME("boost_multiarray_example.h5")
File class.
Definition: H5File.hpp:25
const char * what() const override
get the current exception error message
Definition: H5Exception.hpp:34
FILE * file
const size_t size_y
Basic HighFive Exception class.
Definition: H5Exception.hpp:23
const size_t size_x
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
const std::string DATASET_NAME("dset")


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