H5F_OPEN 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 H5F_OPEN does not create a file if it does not already exist; see H5F_CREATE.
name parameter specifies the name of the file to be opened.
fapl_id parameter specifies the file access property list. Use of
H5P_DEFAULT specifies that default I/O access properties are to be used
flags parameter specifies whether the file will be opened in read-write or read-only mode,
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 H5F_CLOSE when it is no longer needed.
PLEASE be aware that by default when opening and then closing objects in an HDF5 file, the file close is delayed until ALL objects in the file are closed (in other words, a WEAK file close degree is used). This behavior can be changed by modifying the file close degree file access property list with H5P_SET_FCLOSE_DEGREE when the file is opened. See the notes below and the H5P_SET_FCLOSE_DEGREE function for more information.
Special cases — Multiple opens:
A file can often be opened with a new H5F_OPEN call without closing an already-open identifier established in a previous H5F_OPEN or H5F_CREATE call. Each such H5F_OPEN 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 H5P_SET_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 H5L_CREATE_EXTERNAL and H5P_SET_FCLOSE_DEGREE). If the file is reopened with H5F_OPEN 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.