Please, help us to better know about our user community by answering the following short survey: https://www.hdfgroup.org/website-survey/
HDF5  1.8.23
C-API Reference

Files

Creating an HDF5 File User Block

Problem
You would like to include certain ancillary, non-HDF5 content in an HDF5 file such that it can be accessed without the HDF5 library.
Solution
Use a file creation property list in which the user block size is set via H5Pset_userblock(). In the example below, we create an 8 MiB user block.
44 {
45 __label__ fail_fcpl, fail_file;
46 hid_t fcpl, file;
47
48 if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0) {
49 ret_val = EXIT_FAILURE;
50 goto fail_fcpl;
51 }
52 if (H5Pset_userblock(fcpl, 8192 * 1024) < 0) {
53 ret_val = EXIT_FAILURE;
54 goto fail_file;
55 }
56 if ((file = H5Fcreate("userblock.h5", H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0) {
57 ret_val = EXIT_FAILURE;
58 goto fail_file;
59 }
60 H5Fclose(file);
61
62fail_file:
63 H5Pclose(fcpl);
64fail_fcpl:;
65 }
#define H5F_ACC_TRUNC
Definition: H5Fpublic.h:90
int hid_t
Definition: H5Ipublic.h:60
#define H5P_FILE_CREATE
Definition: H5Ppublic.h:214
#define H5P_DEFAULT
Definition: H5Ppublic.h:255
herr_t H5Pset_userblock(hid_t plist_id, hsize_t size)
Sets user block size.
herr_t H5Pclose(hid_t plist_id)
Terminates access to a property list.
hid_t H5Pcreate(hid_t cls_id)
Creates a new property list as an instance of a property list class.
herr_t H5Fclose(hid_t file_id)
Terminates access to an HDF5 file.
hid_t H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
Creates an HDF5 file.
Discussion
The user block begins at offset 0 and must be at least 512 bytes and a power of 2. The HDF5 library ignores any content between the beginning of the file and the end of the user block.
You can add or strip a user block to/from an existing HDF5 file with the h5jam/h5unjam tool, respectively.
Warning
If you try to embed content into the user block for use by other applications, pay close attention to how they handle space beyond the last used byte in the user block or the user block in general. In the worst case, applications might try to truncate the rest of the file and destroy the HDF5 portion of the file.
See Also
References to related recipes