Please, help us to better serve our user community by answering the following short survey: https://www.hdfgroup.org/website-survey/
HDF5 2.0.0.258fa78
API Reference
Loading...
Searching...
No Matches
Files (H5F)

Detailed Description

Use the functions in this module to manage HDF5 files.

In the code snippets below, we show the skeletal life cycle of an HDF5 file, when creating a new file (left) or when opening an existing file (right). File creation is essentially controlled through File Creation Properties, and file access to new and existing files is controlled through File Access Properties. The file name and creation or access mode control the interaction with the underlying storage such as file systems.

CreateRead
14 {
15 __label__ fail_fapl, fail_fcpl, fail_file;
16 hid_t fcpl, fapl, file;
17
18 if ((fcpl = H5Pcreate(H5P_FILE_CREATE)) == H5I_INVALID_HID) {
19 ret_val = EXIT_FAILURE;
20 goto fail_fcpl;
21 }
22 else {
23 // adjust the file creation properties
24 }
25
26 if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) == H5I_INVALID_HID) {
27 ret_val = EXIT_FAILURE;
28 goto fail_fapl;
29 }
30 else {
31 // adjust the file access properties
32 }
33
34 unsigned mode = H5F_ACC_EXCL;
35 char name[] = "f1.h5";
36
37 if ((file = H5Fcreate(name, mode, fcpl, fapl)) == H5I_INVALID_HID) {
38 ret_val = EXIT_FAILURE;
39 goto fail_file;
40 }
41
42 // do something useful with FILE
43
44 H5Fclose(file);
45fail_file:
46 H5Pclose(fapl);
47fail_fapl:
48 H5Pclose(fcpl);
49fail_fcpl:;
50 }
#define H5F_ACC_EXCL
Definition H5Fpublic.h:31
int64_t hid_t
Definition H5Ipublic.h:60
#define H5I_INVALID_HID
Definition H5Ipublic.h:75
#define H5P_FILE_CREATE
Definition H5Ppublic.h:52
#define H5P_FILE_ACCESS
Definition H5Ppublic.h:56
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.
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.
54 {
55 __label__ fail_fapl, fail_file;
56 hid_t fapl, file;
57 hsize_t size;
58
59 if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) == H5I_INVALID_HID) {
60 ret_val = EXIT_FAILURE;
61 goto fail_fapl;
62 }
63 else {
64 // adjust the file access properties
65 }
66
67 unsigned mode = H5F_ACC_RDONLY;
68 char name[] = "f1.h5";
69
70 if ((file = H5Fopen(name, mode, fapl)) == H5I_INVALID_HID) {
71 ret_val = EXIT_FAILURE;
72 goto fail_file;
73 }
74
75 if (H5Fget_filesize(file, &size) < 0) {
76 ret_val = EXIT_FAILURE;
77 }
78
79 printf("File size: %llu bytes\n", size);
80
81 H5Fclose(file);
82fail_file:
83 H5Pclose(fapl);
84fail_fapl:;
85 }
#define H5F_ACC_RDONLY
Definition H5Fpublic.h:28
uint64_t hsize_t
Definition H5public.h:301
herr_t H5Fget_filesize(hid_t file_id, hsize_t *size)
Returns the size of an HDF5 file (in bytes)
hid_t H5Fopen(const char *filename, unsigned flags, hid_t fapl_id)
Opens an existing HDF5 file.
UpdateDelete
89 {
90 __label__ fail_file;
91 hid_t file;
92
93 unsigned mode = H5F_ACC_RDWR;
94 char name[] = "f1.h5";
95
96 if ((file = H5Fopen(name, mode, H5P_DEFAULT)) == H5I_INVALID_HID) {
97 ret_val = EXIT_FAILURE;
98 goto fail_file;
99 }
100
101 // create a cycle by hard linking the root group in the root group
102 if (H5Lcreate_hard(file, ".", file, "loopback", H5P_DEFAULT, H5P_DEFAULT) < 0) {
103 ret_val = EXIT_FAILURE;
104 }
105
106 H5Fclose(file);
107fail_file:;
108 }
#define H5F_ACC_RDWR
Definition H5Fpublic.h:29
#define H5P_DEFAULT
Definition H5Ppublic.h:220
herr_t H5Lcreate_hard(hid_t cur_loc, const char *cur_name, hid_t dst_loc, const char *dst_name, hid_t lcpl_id, hid_t lapl_id)
Creates a hard link to an object.
215 {
216#if H5_VERSION_GE(1, 12, 0)
217
218 // this function is only available in HDF5 1.12.x
219 if (H5Fdelete("f1.h5", H5P_DEFAULT) < 0) {
220 ret_val = EXIT_FAILURE;
221 }
222
223#endif
224 }
herr_t H5Fdelete(const char *filename, hid_t fapl_id)
Deletes an HDF5 file.

In addition to general file management functions, there are three categories of functions that deal with advanced file management tasks and use cases:

  1. The control of the HDF5 Metadata Cache
  2. The use of (MPI-) Parallel HDF5
  3. The Introduction to Single-Writer/Multiple-Reader (SWMR) pattern

Modules

 Metadata Cache
 
 Parallel
 
 Single Writer Multiple Readers
 

Macros

#define H5Fget_info   H5Fget_info2
 

Functions

htri_t H5Fis_accessible (const char *container_name, hid_t fapl_id)
 Checks if a file can be opened with a given file access property list.
 
