diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2021-05-04 22:46:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-04 22:46:10 (GMT) |
commit | 021d7c7278fd9c182802f2d5419438716beb37bc (patch) | |
tree | 772b610158e3c771e575a5d7095ebfa589480240 /doxygen/examples/H5A_examples.c | |
parent | 0801e83615713d95174ed936462310cea32328c7 (diff) | |
download | hdf5-021d7c7278fd9c182802f2d5419438716beb37bc.zip hdf5-021d7c7278fd9c182802f2d5419438716beb37bc.tar.gz hdf5-021d7c7278fd9c182802f2d5419438716beb37bc.tar.bz2 |
Hdf5 1 12 doxygen merge (#615)
* OESS-98 fix tools test for plugins
* sync fork
* Merge of changes from dev
* Move problem option to bottom of the list until fixed
* HDFFV-11106 - fix parsing optional args
* HDFFV-11106 add note
* grammer fix
* Whitespace after clang formatting
* Undo format version 11 changes
* Update check to working version
* Merge workflow and minor changes from develop
* Update supported platforms
* PR#3 merge from develop
* Merge gcc 10 diagnostics option from develop
* Merge #318 OSX changes from develop
* Merge serval small changes from dev
* fix typo
* Minor non-space formatting changes
* GH #386 copyright corrections for java folder
* revert because logic requires false return
* Merges from develop
#358 patches from vtk
#361 fix header guard spelling
* Remove case statement for H5I_EVENTSET
* Correct call with versioning
* Remove tabs
* Double underscore change
* Merges from develop
#340 clang -Wformat-security warnings
#360 Fixed uninitialized warnings
Remove more underscores from header guards
* Merge #380 from develop
* Correct date entry
* Split format source and commit changes on repo push
* remove pre-split setting
* Change windows TS to use older VS.
* HDFFV-11212 JNI export util and Javadoc
* Suggested review changes
* Another change found
* Committing clang-format changes
* Some Javadoc warning fixes
* Committing clang-format changes
* Updated javadoc fixes
* HDFFV-11228/9 merges from develop
* remove obsolete debug comment
* Fix conflict
* HDFFV-11229 merge changes from develop
* HDFFV-11229 merge second compare from develop
* HDFFV-11229 fix reference file
* HDFFV-11229 update autotools test script for two ref files
* HDFFV-11229 merge dev changes for long double display in tools
* Committing clang-format changes
* Update with changes from develop
* Add "option" command for clang options
* Rework CMake add_custom to use the BYPRODUCTS argument
Update pkgconfig scripts for parallel builds.
Fix install COPYING file reference.
Remove unused round defines.
Change CMake default setting of BUILD_CPP to off.
* Whitespace changes
* Rework CMake add_custom to use the BYPRODUCTS argument
* Revert CMake configure checks for round defines
* With VS 2015 minimum strdup is supported
* Doxygen comments merged from develop
* doxygen build updates
* Correct version string for map functions
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Diffstat (limited to 'doxygen/examples/H5A_examples.c')
-rw-r--r-- | doxygen/examples/H5A_examples.c | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/doxygen/examples/H5A_examples.c b/doxygen/examples/H5A_examples.c new file mode 100644 index 0000000..f332efa --- /dev/null +++ b/doxygen/examples/H5A_examples.c @@ -0,0 +1,145 @@ +/* -*- c-file-style: "stroustrup" -*- */ + +#include "hdf5.h" + +#include <stdio.h> +#include <stdlib.h> + +int +main(void) +{ + int ret_val = EXIT_SUCCESS; + + //! <!-- [create] --> + { + __label__ fail_acpl, fail_attr, fail_file; + hid_t file, acpl, fspace, attr; + + unsigned mode = H5F_ACC_TRUNC; + char file_name[] = "f1.h5"; + // attribute names can be arbitrary Unicode strings + char attr_name[] = "Χαρακτηριστικό"; + + if ((file = H5Fcreate(file_name, mode, H5P_DEFAULT, H5P_DEFAULT)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_file; + } + if ((acpl = H5Pcreate(H5P_ATTRIBUTE_CREATE)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_acpl; + } + // use UTF-8 encoding for the attribute name + if (H5Pset_char_encoding(acpl, H5T_CSET_UTF8) < 0) { + ret_val = EXIT_FAILURE; + goto fail_fspace; + } + // create a scalar (singleton) attribute + if ((fspace = H5Screate(H5S_SCALAR)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_fspace; + } + // create an attribute on the root group + if ((attr = H5Acreate2(file, attr_name, H5T_STD_I32LE, fspace, acpl, H5P_DEFAULT)) == + H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_attr; + } + + H5Aclose(attr); +fail_attr: + H5Sclose(fspace); +fail_fspace: + H5Pclose(acpl); +fail_acpl: + H5Fclose(file); +fail_file:; + } + //! <!-- [create] --> + + //! <!-- [read] --> + { + __label__ fail_attr, fail_file; + hid_t file, attr; + + unsigned mode = H5F_ACC_RDONLY; + char file_name[] = "f1.h5"; + char attr_name[] = "Χαρακτηριστικό"; + int value; + + if ((file = H5Fopen(file_name, mode, H5P_DEFAULT)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_file; + } + if ((attr = H5Aopen(file, attr_name, H5P_DEFAULT)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_attr; + } + // read the attribute value + if (H5Aread(attr, H5T_NATIVE_INT, &value) < 0) + ret_val = EXIT_FAILURE; + + // do something w/ the attribute value + + H5Aclose(attr); +fail_attr: + H5Fclose(file); +fail_file:; + } + //! <!-- [read] --> + + //! <!-- [update] --> + { + __label__ fail_attr, fail_file; + hid_t file, attr; + + unsigned mode = H5F_ACC_RDWR; + char file_name[] = "f1.h5"; + char attr_name[] = "Χαρακτηριστικό"; + int value = 1234; + + if ((file = H5Fopen(file_name, mode, H5P_DEFAULT)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_file; + } + if ((attr = H5Aopen(file, attr_name, H5P_DEFAULT)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_attr; + } + // update the attribute value + if (H5Awrite(attr, H5T_NATIVE_INT, &value) < 0) + ret_val = EXIT_FAILURE; + + H5Aclose(attr); +fail_attr: + H5Fclose(file); +fail_file:; + } + //! <!-- [update] --> + + //! <!-- [delete] --> + { + __label__ fail_attr, fail_file; + hid_t file; + + unsigned mode = H5F_ACC_RDWR; + char file_name[] = "f1.h5"; + char attr_name[] = "Χαρακτηριστικό"; + + if ((file = H5Fopen(file_name, mode, H5P_DEFAULT)) == H5I_INVALID_HID) { + ret_val = EXIT_FAILURE; + goto fail_file; + } + // delete the attribute + if (H5Adelete(file, attr_name) < 0) { + ret_val = EXIT_FAILURE; + goto fail_attr; + } + +fail_attr: + H5Fclose(file); +fail_file:; + } + //! <!-- [delete] --> + + return ret_val; +} |