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
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:91
#define H5I_INVALID_HID
Definition: H5Ipublic.h:66
int hid_t
Definition: H5Ipublic.h:60
#define H5P_FILE_CREATE
Definition: H5Ppublic.h:214
#define H5P_FILE_ACCESS
Definition: H5Ppublic.h:215
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.
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:88
unsigned long long hsize_t
Definition: H5public.h:334
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:89
#define H5P_DEFAULT
Definition: H5Ppublic.h:255
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:

  1. The control of the HDF5 Metadata Cache
  2. The use of (MPI-) Parallel HDF5

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...
 

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:90
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 opened 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.
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()

◆ 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:131
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 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.

◆ 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.

◆ 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().

◆ 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_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_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_info()

herr_t H5Fget_info ( hid_t  obj_id,
H5F_info_t file_info 
)

Retrieves name of file to which object belongs.

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_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:

typedef struct H5F_info_t {
struct {
} sohm;
Definition: H5public.h:456
Definition: H5Fpublic.h:154
struct H5F_info_t::@0 sohm
H5_ih_info_t msgs_info
Definition: H5Fpublic.h:158
hsize_t super_ext_size
Definition: H5Fpublic.h:155
hsize_t hdr_size
Definition: H5Fpublic.h:157

super_ext_size is the size of the superblock extension.

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

Since
1.8.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.
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]sizeSize, in bytes, of the name buffer
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.

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.

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, 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_DATATYPENamed datatypes only
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.

◆ 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_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

◆ H5Fis_hdf5()

htri_t H5Fis_hdf5 ( const char *  filename)

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

Parameters
[in]filenameName of a file
Returns
Returns zero (false), a positive (true) or a negative (failure) value.

H5F__is_hdf5() checks if the file specified by filename can be opened.

Note
The H5Fis_hdf5(), only uses the default file driver when opening a file.

◆ H5Fmount()

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

Mounts an HDF5 file.

Parameters
[in]locLocation identifier
[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, 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.

◆ 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
  • 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. 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.
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.

◆ H5Funmount()

herr_t H5Funmount ( hid_t  loc,
const char *  name 
)

Unounts an HDF5 file.

Parameters
[in]locLocation identifier
[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.