hid_t H5Fcreate (const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
 Creates an HDF5 file.
 
hid_t H5Fopen (const char *filename, unsigned flags, hid_t fapl_id)
 Opens an existing HDF5 file.
 
hid_t H5Freopen (hid_t file_id)
 Returns a new identifier for a previously-opened HDF5 file.
 
herr_t H5Fflush (hid_t object_id, H5F_scope_t scope)
 Flushes all buffers associated with a file to storage.
 
herr_t H5Fclose (hid_t file_id)
 Terminates access to an HDF5 file.
 
herr_t H5Fdelete (const char *filename, hid_t fapl_id)
 Deletes an HDF5 file.
 
hid_t H5Fget_create_plist (hid_t file_id)
 Returns a file creation property list identifier.
 
hid_t H5Fget_access_plist (hid_t file_id)
 Returns a file access property list identifier.
 
herr_t H5Fget_intent (hid_t file_id, unsigned *intent)
 Determines the read/write or read-only status of a file.
 
herr_t H5Fget_fileno (hid_t file_id, unsigned long *fileno)
 Retrieves a file's file number that uniquely identifies an open file.
 
ssize_t H5Fget_obj_count (hid_t file_id, unsigned types)
 Returns the number of open object identifiers for an open file.
 
ssize_t H5Fget_obj_ids (hid_t file_id, unsigned types, size_t max_objs, hid_t *obj_id_list)
 Returns a list of open object identifiers.
 
herr_t H5Fget_vfd_handle (hid_t file_id, hid_t fapl, void **file_handle)
 Returns pointer to the file handle from the virtual file driver.
 
herr_t H5Fmount (hid_t loc_id, const char *name, hid_t child, hid_t plist)
 Mounts an HDF5 file.
 
herr_t H5Funmount (hid_t loc_id, const char *name)
 Un-mounts an HDF5 file.
 
hssize_t H5Fget_freespace (hid_t file_id)
 Returns the amount of free space in a file (in bytes)
 
herr_t H5Fget_filesize (hid_t file_id, hsize_t *size)
 Returns the size of an HDF5 file (in bytes)
 
herr_t H5Fget_eoa (hid_t file_id, haddr_t *eoa)
 Retrieves the file's end-of-allocation (EOA)
 
herr_t H5Fincrement_filesize (hid_t file_id, hsize_t increment)
 Sets the file' EOA to the maximum of (EOA, EOF) + increment.
 
ssize_t H5Fget_file_image (hid_t file_id, void *buf_ptr, size_t buf_len)
 Retrieves a copy of the image of an existing, open file.
 
ssize_t H5Fget_name (hid_t obj_id, char *name, size_t size)
 Retrieves name of file to which object belongs.
 
herr_t H5Fget_info2 (hid_t obj_id, H5F_info2_t *file_info)
 Retrieves global file information.
 
ssize_t H5Fget_free_sections (hid_t file_id, H5F_mem_t type, size_t nsects, H5F_sect_info_t *sect_info)
 Retrieves free-space section information for a file.
 
herr_t H5Fclear_elink_file_cache (hid_t file_id)
 Clears the external link open file cache.
 
herr_t H5Fset_libver_bounds (hid_t file_id, H5F_libver_t low, H5F_libver_t high)
 Enables the switch of version bounds setting for a file.
 
herr_t H5Freset_page_buffering_stats (hid_t file_id)
 Resets the page buffer statistics.
 
herr_t H5Fget_page_buffering_stats (hid_t file_id, unsigned accesses[2], unsigned hits[2], unsigned misses[2], unsigned evictions[2], unsigned bypasses[2])
 Retrieves statistics about page access when it is enabled.
 
herr_t H5Fget_dset_no_attrs_hint (hid_t file_id, hbool_t *minimize)
 Retrieves the setting for whether or not a file will create minimized dataset object headers.
 
herr_t H5Fset_dset_no_attrs_hint (hid_t file_id, hbool_t minimize)
 Sets the flag to create minimized dataset object headers.
 
herr_t H5Fget_info1 (hid_t obj_id, H5F_info1_t *file_info)
 Retrieves global file information.
 
herr_t H5Fset_latest_format (hid_t file_id, hbool_t latest_format)
 Sets the latest version of the library to be used for writing objects.
 
htri_t H5Fis_hdf5 (const char *file_name)
 Determines whether a file is in the HDF5 format.
 

Macro Definition Documentation

◆ H5Fget_info

#define H5Fget_info   H5Fget_info2

H5Fget_info() is a macro that is mapped to either H5Fget_info1() or H5Fget_info2().

See also
API Compatibility Macros

Function Documentation

◆ H5Fclear_elink_file_cache()

herr_t H5Fclear_elink_file_cache ( hid_t  file_id)

Clears the external link open file cache.

Parameters
[in]file_idFile identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fclear_elink_file_cache() evicts all the cached child files in the specified file's external file cache, causing them to be closed if there is nothing else holding them open.

H5Fclear_elink_file_cache() does not close the cache itself; subsequent external link traversals from the parent file will again cache the target file. See H5Pset_elink_file_cache_size() for information on closing the file cache.

See also
H5Pset_elink_file_cache_size(), H5Pget_elink_file_cache_size()
Since
1.8.7

◆ H5Fclose()

herr_t H5Fclose ( hid_t  file_id)

Terminates access to an HDF5 file.

Parameters
[in]file_idFile identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fclose() terminates access to an HDF5 file (specified by file_id) by flushing all data to storage.

If this is the last file identifier open for the file and no other access identifier is open (e.g., a dataset identifier, group identifier, or shared datatype identifier), the file will be fully closed and access will end.

Example
{
unsigned mode = H5F_ACC_TRUNC;
char name[] = "f11.h5";
hid_t file = H5Fcreate(name, mode, H5P_DEFAULT, H5P_DEFAULT);
if (file != H5I_INVALID_HID)
H5Fclose(file);
else
ret_val = EXIT_FAILURE;
}
#define H5F_ACC_TRUNC
Definition H5Fpublic.h:30
Note
Delayed close: Note the following deviation from the above-described behavior. If H5Fclose() is called for a file, but one or more objects within the file remain open, those objects will remain accessible until they are individually closed. Thus, if the dataset data_sample is open when H5Fclose() is called for the file containing it, data_sample will remain open and accessible (including writable) until it is explicitly closed. The file will be automatically closed once all objects in the file have been closed.
Be warned, however, that there are circumstances where it is not possible to delay closing a file. For example, an MPI-IO file close is a collective call; all of the processes that open the file must close it collectively. The file cannot be closed at some time in the future by each process in an independent fashion. Another example is that an application using an AFS token-based file access privilege may destroy its AFS token after H5Fclose() has returned successfully. This would make any future access to the file, or any object within it, illegal.
In such situations, applications must close all open objects in a file before calling H5Fclose. It is generally recommended to do so in all cases.
Since
1.0.0
See also
H5Fopen()

◆ H5Fcreate()

hid_t H5Fcreate ( const char *  filename,
unsigned  flags,
hid_t  fcpl_id,
hid_t  fapl_id 
)

Creates an HDF5 file.

Parameters
[in]filenameName of the file to create
[in]flagsFile access flags. Allowable values are:
  • H5F_ACC_TRUNC: Truncate file, if it already exists, erasing all data previously stored in the file
  • H5F_ACC_EXCL: Fail if file already exists
[in]fcpl_idFile creation property list identifier
[in]fapl_idFile access property list identifier
Returns
Returns a file identifier if successful; otherwise returns H5I_INVALID_HID.

H5Fcreate() is the primary function for creating HDF5 files; it creates a new HDF5 file with the specified name and property lists.

The filename parameter specifies the name of the new file.

The flags parameter specifies whether an existing file is to be overwritten. It should be set to either H5F_ACC_TRUNC to overwrite an existing file or H5F_ACC_EXCL, instructing the function to fail if the file already exists.

New files are always created in read-write mode, so the read-write and read-only flags, H5F_ACC_RDWR and H5F_ACC_RDONLY, respectively, are not relevant in this function. Further note that a specification of H5F_ACC_RDONLY will be ignored; the file will be created in read-write mode, regardless.

More complex behaviors of file creation and access are controlled through the file creation and file access property lists, fcpl_id and fapl_id, respectively. The value of H5P_DEFAULT for any property list value indicates that the library should use the default values for that appropriate property list.

The return value is a file identifier for the newly-created file; this file identifier should be closed by calling H5Fclose() when it is no longer needed.

Example
{
unsigned mode = H5F_ACC_TRUNC;
char name[] = "f11.h5";
hid_t file = H5Fcreate(name, mode, H5P_DEFAULT, H5P_DEFAULT);
if (file != H5I_INVALID_HID)
H5Fclose(file);
else
ret_val = EXIT_FAILURE;
}
Note
H5F_ACC_TRUNC and H5F_ACC_EXCL are mutually exclusive; use exactly one.
An additional flag, H5F_ACC_DEBUG, prints debug information. This flag can be combined with one of the above values using the bit-wise OR operator (|), but it is used only by HDF5 library developers; it is neither tested nor supported for use in applications.
Attention
Special case — File creation in the case of an already-open file: If a file being created is already opened, by either a previous H5Fopen() or H5Fcreate() call, the HDF5 library may or may not detect that the open file and the new file are the same physical file. (See H5Fopen() regarding the limitations in detecting the re-opening of an already-open file.)
If the library detects that the file is already opened, H5Fcreate() will return a failure, regardless of the use of H5F_ACC_TRUNC.
If the library does not detect that the file is already opened and H5F_ACC_TRUNC is not used, H5Fcreate() will return a failure because the file already exists. Note that this is correct behavior.
But if the library does not detect that the file is already opened and H5F_ACC_TRUNC is used, H5Fcreate() will truncate the existing file and return a valid file identifier. Such a truncation of a currently-opened file will almost certainly result in errors. While unlikely, the HDF5 library may not be able to detect, and thus report, such errors.
Applications should avoid calling H5Fcreate() with an already opened file.
Since
1.0.0
See also
H5Fopen(), H5Fclose()

◆ H5Fdelete()

herr_t H5Fdelete ( const char *  filename,
hid_t  fapl_id 
)

Deletes an HDF5 file.

Parameters
[in]filenameName of the file to delete
[in]fapl_idFile access property list identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fdelete() deletes an HDF5 file filename with a file access property list fapl_id. The fapl_id should be configured with the same VOL connector or VFD that was used to open the file.

This API was introduced for use with the Virtual Object Layer (VOL). With the VOL, HDF5 "files" can map to arbitrary storage schemes such as object stores and relational database tables. The data created by these implementations may be inconvenient for a user to remove without a detailed knowledge of the storage scheme. H5Fdelete() gives VOL connector authors the ability to add connector-specific delete code to their connectors so that users can remove these "files" without detailed knowledge of the storage scheme.

For a VOL connector, H5Fdelete() deletes the file in a way that makes sense for the specified VOL connector.

For the native HDF5 connector, HDF5 files will be deleted via the VFDs, each of which will have to be modified to delete the files it creates.

For all implementations, H5Fdelete() will first check if the file is an HDF5 file via H5Fis_accessible(). This is done to ensure that H5Fdelete() cannot be used as an arbitrary file deletion call.

Since
1.12.0

◆ H5Fflush()

herr_t H5Fflush ( hid_t  object_id,
H5F_scope_t  scope 
)

Flushes all buffers associated with a file to storage.

Parameters
[in]object_idLocation identifier
[in]scopeThe scope of the flush action
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fflush() causes all buffers associated with a file to be immediately flushed to storage without removing the data from the cache.

object_id can be any object associated with the file, including the file itself, a dataset, a group, an attribute, or a named datatype.

scope specifies whether the scope of the flush action is global or local. Valid values are as follows:

H5F_SCOPE_GLOBALFlushes the entire virtual file
H5F_SCOPE_LOCALFlushes only the specified file
Example
{
unsigned mode = H5F_ACC_RDWR;
char name[] = "f11.h5";
hid_t file = H5Fopen(name, mode, H5P_DEFAULT);
if (file != H5I_INVALID_HID) {
int step;
for (step = 0; step < 1000; ++step) {
// do important work & flush every 20 steps
if (step % 20 == 0) {
if (H5Fflush(file, H5F_SCOPE_LOCAL) < 0) {
perror("H5Fflush failed.");
ret_val = EXIT_FAILURE;
break;
}
}
}
if (H5Fclose(file) < 0)
perror("H5Fclose failed.");
}
else
ret_val = EXIT_FAILURE;
}
@ H5F_SCOPE_LOCAL
Definition H5Fpublic.h:82
herr_t H5Fflush(hid_t object_id, H5F_scope_t scope)
Flushes all buffers associated with a file to storage.
Attention
HDF5 does not possess full control over buffering. H5Fflush() flushes the internal HDF5 buffers and then asks the operating system (the OS) to flush the system buffers for the open files. After that, the OS is responsible for ensuring that the data is actually flushed to disk.
Since
1.0.0

◆ H5Fget_access_plist()

hid_t H5Fget_access_plist ( hid_t  file_id)

Returns a file access property list identifier.

Parameters
[in]file_idFile identifier
Returns
Returns a file access property list identifier if successful; otherwise returns H5I_INVALID_HID.

H5Fget_access_plist() returns the file access property list identifier of the specified file.

Since
1.0.0

◆ H5Fget_create_plist()

hid_t H5Fget_create_plist ( hid_t  file_id)

Returns a file creation property list identifier.

Parameters
[in]file_idFile identifier
Returns
Returns a file creation property list identifier if successful; otherwise returns H5I_INVALID_HID.

H5Fget_create_plist() returns the file creation property list identifier identifying the creation properties used to create this file. This function is useful for duplicating properties when creating another file.

The creation property list identifier should be released with H5Pclose().

Since
1.0.0

◆ H5Fget_dset_no_attrs_hint()

herr_t H5Fget_dset_no_attrs_hint ( hid_t  file_id,
hbool_t minimize 
)

Retrieves the setting for whether or not a file will create minimized dataset object headers.

Parameters
[in]file_idFile identifier
[out]minimizeFlag indicating whether the library will or will not create minimized dataset object headers
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fget_dset_no_attrs_hint() retrieves the no dataset attributes hint setting for the file specified by the file identifier file_id. This setting is used to inform the library to create minimized dataset object headers when true.

The setting's value is returned in the boolean pointer minimized.

Since
1.10.5

◆ H5Fget_eoa()

herr_t H5Fget_eoa ( hid_t  file_id,
haddr_t eoa 
)

Retrieves the file's end-of-allocation (EOA)

Parameters
[in]file_idFile identifier
[out]eoaThe file's EOA
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fget_eoa() retrieves the file's EOA and returns it in the parameter eoa.

Since
1.10.2

◆ H5Fget_file_image()

ssize_t H5Fget_file_image ( hid_t  file_id,
void *  buf_ptr,
size_t  buf_len 
)

Retrieves a copy of the image of an existing, open file.

Parameters
[in]file_idFile identifier
[out]buf_ptrPointer to the buffer into which the image of the HDF5 file is to be copied. If buf_ptr is NULL, no data will be copied but the function's return value will still indicate the buffer size required (or a negative value on error).
[out]buf_lenSize of the supplied buffer
Returns
ssize_t

H5Fget_file_image() retrieves a copy of the image of an existing, open file. This routine can be used with files opened using the SEC2 (or POSIX), STDIO, and Core (or Memory) virtual file drivers (VFDs).

If the return value of H5Fget_file_image() is a positive value, it will be the length in bytes of the buffer required to store the file image. So if the file size is unknown, it can be safely determined with an initial H5Fget_file_image() call with buf_ptr set to NULL. The file image can then be retrieved with a second H5Fget_file_image() call with buf_len set to the initial call's return value.

While the current file size can also be retrieved with H5Fget_filesize(), that call may produce a larger value than is needed. The value returned by H5Fget_filesize() includes the user block, if it exists, and any unallocated space at the end of the file. It is safe in all situations to get the file size with H5Fget_file_image() and it often produces a value that is more appropriate for the size of a file image buffer.

Note
Recommended Reading: This function is part of the file image operations feature set. It is highly recommended to study the guide HDF5 File Image Operations before using this feature set.
Attention
H5Pget_file_image() will fail, returning a negative value, if the file is too large for the supplied buffer.
See also
H5LTopen_file_image(), H5Pset_file_image(), H5Pget_file_image(), H5Pset_file_image_callbacks(), H5Pget_file_image_callbacks()
Since
1.8.0

◆ H5Fget_fileno()

herr_t H5Fget_fileno ( hid_t  file_id,
unsigned long *  fileno 
)

Retrieves a file's file number that uniquely identifies an open file.

Parameters
[in]file_idFile identifier
[out]filenoA buffer to hold the file number
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fget_fileno() retrieves a file number for a file specified by the file identifier file_id and the pointer fnumber to the file number.

This file number is the same for all open instances of the same file, as long as 1. The active VFD implements the file comparison operator, and 2. The current filesystem is able to determine if the same file is opened more than once. If these conditions are not met, it is the application's responsibility to avoid opening multiple handles into the same file, which results in undefined behavior.

Since
1.12.0

◆ H5Fget_filesize()

herr_t H5Fget_filesize ( hid_t  file_id,
hsize_t size 
)

Returns the size of an HDF5 file (in bytes)

Parameters
[in]file_idFile identifier
[out]sizeSize of the file, in bytes
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fget_filesize() returns the size of the HDF5 file specified by file_id.

The returned size is that of the entire file, as opposed to only the HDF5 portion of the file. I.e., size includes the user block, if any, the HDF5 portion of the file, and any data that may have been appended beyond the data written through the HDF5 library.

Since
1.6.3

◆ H5Fget_free_sections()

ssize_t H5Fget_free_sections ( hid_t  file_id,
H5F_mem_t  type,
size_t  nsects,
H5F_sect_info_t sect_info 
)

Retrieves free-space section information for a file.

Parameters
[in]file_idFile identifier
[in]typeThe file memory allocation type
[in]nsectsThe number of free-space sections
[out]sect_infoArray of instances of H5F_sect_info_t in which the free-space section information is to be returned
Returns
Returns the number of free-space sections for the specified free-space manager in the file; otherwise returns a negative value.

H5Fget_free_sections() retrieves free-space section information for the free-space manager with type that is associated with file file_id. If type is H5FD_MEM_DEFAULT, this routine retrieves free-space section information for all the free-space managers in the file.

Valid values for type are the following:

H5FD_MEM_DEFAULTThe default file memory allocation type
H5FD_MEM_SUPERFile memory allocated for Superblock
H5FD_MEM_BTREEFile memory allocated for B-tree
H5FD_MEM_DRAWFile memory allocated for raw data
H5FD_MEM_GHEAPFile memory allocated for Global Heap
H5FD_MEM_LHEAPFile memory allocated for Local Heap
H5FD_MEM_OHDRFile memory allocated for Object Header

H5F_sect_info_t is defined as follows (in H5Fpublic.h):

typedef struct H5F_sect_info_t {
uint64_t haddr_t
Definition H5public.h:345
Definition H5Fpublic.h:155
haddr_t addr
Definition H5Fpublic.h:156
hsize_t size
Definition H5Fpublic.h:157

This routine retrieves free-space section information for nsects sections or, at most, the maximum number of sections in the specified free-space manager. If the number of sections is not known, a preliminary H5Fget_free_sections() call can be made by setting sect_info to NULL and the total number of free-space sections for the specified free-space manager will be returned. Users can then allocate space for entries in sect_info, each of which is defined as an H5F_sect_info_t struct.

Attention
Failure Modes: This routine will fail when the following is true:
  • The library fails to retrieve the file creation property list associated with file_id.
  • If the parameter sect_info is non-null, but the parameter nsects is equal to 0.
  • The library fails to retrieve free-space section information for the file.
Since
1.10.0

◆ H5Fget_freespace()

hssize_t H5Fget_freespace ( hid_t  file_id)

Returns the amount of free space in a file (in bytes)

Parameters
[in]file_idFile identifier
Returns
Returns the amount of free space in the file if successful; otherwise returns a negative value.

Given the identifier of an open file, file_id, H5Fget_freespace() returns the amount of space that is unused by any objects in the file.

The interpretation of this number depends on the configured free space management strategy. For example, if the HDF5 library only tracks free space in a file from a file open or create until that file is closed, then this routine will report the free space that has been created during that interval.

Since
1.6.1

◆ H5Fget_info1()

herr_t H5Fget_info1 ( hid_t  obj_id,
H5F_info1_t file_info 
)

Retrieves global file information.

Parameters
[in]obj_idObject identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[out]file_infoBuffer for global file information
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Deprecated:
This function has been renamed from H5Fget_info() and is deprecated in favor of the macro H5Fget_info or the function H5Fget_info2().

H5Fget_info1() returns global information for the file associated with the object identifier obj_id in the H5F_info1_t struct named file_info.

obj_id is an identifier for any object in the file of interest.

H5F_info1_t struct is defined in H5Fpublic.h as follows:

typedef struct H5F_info1_t {
struct {
} sohm;
Definition H5public.h:399
Definition H5Fpublic.h:1868
H5_ih_info_t msgs_info
Definition H5Fpublic.h:1872
hsize_t super_ext_size
Definition H5Fpublic.h:1869
struct H5F_info1_t::@3 sohm
hsize_t hdr_size
Definition H5Fpublic.h:1871

super_ext_size is the size of the superblock extension.

The sohm sub-struct contains shared object header message information as follows:

  • index_size is the summed size of all the shared object header indexes. Each index might be either a B-tree or a list.
Version
1.10.0 Function H5Fget_info() renamed to H5Fget_info1() and deprecated in this release.
Since
1.8.0

◆ H5Fget_info2()

herr_t H5Fget_info2 ( hid_t  obj_id,
H5F_info2_t file_info 
)

Retrieves global file information.

Parameters
[in]obj_idObject identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute.
[out]file_infoBuffer for global file information
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fget_info2() returns global information for the file associated with the object identifier obj_id in the H5F_info2_t struct named file_info.

obj_id is an identifier for any object in the file of interest.

H5F_info2_t struct is defined in H5Fpublic.h as follows:

typedef struct H5F_info2_t {
struct {
unsigned version;
} super;
struct {
unsigned version;
} free;
struct {
unsigned version;
} sohm;
Definition H5Fpublic.h:105
unsigned version
Definition H5Fpublic.h:107
hsize_t super_size
Definition H5Fpublic.h:108
struct H5F_info2_t::@2 sohm
H5_ih_info_t msgs_info
Definition H5Fpublic.h:119
hsize_t super_ext_size
Definition H5Fpublic.h:109
hsize_t hdr_size
Definition H5Fpublic.h:118
struct H5F_info2_t::@1 free
hsize_t tot_space
Definition H5Fpublic.h:114
hsize_t meta_size
Definition H5Fpublic.h:113
struct H5F_info2_t::@0 super

The super sub-struct contains the following information:

  • vers is the version number of the superblock.
  • super_size is the size of the superblock.
  • super_ext_size is the size of the superblock extension.

The free sub-struct contains the following information:

  • vers is the version number of the free-space manager.
  • hdr_size is the size of the free-space manager header.
  • tot_space is the total amount of free space in the file.

The sohm sub-struct contains shared object header message information as follows:

  • vers is the version number of the shared object header information.
  • hdr_size is the size of the shared object header message.
  • msgs_info is an H5_ih_info_t struct defined in H5public.h as follows:
  • index_size is the summed size of all the shared object header indexes. Each index might be either a B-tree or a list.
  • heap_size is the size of the heap.
Since
1.10.0

◆ H5Fget_intent()

herr_t H5Fget_intent ( hid_t  file_id,
unsigned *  intent 
)

Determines the read/write or read-only status of a file.

Parameters
[in]file_idFile identifier
[out]intentAccess mode flag as originally passed with H5Fopen()
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

Given the identifier of an open file, file_id, H5Fget_intent() retrieves the intended access mode" flag passed with H5Fopen() when the file was opened.

The value of the flag is returned in intent. Valid values are as follows:

H5F_ACC_RDWRFile was opened with read/write access.
H5F_ACC_RDONLYFile was opened with read-only access.
H5F_ACC_SWMR_WRITEFile was opened with read/write access for a single-writer/multiple-reader (SWMR) scenario. Note that the writer process must also open the file with the H5F_ACC_RDWR flag.
H5F_ACC_SWMR_READFile was opened with read-only access for a single-writer/multiple-reader (SWMR) scenario. Note that the reader process must also open the file with the H5F_ACC_RDONLY flag.
Note
The function will not return an error if intent is NULL; it will simply do nothing.
Version
1.10.0 Function enhanced to work with SWMR functionality.
Since
1.8.0

◆ H5Fget_name()

ssize_t H5Fget_name ( hid_t  obj_id,
char *  name,
size_t  size 
)

Retrieves name of file to which object belongs.

Parameters
[in]obj_idObject identifier
[out]nameBuffer for the file name
[in]sizeThe size, in bytes, of the name buffer. Must be the size of the file name in bytes plus 1 for a NULL terminator
Returns
Returns the length of the file name if successful; otherwise returns a negative value.

H5Fget_name() retrieves the name of the file to which the object obj_id belongs. The object can be a file, group, dataset, attribute, or named datatype.

Up to size characters of the file name are returned in name; additional characters, if any, are not returned to the user application.

Up to size characters of the file name are returned in name; additional characters, if any, are not returned to the user application.

If the length of the file name, which determines the required value of size, is unknown, a preliminary call to H5Fget_name() with the last two parameters set to NULL and zero respectively can be made. The return value of this call will be the size in bytes of the file name. That value, plus 1 for a NULL terminator, must then be assigned to size for a second H5Fget_name() call, which will retrieve the actual file name.

If an error occurs, the buffer pointed to by name is unchanged and the function returns a negative value.

Since
1.6.3

◆ H5Fget_obj_count()

ssize_t H5Fget_obj_count ( hid_t  file_id,
unsigned  types 
)

Returns the number of open object identifiers for an open file.

Parameters
[in]file_idFile identifier or H5F_OBJ_ALL for all currently-open HDF5 files
[in]typesType of object for which identifiers are to be returned
Returns
Returns the number of open objects if successful; otherwise returns a negative value.

Given the identifier of an open file, file_id, and the desired object types, types, H5Fget_obj_count() returns the number of open object identifiers for the file.

To retrieve a count of open identifiers for open objects in all HDF5 application files that are currently open, as well as transient datatype objects that are not associated with any file, pass the value H5F_OBJ_ALL in file_id.

The types of objects to be counted are specified in types as follows:

H5F_OBJ_FILEFiles only
H5F_OBJ_DATASETDatasets only
H5F_OBJ_GROUPGroups only
H5F_OBJ_DATATYPEDatatypes only. If file_id is H5F_OBJ_ALL, this will count committed and transient datatypes. Otherwise, it will only count committed datatypes.
H5F_OBJ_ATTRAttributes only
H5F_OBJ_ALLAll of the above
H5F_OBJ_LOCALRestrict search to objects opened through current file identifier.
Attention
H5F_OBJ_LOCAL does not stand alone; it is effective only when used in combination with one or more of the preceding types. For example, H5F_OBJ_DATASET | H5F_OBJ_GROUP | H5F_OBJ_LOCAL would count all datasets and groups opened through the current file identifier.

Multiple object types can be combined with the logical OR operator (|). For example, the expression (H5F_OBJ_DATASET|H5F_OBJ_GROUP) would call for datasets and groups.

Version
1.6.8, 1.8.2 Function return type changed to ssize_t.
1.6.5 H5F_OBJ_LOCAL has been added as a qualifier on the types of objects to be counted. H5F_OBJ_LOCAL restricts the search to objects opened through current file identifier.
Since
1.6.0

◆ H5Fget_obj_ids()

ssize_t H5Fget_obj_ids ( hid_t  file_id,
unsigned  types,
size_t  max_objs,
hid_t obj_id_list 
)

Returns a list of open object identifiers.


Parameters
[in]file_idFile identifier or H5F_OBJ_ALL for all currently-open HDF5 files
[in]typesType of object for which identifiers are to be returned
[in]max_objsMaximum number of object identifiers to place into obj_id_list
[out]obj_id_listPointer to the returned buffer of open object identifiers
Returns
Returns number of objects placed into obj_id_list if successful; otherwise returns a negative value.

Given the file identifier file_id and the type of objects to be identified, types, H5Fget_obj_ids() returns the list of identifiers for all open HDF5 objects fitting the specified criteria.

To retrieve identifiers for open objects in all HDF5 application files that are currently open, pass the value H5F_OBJ_ALL in file_id.

The types of object identifiers to be retrieved are specified in types using the codes listed for the same parameter in H5Fget_obj_count().

To retrieve a count of open objects, use the H5Fget_obj_count() function. This count can be used to set the max_objs parameter.

Version
1.8.2 Function return type changed to ssize_t and max_objs parameter datatype changed to size_t.
1.6.8 Function return type changed to ssize_t and max_objs parameter datatype changed to size_t.
Since
1.6.0

◆ H5Fget_page_buffering_stats()

herr_t H5Fget_page_buffering_stats ( hid_t  file_id,
unsigned  accesses[2],
unsigned  hits[2],
unsigned  misses[2],
unsigned  evictions[2],
unsigned  bypasses[2] 
)

Retrieves statistics about page access when it is enabled.

Parameters
[in]file_idFile identifier
[out]accessesTwo integer array for the number of metadata and raw data accesses to the page buffer
[out]hitsTwo integer array for the number of metadata and raw data hits in the page buffer
[out]missesTwo integer array for the number of metadata and raw data misses in the page buffer
[out]evictionsTwo integer array for the number of metadata and raw data evictions from the page buffer
[out]bypassesTwo integer array for the number of metadata and raw data accesses that bypass the page buffer
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fget_page_buffering_stats() retrieves page buffering statistics such as the number of metadata and raw data accesses (accesses), hits (hits), misses (misses), evictions (evictions), and accesses that bypass the page buffer (bypasses).

Since
1.10.1

◆ H5Fget_vfd_handle()

herr_t H5Fget_vfd_handle ( hid_t  file_id,
hid_t  fapl,
void **  file_handle 
)

Returns pointer to the file handle from the virtual file driver.

Parameters
[in]file_idFile identifier
[in]faplFile access property list identifier
[out]file_handlePointer to the file handle being used by the low-level virtual file driver
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

Given the file identifier file_id and the file access property list fapl_id, H5Fget_vfd_handle() returns a pointer to the file handle from the low-level file driver currently being used by the HDF5 library for file I/O.

Note
For most drivers, the value of fapl_id will be H5P_DEFAULT. For the FAMILY or MULTI drivers, this value should be defined through the property list functions: H5Pset_family_offset() for the FAMILY driver and H5Pset_multi_type() for the MULTI driver
Since
1.6.0

◆ H5Fincrement_filesize()

herr_t H5Fincrement_filesize ( hid_t  file_id,
hsize_t  increment 
)

Sets the file' EOA to the maximum of (EOA, EOF) + increment.

Parameters
[in]file_idFile identifier
[in]incrementThe number of bytes to be added to the maximum of (EOA, EOF)
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fincrement_filesize() sets the file's EOA to the maximum of (EOA, EOF) + increment. The EOA is the end-of-file address stored in the file's superblock while EOF is the file's actual end-of-file.

Since
1.10.2

◆ H5Fis_accessible()

htri_t H5Fis_accessible ( const char *  container_name,
hid_t  fapl_id 
)

Checks if a file can be opened with a given file access property list.

Parameters
[in]container_nameName of a file
[in]fapl_idFile access property list identifier
Returns
Returns zero (false), a positive (true) or a negative (failure) value.

H5Fis_accessible() checks if the file specified by container_name can be opened with the file access property list fapl_id.

Note
The H5Fis_accessible() function enables files to be checked with a given file access property list, unlike H5Fis_hdf5(), which only uses the default file driver when opening a file.
Since
1.12.0

◆ H5Fis_hdf5()

htri_t H5Fis_hdf5 ( const char *  file_name)

Determines whether a file is in the HDF5 format.

Parameters
[in]file_nameFile name
Returns
Returns zero (false), a positive (true) or a negative (failure) value.

H5Fis_hdf5() determines whether a file is in the HDF5 format.

Since
1.0.0
Deprecated:
1.12.0 Deprecated in favor of the function H5Fis_accessible()

◆ H5Fmount()

herr_t H5Fmount ( hid_t  loc_id,
const char *  name,
hid_t  child,
hid_t  plist 
)

Mounts an HDF5 file.

Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]nameName of the group onto which the file specified by child is to be mounted
[in]childFile identifier
[in]plistFile mount property list identifier. Pass H5P_DEFAULT!
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fmount() mounts the file specified by child onto the object specified by loc and name using the mount properties plist If the object specified by loc is a dataset, named datatype or attribute, then the file will be mounted at the location where the attribute, dataset, or named datatype is attached.

Example
{
hid_t file = H5Fopen("f11.h5", H5F_ACC_RDWR, H5P_DEFAULT);
if (file != H5I_INVALID_HID) {
hid_t group, child;
if ((group = H5Gcreate1(file, "mount_point", H5P_DEFAULT)) != H5I_INVALID_HID) {
if ((child = H5Fopen("f1.h5", H5F_ACC_RDONLY, H5P_DEFAULT)) != H5I_INVALID_HID) {
if (H5Fmount(group, ".", child, H5P_DEFAULT) >= 0) {
// do something useful w/ the mounted file
}
else {
ret_val = EXIT_FAILURE;
perror("H5Fmount failed.");
}
H5Fclose(child);
}
H5Gclose(group);
}
H5Fclose(file);
}
else
ret_val = EXIT_FAILURE;
}
herr_t H5Fmount(hid_t loc_id, const char *name, hid_t child, hid_t plist)
Mounts an HDF5 file.
hid_t H5Gcreate1(hid_t loc_id, const char *name, size_t size_hint)
Creates a new group and links it into the file.
herr_t H5Gclose(hid_t group_id)
Closes the specified group.
Note
To date, no file mount properties have been defined in HDF5. The proper value to pass for plist is H5P_DEFAULT, indicating the default file mount property list.
Since
1.0.0

◆ H5Fopen()

hid_t H5Fopen ( const char *  filename,
unsigned  flags,
hid_t  fapl_id 
)

Opens an existing HDF5 file.

Parameters
[in]filenameName of the file to be opened
[in]flagsFile access flags. Allowable values are:
  • H5F_ACC_RDWR: Allows read and write access to file
  • H5F_ACC_RDONLY: Allows read-only access to file
  • H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE: Indicates that the file is open for writing in a single-writer/multi-writer (SWMR) scenario.
  • H5F_ACC_RDONLY | H5F_ACC_SWMR_READ: Indicates that the file is open for reading in a single-writer/multi-reader (SWMR) scenario.
  • An additional flag, H5F_ACC_DEBUG, prints debug information. This flag can be combined with one of the above values using the bit-wise OR operator (|), but it is used only by HDF5 library developers; it is neither tested nor supported for use in applications.
[in]fapl_idFile access property list identifier
Returns
Returns a file identifier if successful; otherwise returns H5I_INVALID_HID.

H5Fopen() is the primary function for accessing existing HDF5 files. This function opens the named file in the specified access mode and with the specified access property list.

Note that H5Fopen() does not create a file if it does not already exist; see H5Fcreate().

The filename parameter specifies the name of the file to be opened.

The fapl_id parameter specifies the file access property list. The use of H5P_DEFAULT specifies that default I/O access properties are to be used.

The flags parameter specifies whether the file will be opened in read-write or read-only mode, H5F_ACC_RDWR or H5F_ACC_RDONLY, respectively. More complex behaviors of file access are controlled through the file-access property list.

The return value is a file identifier for the open file; this file identifier should be closed by calling H5Fclose() when it is no longer needed.

Example
{
unsigned mode = H5F_ACC_RDONLY;
char name[] = "f11.h5";
hid_t file = H5Fopen(name, mode, H5P_DEFAULT);
if (file != H5I_INVALID_HID)
H5Fclose(file);
else
ret_val = EXIT_FAILURE;
}
Note
H5F_ACC_RDWR and H5F_ACC_RDONLY are mutually exclusive; use exactly one.
Attention
Special cases — Multiple opens: A file can often be opened with a new H5Fopen() call without closing an already-open identifier established in a previous H5Fopen() or H5Fcreate() call. Each such H5Fopen() call will return a unique identifier and the file can be accessed through any of these identifiers as long as the identifier remains valid. In such multiply-opened cases, the open calls must use the same flags argument and the file access property lists must use the same file close degree property setting (see the external link discussion below and H5Pset_fclose_degree()).
In some cases, such as files on a local Unix file system, the HDF5 library can detect that a file is multiply opened and will maintain coherent access among the file identifiers.
But in many other cases, such as parallel file systems or networked file systems, it is not always possible to detect multiple opens of the same physical file. In such cases, HDF5 will treat the file identifiers as though they are accessing different files and will be unable to maintain coherent access. Errors are likely to result in these cases. While unlikely, the HDF5 library may not be able to detect, and thus report, such errors.
It is generally recommended that applications avoid multiple opens of the same file.
Special restriction on multiple opens of a file first opened by means of an external link: When an external link is followed, the external file is always opened with the weak file close degree property setting, H5F_CLOSE_WEAK (see H5Lcreate_external() and H5Pset_fclose_degree()). If the file is reopened with H5Fopen while it remains held open from such an external link call, the file access property list used in the open call must include the file close degree setting H5F_CLOSE_WEAK or the open will fail.
Version
1.10.0 The H5F_ACC_SWMR_WRITE and H5F_ACC_SWMR_READ flags were added.
Since
1.0.0
See also
H5Fclose()

◆ H5Freopen()

hid_t H5Freopen ( hid_t  file_id)

Returns a new identifier for a previously-opened HDF5 file.

Parameters
[in]file_idIdentifier of a file for which an additional identifier is required
Returns
Returns a file identifier if successful; otherwise returns H5I_INVALID_HID.

H5Freopen() returns a new file identifier for an already-open HDF5 file, as specified by file_id. Both identifiers share caches and other information. The only difference between the identifiers is that the new identifier is not mounted anywhere and no files are mounted on it.

The new file identifier should be closed by calling H5Fclose() when it is no longer needed.

Note
Note that there is no circumstance under which H5Freopen() can actually open a closed file; the file must already be open and have an active file_id. E.g., one cannot close a file with H5Fclose() on file_id then use H5Freopen() on file_id to reopen it.
Since
1.0.0

◆ H5Freset_page_buffering_stats()

herr_t H5Freset_page_buffering_stats ( hid_t  file_id)

Resets the page buffer statistics.

Parameters
[in]file_idFile identifier
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Freset_page_buffering_stats() resets the page buffer statistics for a specified file identifier file_id.

Since
1.10.1

◆ H5Fset_dset_no_attrs_hint()

herr_t H5Fset_dset_no_attrs_hint ( hid_t  file_id,
hbool_t  minimize 
)

Sets the flag to create minimized dataset object headers.

Parameters
[in]file_idFile identifier
[in]minimizeFlag indicating whether the library will or will not create minimized dataset object headers
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fset_dset_no_attrs_hint() sets the no dataset attributes hint setting for the file specified by the file identifier file_id. If the boolean flag minimize is set to true, then the library will create minimized dataset object headers in the file. All files that refer to the same file-on-disk will be affected by the most recent setting, regardless of the file identifier/handle (e.g., as returned by H5Fopen()). By setting the minimize flag to true, the library expects that no attributes will be added to the dataset - attributes can be added, but they are appended with a continuation message, which can reduce performance.

Attention
This setting interacts with H5Pset_dset_no_attrs_hint(): if either is set to true, then the created dataset's object header will be minimized.
Since
1.10.5

◆ H5Fset_latest_format()

herr_t H5Fset_latest_format ( hid_t  file_id,
hbool_t  latest_format 
)

Sets the latest version of the library to be used for writing objects.

Parameters
[in]file_idFile identifier
[in]latest_formatLatest format flag
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.
Since
1.10.1
Deprecated:
1.10.2 Deprecated in favor of the function H5Fset_libver_bounds()

◆ H5Fset_libver_bounds()

herr_t H5Fset_libver_bounds ( hid_t  file_id,
H5F_libver_t  low,
H5F_libver_t  high 
)

Enables the switch of version bounds setting for a file.

Parameters
[in]file_idFile identifier
[in]lowThe earliest version of the library that will be used for writing objects
[in]highThe latest version of the library that will be used for writing objects
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

H5Fset_libver_bounds() enables the switch of version bounds setting for an open file associated with file_id.

For the parameters low and high, see the description for H5Pset_libver_bounds().

Example
{
unsigned mode = H5F_ACC_RDWR;
char name[] = "f11.h5";
hid_t file = H5Fopen(name, mode, H5P_DEFAULT);
if (file != H5I_INVALID_HID) {
// object creation will not exceed HDF5 version 1.8.x
}
else
perror("H5Fset_libver_bounds failed.");
if (H5Fclose(file) < 0)
perror("H5Fclose failed.");
}
else
ret_val = EXIT_FAILURE;
}
@ H5F_LIBVER_V18
Definition H5Fpublic.h:167
@ H5F_LIBVER_EARLIEST
Definition H5Fpublic.h:166
herr_t H5Fset_libver_bounds(hid_t file_id, H5F_libver_t low, H5F_libver_t high)
Enables the switch of version bounds setting for a file.
Since
1.10.2

◆ H5Funmount()

herr_t H5Funmount ( hid_t  loc_id,
const char *  name 
)

Un-mounts an HDF5 file.

Parameters
[in]loc_idLocation identifier. The identifier may be that of a file or group.
[in]nameName of the mount point
Returns
Returns a non-negative value if successful; otherwise, returns a negative value.

Given a mount point, H5Funmount() dissociates the mount point's file from the file mounted there. This function does not close either file.

The mount point can be either the group in the parent or the root group of the mounted file (both groups have the same name). If the mount point was opened before the mount then it is the group in the parent; if it was opened after the mount then it is the root group of the child.

Since
1.0.0