![]() |
HDF5
1.8.23
C-API Reference
|
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.
Create | Read |
---|---|
hid_t H5Pcreate(hid_t cls_id) Creates a new property list as an instance of a property list class. hid_t H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id) Creates an HDF5 file. | 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. |
Update | Delete |
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. |
In addition to general file management functions, there are three categories of functions that deal with advanced file management tasks and use cases:
Modules | |
Metadata Cache | |
Parallel | |
Functions | |
htri_t | H5Fis_hdf5 (const char *filename) |
Checks if a file can be opened with a given file access property list. More... | |
hid_t | H5Fcreate (const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id) |
Creates an HDF5 file. More... | |
hid_t | H5Fopen (const char *filename, unsigned flags, hid_t fapl_id) |
Opens an existing HDF5 file. More... | |
hid_t | H5Freopen (hid_t file_id) |
Returns a new identifier for a previously-opened HDF5 file. More... | |
herr_t | H5Fflush (hid_t object_id, H5F_scope_t scope) |
Flushes all buffers associated with a file to storage. More... | |
herr_t | H5Fclose (hid_t file_id) |
Terminates access to an HDF5 file. More... | |
hid_t | H5Fget_create_plist (hid_t file_id) |
Returns a file creation property list identifier. More... | |
hid_t | H5Fget_access_plist (hid_t file_id) |
Returns a file access property list identifier. More... | |
herr_t | H5Fget_intent (hid_t file_id, unsigned *intent) |
Determines the read/write or read-only status of a file. More... | |
ssize_t | H5Fget_obj_count (hid_t file_id, unsigned types) |
Returns the number of open object identifiers for an open file. More... | |
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. More... | |
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. More... | |
herr_t | H5Fmount (hid_t loc, const char *name, hid_t child, hid_t plist) |
Mounts an HDF5 file. More... | |
herr_t | H5Funmount (hid_t loc, const char *name) |
Unounts an HDF5 file. More... | |
hssize_t | H5Fget_freespace (hid_t file_id) |
Returns the amount of free space in a file (in bytes) More... | |
herr_t | H5Fget_filesize (hid_t file_id, hsize_t *size) |
Returns the size of an HDF5 file (in bytes) More... | |
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. More... | |
ssize_t | H5Fget_name (hid_t obj_id, char *name, size_t size) |
Retrieves name of file to which object belongs. More... | |
herr_t | H5Fget_info (hid_t obj_id, H5F_info_t *file_info) |
Retrieves name of file to which object belongs. More... | |
herr_t | H5Fclear_elink_file_cache (hid_t file_id) |
Clears the external link open file cache. More... | |
Clears the external link open file cache.
[in] | file_id | File identifier |
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.
Terminates access to an HDF5 file.
[in] | file_id | File identifier |
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.
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.Creates an HDF5 file.
[in] | filename | Name of the file to create |
[in] | flags | File access flags. Allowable values are:
|
[in] | fcpl_id | File creation property list identifier |
[in] | fapl_id | File access property list identifier |
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.
|), but it is used only by HDF5 library developers; it is neither tested nor supported for use in applications.herr_t H5Fflush | ( | hid_t | object_id, |
H5F_scope_t | scope | ||
) |
Flushes all buffers associated with a file to storage.
[in] | object_id | Location identifier |
[in] | scope | The scope of the flush action |
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_GLOBAL | Flushes the entire virtual file |
H5F_SCOPE_LOCAL | Flushes only the specified file |
Returns a file access property list identifier.
[in] | file_id | File identifier |
H5Fget_access_plist() returns the file access property list identifier of the specified file.
Returns a file creation property list identifier.
[in] | file_id | File identifier |
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().
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.
[in] | file_id | File identifier |
[out] | buf_ptr | Pointer 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_len | Size of the supplied buffer |
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.
Returns the size of an HDF5 file (in bytes)
[in] | file_id | File identifier |
[out] | size | Size of the file, in bytes |
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.
Returns the amount of free space in a file (in bytes)
[in] | file_id | File identifier |
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.
herr_t H5Fget_info | ( | hid_t | obj_id, |
H5F_info_t * | file_info | ||
) |
Retrieves name of file to which object belongs.
[in] | obj_id | Object identifier. The identifier may be that of a file, group, dataset, named datatype, or attribute. |
[out] | file_info | Buffer for global file information |
H5Fget_info() returns global information for the file associated with the object identifier obj_id
in the H5F_info_t struct
named file_info
.
obj_id
is an identifier for any object in the file of interest.
H5F_info_t struct is defined in H5Fpublic.h as follows:
super_ext_size
is the size of the superblock extension.
The sohm
sub-struct contains shared object header message information as follows:
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.Determines the read/write or read-only status of a file.
[in] | file_id | File identifier |
[out] | intent | Access mode flag as originally passed with H5Fopen() |
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_RDWR | File was opened with read/write access. |
H5F_ACC_RDONLY | File was opened with read-only access. |
ssize_t H5Fget_name | ( | hid_t | obj_id, |
char * | name, | ||
size_t | size | ||
) |
Retrieves name of file to which object belongs.
[in] | obj_id | Object identifier |
[out] | name | Buffer for the file name |
[in] | size | Size, in bytes, of the name buffer |
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.
If the length of the name, which determines the required value of size, is unknown, a preliminary H5Fget_name() call can be made by setting name
to NULL. The return value of this call will be the size of the file name; that value plus one (1) can then be assigned to size for a second H5Fget_name() call, which will retrieve the actual name. (The value passed in with the parameter size
must be one greater than size in bytes of the actual name in order to accommodate the null terminator; if size
is set to the exact size of the name, the last byte passed back will contain the null terminator and the last character will be missing from the name passed back to the calling application.)
If an error occurs, the buffer pointed to by name
is unchanged and the function returns a negative value.
ssize_t H5Fget_obj_count | ( | hid_t | file_id, |
unsigned | types | ||
) |
Returns the number of open object identifiers for an open file.
[in] | file_id | File identifier or H5F_OBJ_ALL for all currently-open HDF5 files |
[in] | types | Type of object for which identifiers are to be returned |
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, pass the value H5F_OBJ_ALL in file_id
.
The types of objects to be counted are specified in types as follows:
H5F_OBJ_FILE | Files only |
H5F_OBJ_DATASET | Datasets only |
H5F_OBJ_GROUP | Groups only |
H5F_OBJ_DATATYPE | Named datatypes only |
H5F_OBJ_ATTR | Attributes only |
H5F_OBJ_ALL | All of the above |
H5F_OBJ_LOCAL | Restrict search to objects opened through 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.
ssize_t
. Returns a list of open object identifiers.
[in] | file_id | File identifier or H5F_OBJ_ALL for all currently-open HDF5 files |
[in] | types | Type of object for which identifiers are to be returned |
[in] | max_objs | Maximum number of object identifiers to place into obj_id_list |
[out] | obj_id_list | Pointer to the returned buffer of open object identifiers |
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.
ssize_t
and max_objs
parameter datatype changed to size_t
. ssize_t
and max_objs
parameter datatype changed to size_t
. Returns pointer to the file handle from the virtual file driver.
[in] | file_id | File identifier |
[in] | fapl | File access property list identifier |
[out] | file_handle | Pointer to the file handle being used by the low-level virtual file driver |
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.
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
driverhtri_t H5Fis_hdf5 | ( | const char * | filename | ) |
Checks if a file can be opened with a given file access property list.
[in] | filename | Name of a file |
H5F__is_hdf5() checks if the file specified by filename
can be opened.
Mounts an HDF5 file.
[in] | loc | Location identifier |
[in] | name | Name of the group onto which the file specified by child is to be mounted |
[in] | child | File identifier |
[in] | plist | File mount property list identifier. Pass H5P_DEFAULT! |
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.
plist
is H5P_DEFAULT, indicating the default file mount property list. Opens an existing HDF5 file.
[in] | filename | Name of the file to be opened |
[in] | flags | File access flags. Allowable values are:
|
[in] | fapl_id | File access property list identifier |
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. 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.
Returns a new identifier for a previously-opened HDF5 file.
[in] | file_id | Identifier of a file for which an additional identifier is required |
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.
file_id
. E.g., one cannot close a file with H5Fclose() on file_id
then use H5Freopen() on file_id
to reopen it. Unounts an HDF5 file.
[in] | loc | Location identifier |
[in] | name | Name of the mount point |
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.