create_dataset_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 #include <string>
11 #include <vector>
12 
13 #include <highfive/H5DataSet.hpp>
14 #include <highfive/H5DataSpace.hpp>
15 #include <highfive/H5File.hpp>
16 
17 const std::string FILE_NAME("create_dataset_example.h5");
18 const std::string DATASET_NAME("dset");
19 
20 // Create a dataset name "dset" of double 4x6
21 //
22 int main(void) {
23  using namespace HighFive;
24  try {
25  // Create a new file using the default property lists.
27 
28  // Define the size of our dataset: 2x6
29  std::vector<size_t> dims(2);
30  dims[0] = 2;
31  dims[1] = 6;
32 
33  // Create the dataset
34  DataSet dataset =
35  file.createDataSet<double>(DATASET_NAME, DataSpace(dims));
36 
37  double data[2][6] = {{1.1, 2.2, 3.3, 4.4, 5.5, 6.6},
38  {11.11, 12.12, 13.13, 14.14, 15.15, 16.16}};
39 
40  // write it
41  dataset.write(data);
42 
43  } catch (Exception& err) {
44  // catch and print any HDF5 error
45  std::cerr << err.what() << std::endl;
46  }
47 
48  return 0; // successfully terminated
49 }
const std::string FILE_NAME("create_dataset_example.h5")
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
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