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 }
size_x
const size_t size_x
Definition: boost_multi_array_2D.cpp:21
main
int main(void)
Definition: boost_multi_array_2D.cpp:26
H5File.hpp
HighFive::DataSpace::From
static DataSpace From(const ScalarValue &scalar_value)
Definition: H5Dataspace_misc.hpp:130
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
FILE_NAME
const std::string FILE_NAME("boost_multiarray_example.h5")
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
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
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
DATASET_NAME
const std::string DATASET_NAME("dset")
size_y
const size_t size_y
Definition: boost_multi_array_2D.cpp:22


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:22