select_partial_dataset_cpp11.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 <functional>
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 
14 #include <highfive/H5File.hpp>
15 #include <highfive/H5DataSet.hpp>
16 #include <highfive/H5DataSpace.hpp>
17 
18 const std::string FILE_NAME("select_partial_example.h5");
19 const std::string DATASET_NAME("dset");
20 
21 // Create a dataset name "dset" of double 4x6
22 //
23 int main(void) {
24  using namespace HighFive;
25  try {
26  // Create a new file using the default property lists.
28 
29  // we have some example values in a 2D vector 2x5
30  std::vector<std::vector<double>> values = {
31  {1.0, 2.0, 4.0, 8.0, 16.0}, {32.0, 64.0, 128.0, 256.0, 512.0}};
32 
33  // let's create a dataset of this size
34  DataSet dataset =
35  file.createDataSet<double>(DATASET_NAME, DataSpace::From(values));
36  // and write them
37  dataset.write(values);
38 
39  // now we read back 2x2 values after an offset of 0x2
40  std::vector<std::vector<double>> result;
41  dataset.select({0, 2}, {2, 2}).read(result);
42 
43  // we print out 4 values
44  for (auto i : result) {
45  for (auto j : i) {
46  std::cout << " " << j;
47  }
48  std::cout << "\n";
49  }
50 
51  } catch (Exception& err) {
52  // catch and print any HDF5 error
53  std::cerr << err.what() << std::endl;
54  }
55 
56  return 0; // successfully terminated
57 }
const std::string DATASET_NAME("dset")
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
const std::string FILE_NAME("select_partial_example.h5")
File class.
Definition: H5File.hpp:25
const char * what() const override
get the current exception error message
Definition: H5Exception.hpp:34
int main(void)
FILE * file
Selection select(const std::vector< size_t > &offset, const std::vector< size_t > &count, const std::vector< size_t > &stride=std::vector< size_t >()) const
Basic HighFive Exception class.
Definition: H5Exception.hpp:23
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