blob: bf6167e5a4396a63a93cf0d90433b52013d67210 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include <cassert>
#include <string>
#include <hdf5.h>
#include "cctk.h"
#include "file.hh"
namespace CarpetIOF5 {
namespace F5 {
file_t::
file_t (cGH const * const cctkGH,
string const filename,
bool const do_truncate)
: m_cctkGH (cctkGH),
m_filename (filename)
{
assert (cctkGH);
char const * const filenameptr = filename.c_str();
htri_t is_hdf5;
H5E_BEGIN_TRY {
is_hdf5 = H5Fis_hdf5 (filenameptr);
} H5E_END_TRY;
bool const file_exists = is_hdf5 > 0;
if (do_truncate or not file_exists)
{
m_hdf5_file
= H5Fcreate (filenameptr, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
}
else
{
m_hdf5_file = H5Fopen (filenameptr, H5F_ACC_RDWR, H5P_DEFAULT);
}
assert (invariant());
}
file_t::
~ file_t()
{
herr_t const herr = H5Fclose (m_hdf5_file);
assert (not herr);
}
cGH const * file_t::
get_cctkGH ()
const
{
return m_cctkGH;
}
hid_t file_t::
get_hdf5_file()
const
{
return m_hdf5_file;
}
bool file_t::
invariant()
const
{
return (m_cctkGH != 0
and m_hdf5_file >= 0);
}
} // namespace F5
} // namespace CarpetIOF5
|