select_by_id_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_string.h5");
19 const std::string DATASET_NAME("message");
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  {
30  // We have a set of string
31  std::vector<std::string> values = {
32  "Cat", "Dog", "Hello", "Tree", "World", "Plane",
33  ", ", "你好", "Tea", "Moon", "صباح جميل", "Spaceship",
34  };
35 
36  // let's create a dataset
37  DataSet dataset = file.createDataSet<std::string>(
39 
40  // and write them
41  dataset.write(values);
42  }
43 
44  {
45  DataSet dataset = file.getDataSet(DATASET_NAME);
46 
47  // now let's read back by cherry pick our interesting string
48  std::vector<std::string> result;
49  // we select only element N° 2 and 5
50  dataset.select(ElementSet({2, 4, 6, 7, 6, 10})).read(result);
51 
52  // and display it
53  for (auto i : result) {
54  std::cout << i << " ";
55  }
56  std::cout << "\n";
57  }
58 
59  } catch (Exception& err) {
60  // catch and print any HDF5 error
61  std::cerr << err.what() << std::endl;
62  }
63 
64  return 0; // successfully terminated
65 }
H5File.hpp
main
int main(void)
Definition: select_by_id_dataset_cpp11.cpp:23
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
DATASET_NAME
const std::string DATASET_NAME("message")
H5DataSpace.hpp
HighFive::SliceTraits::select
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
Definition: H5Slice_traits_misc.hpp:66
HighFive::SliceTraits::write
void write(const T &buffer)
Definition: H5Slice_traits_misc.hpp:210
HighFive::ElementSet
Definition: H5Slice_traits.hpp:28
HighFive::File::Create
static const int Create
Open flag: Create non existing file.
Definition: H5File.hpp:40
scripts.create_png.values
values
Definition: create_png.py:26
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
FILE_NAME
const std::string FILE_NAME("select_partial_string.h5")
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


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