summaryrefslogtreecommitdiffstats
path: root/doxygen/examples/H5_examples.c
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2021-09-07 21:08:41 (GMT)
committerGitHub <noreply@github.com>2021-09-07 21:08:41 (GMT)
commitd0507c23f30fc1ff66ae4a31d41f681612e51851 (patch)
tree18032d7c438334900adf45d22659b70cee072215 /doxygen/examples/H5_examples.c
parentf5709db18e10993de3bc4668ad07b66d14279877 (diff)
downloadhdf5-d0507c23f30fc1ff66ae4a31d41f681612e51851.zip
hdf5-d0507c23f30fc1ff66ae4a31d41f681612e51851.tar.gz
hdf5-d0507c23f30fc1ff66ae4a31d41f681612e51851.tar.bz2
1.12 Merge A batch of life-cycle examples for different modules #654 (#987)
* Merge A batch of life-cycle examples for different modules #654 * Remove generated file * Change doxygen generated file location
Diffstat (limited to 'doxygen/examples/H5_examples.c')
-rw-r--r--doxygen/examples/H5_examples.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/doxygen/examples/H5_examples.c b/doxygen/examples/H5_examples.c
new file mode 100644
index 0000000..ef52ed0
--- /dev/null
+++ b/doxygen/examples/H5_examples.c
@@ -0,0 +1,85 @@
+/* -*- c-file-style: "stroustrup" -*- */
+
+#include "hdf5.h"
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+//! <!-- [closing_shop] -->
+void
+closing_shop(void *ctx)
+{
+ printf("GoodBye, Cruel World!\n");
+}
+//! <!-- [closing_shop] -->
+
+int
+main(void)
+{
+ int ret_val = EXIT_SUCCESS;
+
+ //! <!-- [create] -->
+ {
+ // an HDF5 library instance is automatically initialized as
+ // part of the first HDF5 API call, but there's no harm in
+ // calling H5open().
+ if (H5open() < 0) {
+ ret_val = EXIT_FAILURE;
+ }
+ }
+ //! <!-- [create] -->
+
+ //! <!-- [read] -->
+ {
+ __label__ fail_read;
+ unsigned majnum, minnum, relnum;
+ hbool_t flag;
+
+ // retrieve the library version
+ if (H5get_libversion(&majnum, &minnum, &relnum) < 0) {
+ ret_val = EXIT_FAILURE;
+ goto fail_read;
+ }
+ // is this a thread-safe library build?
+ if (H5is_library_threadsafe(&flag) < 0) {
+ ret_val = EXIT_FAILURE;
+ goto fail_read;
+ }
+
+ printf("Welcome to HDF5 %d.%d.%d\n", majnum, minnum, relnum);
+ printf("Thread-safety %s\n", (flag > 0) ? "enabled" : "disabled");
+
+fail_read:;
+ }
+ //! <!-- [read] -->
+
+ //! <!-- [update] -->
+ {
+ // update the library instance free list limits
+ if (H5set_free_list_limits(512 * 1024, 32 * 1024, 2048 * 1024, 128 * 1024, 8192 * 1024, 512 * 1024) <
+ 0) {
+ ret_val = EXIT_FAILURE;
+ }
+ }
+ //! <!-- [update] -->
+
+ //! <!-- [delete] -->
+ {
+#if H5_VERSION_GE(1, 13, 0)
+ // install a finalization routine
+ if (H5atclose(&closing_shop, NULL) < 0) {
+ ret_val = EXIT_FAILURE;
+ }
+#endif
+ // close shop
+ if (H5close() < 0) {
+ ret_val = EXIT_FAILURE;
+ }
+ }
+ //! <!-- [delete] -->
+
+ assert(ret_val == EXIT_SUCCESS);
+
+ return ret_val;
+}