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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <string>
#include <cstdlib>
#include "H5CppDoc.h" // included only for Doxygen to generate part of RM
#include "H5Include.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
#include "H5FaccProp.h"
#include "H5FcreatProp.h"
#include "H5OcreatProp.h"
#include "H5DxferProp.h"
#include "H5Object.h"
#include "H5DataType.h"
#include "H5DcreatProp.h"
#include "H5AtomType.h"
#include "H5PredType.h"
#include "H5DataSpace.h"
#include "H5Library.h"
#ifndef H5_NO_NAMESPACE
namespace H5 {
#endif
#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This static variable is unused, will be removed in future releases.
bool H5Library::need_cleanup = false;
#endif // DOXYGEN_SHOULD_SKIP_THIS
//--------------------------------------------------------------------------
// Function: H5Library::open (static)
///\brief Initializes the HDF5 library.
///
///\exception H5::LibraryIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void H5Library::open()
{
herr_t ret_value = H5open();
if( ret_value < 0 )
{
throw LibraryIException("H5Library::open", "H5open failed");
}
}
//--------------------------------------------------------------------------
// Function: H5Library::close (static)
///\brief Flushes all data to disk, closes files, and cleans up memory.
///
///\exception H5::LibraryIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void H5Library::close()
{
herr_t ret_value = H5close();
if( ret_value < 0 )
{
throw LibraryIException("H5Library::close", "H5close failed");
}
}
//--------------------------------------------------------------------------
// Function: H5Library::dontAtExit (static)
///\brief Instructs library not to install the C \c atexit cleanup routine
///
///\exception H5::LibraryIException
// Programmer Binh-Minh Ribler - 2000
// Modification
// Removed the check for failure returned from H5dont_atexit.
// will be fixed to not fail (HDFFV-9540)
//--------------------------------------------------------------------------
void H5Library::dontAtExit()
{
herr_t ret_value = H5dont_atexit();
}
//--------------------------------------------------------------------------
// Function: H5Library::getLibVersion (static)
///\brief Returns the HDF library release number.
///\param majnum - OUT: Major version of the library
///\param minnum - OUT: Minor version of the library
///\param relnum - OUT: Release number of the library
///\exception H5::LibraryIException
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void H5Library::getLibVersion( unsigned& majnum, unsigned& minnum, unsigned& relnum )
{
herr_t ret_value = H5get_libversion( &majnum, &minnum, &relnum );
if( ret_value < 0 )
{
throw LibraryIException("H5Library::getLibVersion", "H5get_libversion failed");
}
}
//--------------------------------------------------------------------------
// Function: H5Library::checkVersion (static)
///\brief Verifies that the arguments match the version numbers
/// compiled into the library
///\param majnum - IN: Major version of the library
///\param minnum - IN: Minor version of the library
///\param relnum - IN: Release number of the library
///\exception H5::LibraryIException
///\par Description
/// For information about library version, please refer to
/// the C layer Reference Manual at:
/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5.html#Library-VersCheck
// Programmer Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
void H5Library::checkVersion(unsigned majnum, unsigned minnum, unsigned relnum)
{
herr_t ret_value = H5check_version(majnum, minnum, relnum);
if( ret_value < 0 )
{
throw LibraryIException("H5Library::checkVersion", "H5check_version failed");
}
}
//--------------------------------------------------------------------------
// Function: H5Library::garbageCollect (static)
///\brief Walks through all the garbage collection routines for the
/// library, which are supposed to free any unused memory they
/// have allocated.
///
///\exception H5::LibraryIException
///\par Description
/// It is not required that H5Library::garbageCollect be called
/// at any particular time; it is only necessary in certain
/// situations, such as when the application has performed actions
/// that cause the library to allocate many objects. The
/// application should call H5Library::garbageCollect if it
/// eventually releases those objects and wants to reduce the
/// memory used by the library from the peak usage required.
///\par
/// The library automatically garbage collects all the free
/// lists when the application ends.
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
void H5Library::garbageCollect()
{
herr_t ret_value = H5garbage_collect();
if( ret_value < 0 )
{
throw LibraryIException("H5Library::garbageCollect", "H5garbage_collect failed");
}
}
//--------------------------------------------------------------------------
// Function: H5Library::initH5cpp (static)
///\brief Initializes C++ library and registers terminating functions at
/// exit. Only for the library functions, not for user-defined
/// functions.
// Description
// initH5cpp registers the following functions with std::atexit():
// termH5cpp() - calls H5close() after all cleanup in
// the C++ library is done
// <classname>::deleteConstants - deletes all references
// for <classname> global constants
///\exception H5::LibraryIException
//
// Programmer Binh-Minh Ribler - September, 2015
//--------------------------------------------------------------------------
void H5Library::initH5cpp()
{
// Register terminating functions with atexit(); they will be invoked in
// the reversed order
int ret_value = 0;
ret_value = std::atexit(termH5cpp);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating termH5cpp failed");
ret_value = std::atexit(PredType::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating PredType::deleteConstants failed");
ret_value = std::atexit(PropList::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating PropList::deleteConstants failed");
ret_value = std::atexit(FileAccPropList::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating FileAccPropList::deleteConstants failed");
ret_value = std::atexit(FileCreatPropList::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating FileCreatPropList::deleteConstants failed");
ret_value = std::atexit(DSetMemXferPropList::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating DSetMemXferPropList::deleteConstants failed");
ret_value = std::atexit(DSetCreatPropList::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating DSetCreatPropList::deleteConstants failed");
ret_value = std::atexit(ObjCreatPropList::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating ObjCreatPropList::deleteConstants failed");
ret_value = std::atexit(DataSpace::deleteConstants);
if (ret_value != 0)
throw LibraryIException("H5Library::initH5cpp", "Registrating DataSpace::deleteConstants failed");
}
//--------------------------------------------------------------------------
// Function: H5Library::termH5cpp (static)
///\brief Sends request for the C layer to terminate.
///\par Description
/// If the C library fails to terminate, exit with a failure.
// Programmer Binh-Minh Ribler - September, 2015
//--------------------------------------------------------------------------
void H5Library::termH5cpp()
{
// Close the C library
herr_t ret_value = H5close();
if (ret_value == -1)
exit(-1);
}
//--------------------------------------------------------------------------
// Function: H5Library::setFreeListLimits (static)
///\brief Sets limits on the different kinds of free lists.
///\param reg_global_lim - IN: Limit on all "regular" free list memory used
///\param reg_list_lim - IN: Limit on memory used in each "regular" free list
///\param arr_global_lim - IN: Limit on all "array" free list memory used
///\param arr_list_lim - IN: Limit on memory used in each "array" free list
///\param blk_global_lim - IN: Limit on all "block" free list memory used
///\param blk_list_lim - IN: Limit on memory used in each "block" free list
///\exception H5::LibraryIException
///\par Description
/// Setting a value of -1 for a limit means no limit of that type.
/// For more information on free list limits, please refer to C
/// layer Reference Manual at:
/// http://www.hdfgroup.org/HDF5/doc/RM/RM_H5.html#Library-SetFreeListLimits
// Programmer Binh-Minh Ribler - May, 2004
//--------------------------------------------------------------------------
void H5Library::setFreeListLimits(int reg_global_lim, int reg_list_lim,
int arr_global_lim, int arr_list_lim, int blk_global_lim,
int blk_list_lim)
{
herr_t ret_value = H5set_free_list_limits(reg_global_lim, reg_list_lim, arr_global_lim, arr_list_lim, blk_global_lim, blk_list_lim);
if( ret_value < 0 )
{
throw LibraryIException("H5Library::setFreeListLimits", "H5set_free_list_limits failed");
}
}
// Default constructor - private
H5Library::H5Library(){};
// Destructor - private
H5Library::~H5Library(){};
#ifndef H5_NO_NAMESPACE
} // end namespace
#endif
|