44 bool okay = hd.
open(
"should_not_exist.hdf");
53 hd.
create(
"test_simple_data.hdf");
70 std::complex<float> cf(2.3, 3.4);
79 hd3.
create(
"test_simple_data.hdf");
82 hd3.
write(f,
"float");
83 hd3.
write(d,
"double");
90 hd2.
open(
"test_simple_data.hdf");
112 std::complex<float> cf2;
127 hd4.
open(
"test_simple_data.hdf");
129 hd4.
read(b4,
"bool");
138 hd4.
read(d4,
"double");
142 hd4.
read(f4,
"float");
145 std::complex<float> cf4;
146 hd4.
read(cf4,
"complex float");
150 std::vector<int> datashape;
153 REQUIRE(datashape.size() == 0);
155 okay = hd4.
getShape<std::complex<float>>(
"complex float", datashape);
157 REQUIRE(datashape.size() == 0);
161 REQUIRE(datashape.size() == 1);
170 hd.
create(
"test_stl.hdf");
180 const vector<double> v_const(v);
193 for (
int i = 0; i < v.size(); i++)
194 CHECK(v[i] == v2[i]);
196 vector<double> v2_for_const;
198 REQUIRE(v2_for_const.size() == 3);
199 for (
int i = 0; i < v_const.size(); i++)
200 CHECK(v_const[i] == v2_for_const[i]);
206 hd.
create(
"test_group.hdf");
228 REQUIRE_THROWS(hd.
push(
"group"));
231 hd2.
open(
"test_group.hdf");
232 bool int_is_group = hd2.is_group(
"int");
233 REQUIRE(int_is_group ==
false);
235 bool name1_is_group = hd2.is_group(
"name1");
239 okay = hd2.readEntry(j2,
"name1/int2");
244 hd2.push(
"name1",
false);
245 okay = hd2.readEntry(j3,
"int2");
249 REQUIRE_THROWS(hd2.push(
"nonexistent_group",
false));
257 hd.
create(
"test_scalar_convert.hdf");
270 hd2.
open(
"test_scalar_convert.hdf");
287 hd.
create(
"test_tiny_vector.hdf");
292 v_cplx[0] = v[0] = 1.2;
293 v_cplx[1] = v[1] = 1.3;
303 hd2.
open(
"test_tiny_vector.hdf");
311 for (
int i = 0; i < v.
size(); i++)
314 REQUIRE(v_cplx[i] == v2_cplx[i]);
321 hd.
create(
"test_tensor.hdf");
336 hd2.
open(
"test_tensor.hdf");
341 for (
int i = 0; i < 2; i++)
343 for (
int j = 0; j < 2; j++)
353 hd.
create(
"test_string.hdf");
355 string s(
"this is a test");
360 std::ostringstream o;
361 o <<
"Another test" << std::endl;
384 hd.
create(
"test_string_vector.hdf");
386 std::vector<std::string> strings;
387 strings.push_back(
"first");
390 strings.push_back(
"really long string");
398 okay = hd2.
open(
"test_string_vector.hdf");
401 std::vector<std::string> strings2;
406 REQUIRE(strings2[0] ==
"first");
407 REQUIRE(strings2[1] ==
"really long string");
410 TEST_CASE(
"hdf_archive_dataset_existence_checking",
"[hdf]")
413 hd.
create(
"test_dataset_existence_checking.hdf");
415 std::vector<uint64_t> numbers;
416 numbers.push_back(123456);
417 std::string ds_tag =
"numbers_vector";
425 okay = hd2.
open(
"test_dataset_existence_checking.hdf");
435 hd.
create(
"test_dataset_type_checking.hdf");
437 std::vector<uint64_t> numbers;
438 numbers.push_back(123456);
439 std::string ds_tag =
"numbers_vector";
447 okay = hd2.
open(
"test_dataset_type_checking.hdf");
453 REQUIRE(is_correct_type ==
false);
454 REQUIRE_THROWS_AS(hd2.
is_dataset_of_type<uint64_t>(
"tag_doesnt_exist"), std::runtime_error);
460 hd.
create(
"test_vec_bool.hdf");
462 std::vector<bool> v(3,
false);
468 const std::vector<bool> v_const(v);
475 okay = hd2.
open(
"test_vec_bool.hdf");
478 std::vector<bool> v2;
481 for (
int i = 0; i < v.size(); i++)
482 CHECK(v[i] == v2[i]);
484 std::vector<bool> v2_for_const;
486 REQUIRE(v2_for_const.size() == 3);
487 for (
int i = 0; i < v_const.size(); i++)
488 CHECK(v_const[i] == v2_for_const[i]);
void write(T &data, const std::string &aname)
write the data to the group aname and check status runtime error is issued on I/O error ...
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
helper functions for EinsplineSetBuilder
TEST_CASE("complex_helper", "[type_traits]")
void close()
close all the open groups and file
bool is_dataset_of_type(const std::string &aname)
check if aname is a dataset of type T
bool getShape(const std::string &aname, std::vector< int > &sizes_out)
read the shape of multidimensional filespace from the group aname this function can be used to query ...
Tensor<T,D> class for D by D tensor.
REQUIRE(std::filesystem::exists(filename))
bool is_dataset(const std::string &aname)
check if aname is a dataset
void push(const std::string &gname, bool createit=true)
push a group to the group stack
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
std::string group_path_as_string() const
Return a string representation of the current group stack.
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
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 ...
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...