summaryrefslogtreecommitdiffstats
path: root/doxygen/examples
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2021-10-22 15:03:51 (GMT)
committerGitHub <noreply@github.com>2021-10-22 15:03:51 (GMT)
commit223b3765293852c94b84e5b40c7585ecc5021eaa (patch)
tree177ff342ca25f489311a3d84bfcb0a8cb5a105b5 /doxygen/examples
parente5e108dbd56fc1b871915d3de64fe85a6fc9b175 (diff)
downloadhdf5-223b3765293852c94b84e5b40c7585ecc5021eaa.zip
hdf5-223b3765293852c94b84e5b40c7585ecc5021eaa.tar.gz
hdf5-223b3765293852c94b84e5b40c7585ecc5021eaa.tar.bz2
1.8 Merge cmake and flag changes from develop (#1119)
* Merge cmake and flag changes from develop * Committing clang-format changes Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'doxygen/examples')
-rw-r--r--doxygen/examples/H5D_examples.c1
-rw-r--r--doxygen/examples/H5F_examples.c42
-rw-r--r--doxygen/examples/H5_examples.c79
3 files changed, 114 insertions, 8 deletions
diff --git a/doxygen/examples/H5D_examples.c b/doxygen/examples/H5D_examples.c
index aad057d..dfc3ece 100644
--- a/doxygen/examples/H5D_examples.c
+++ b/doxygen/examples/H5D_examples.c
@@ -166,7 +166,6 @@ fail_delete:
H5Fclose(file);
fail_file:;
}
-
//! <!-- [delete] -->
return ret_val;
diff --git a/doxygen/examples/H5F_examples.c b/doxygen/examples/H5F_examples.c
index a7ce6fb..0ca0cd8 100644
--- a/doxygen/examples/H5F_examples.c
+++ b/doxygen/examples/H5F_examples.c
@@ -10,7 +10,7 @@ main(void)
{
int ret_val = EXIT_SUCCESS;
- //! <!-- [life_cycle] -->
+ //! <!-- [create] -->
{
__label__ fail_fapl, fail_fcpl, fail_file;
hid_t fcpl, fapl, file;
@@ -48,12 +48,13 @@ fail_fapl:
H5Pclose(fcpl);
fail_fcpl:;
}
- //! <!-- [life_cycle] -->
+ //! <!-- [create] -->
- //! <!-- [life_cycle_w_open] -->
+ //! <!-- [read] -->
{
__label__ fail_fapl, fail_file;
- hid_t fapl, file;
+ hid_t fapl, file;
+ hsize_t size;
if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) == H5I_INVALID_HID) {
ret_val = EXIT_FAILURE;
@@ -63,7 +64,7 @@ fail_fcpl:;
// adjust the file access properties
}
- unsigned mode = H5F_ACC_RDWR;
+ unsigned mode = H5F_ACC_RDONLY;
char name[] = "f1.h5";
if ((file = H5Fopen(name, mode, fapl)) == H5I_INVALID_HID) {
@@ -71,14 +72,41 @@ fail_fcpl:;
goto fail_file;
}
- // do something useful with FILE
+ if (H5Fget_filesize(file, &size) < 0) {
+ ret_val = EXIT_FAILURE;
+ }
+
+ printf("File size: %llu bytes\n", size);
H5Fclose(file);
fail_file:
H5Pclose(fapl);
fail_fapl:;
}
- //! <!-- [life_cycle_w_open] -->
+ //! <!-- [read] -->
+
+ //! <!-- [update] -->
+ {
+ __label__ fail_file;
+ hid_t file;
+
+ unsigned mode = H5F_ACC_RDWR;
+ char name[] = "f1.h5";
+
+ if ((file = H5Fopen(name, mode, H5P_DEFAULT)) == H5I_INVALID_HID) {
+ ret_val = EXIT_FAILURE;
+ goto fail_file;
+ }
+
+ // create a cycle by hard linking the root group in the root group
+ if (H5Lcreate_hard(file, ".", file, "loopback", H5P_DEFAULT, H5P_DEFAULT) < 0) {
+ ret_val = EXIT_FAILURE;
+ }
+
+ H5Fclose(file);
+fail_file:;
+ }
+ //! <!-- [update] -->
//! <!-- [minimal] -->
{
diff --git a/doxygen/examples/H5_examples.c b/doxygen/examples/H5_examples.c
new file mode 100644
index 0000000..426da8b
--- /dev/null
+++ b/doxygen/examples/H5_examples.c
@@ -0,0 +1,79 @@
+/* -*- 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] -->
+ {
+ // close shop
+ if (H5close() < 0) {
+ ret_val = EXIT_FAILURE;
+ }
+ }
+ //! <!-- [delete] -->
+
+ assert(ret_val == EXIT_SUCCESS);
+
+ return ret_val;
+}