QMCPACK
test_hdf_multiarray.cpp
Go to the documentation of this file.
1 
2 //////////////////////////////////////////////////////////////////////////////////////
3 // This file is distributed under the University of Illinois/NCSA Open Source License.
4 // See LICENSE file in top directory for details.
5 //
6 // Copyright (c) 2018 Jeongnim Kim and QMCPACK developers.
7 //
8 // File developed by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
9 //
10 // File created by: Mark Dewing, mdewing@anl.gov, Argonne National Laboratory
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #include "catch.hpp"
15 
16 #include "boost/version.hpp"
17 #include <vector>
18 #include "multi/array.hpp"
19 #include "hdf/hdf_archive.h"
20 #include "hdf/hdf_multi.h"
21 
22 
23 using std::vector;
24 
25 using namespace qmcplusplus;
26 
27 template<std::ptrdiff_t D>
28 using extensions = typename boost::multi::layout_t<D>::extensions_type;
29 
30 TEST_CASE("hdf_multiarray_one_dim", "[hdf]")
31 {
32  hdf_archive hd;
33  hd.create("test_stl.hdf");
34 
35  boost::multi::array<double, 1> v(extensions<1u>{3});
36  v[0] = 2.3;
37  v[1] = -100.3;
38  v[2] = 135.22;
39 
40  bool okay = hd.writeEntry(v, "boost_multiarray_one_dim");
41  REQUIRE(okay);
42 
43  hd.close();
44 
45  hdf_archive hd2;
46  okay = hd2.open("test_stl.hdf");
47  REQUIRE(okay);
48 
49  boost::multi::array<double, 1> v2(extensions<1u>{3});
50  hd2.read(v2, "boost_multiarray_one_dim");
51  REQUIRE(v2.size() == 3);
52  for (int i = 0; i < v.size(); i++)
53  {
54  REQUIRE(v[i] == v2[i]);
55  }
56 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
TEST_CASE("complex_helper", "[type_traits]")
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
typename boost::multi::layout_t< D >::extensions_type extensions
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244