Help us improve by taking our short survey: https://www.hdfgroup.org/website-survey/

| HDF5 Last Updated on 2026-07-28 The HDF5 Field Guide

Loading...
Searching...
No Matches
HDF5 File

Navigate back: Main / HDF5 User Guide

# The HDF5 File

## Introduction

The purpose of this chapter is to describe how to work with HDF5 data files.

If HDF5 data is to be written to or read from a file, the file must first be explicitly created or opened with the appropriate file driver and access privileges. Once all work with the file is complete, the file must be explicitly closed.

This chapter discusses the following:

- File access modes
- Creating, opening, and closing files
- The use of file creation property lists
- The use of file access property lists
- The use of low-level file drivers

This chapter assumes an understanding of the material presented in the data model chapter. For more information, see The HDF5 Data Model and File Structure.

## File Access Modes

There are two issues regarding file access:

- What should happen when a new file is created but a file of the same name already exists? Should the create action fail, or should the existing file be overwritten?
- Is a file to be opened with read-only or read-write access?

Four access modes address these concerns. Two of these modes can be used with H5Fcreate, and two modes can be used with H5Fopen.

- H5Fcreate accepts H5F_ACC_EXCL or H5F_ACC_TRUNC
- H5Fopen accepts H5F_ACC_RDONLY or H5F_ACC_RDWR

The access modes are described in the table below.

Access flags and modes
Access Flag | Resulting Access Mode
--- | ---
H5F_ACC_EXCL | If the file already exists, H5Fcreate fails. If the file does not exist, it is created and opened with read-write access. (Default)
H5F_ACC_TRUNC | If the file already exists, the file is opened with read-write access, and new data will overwrite any existing data. If the file does not exist, it is created and opened with read-write access.
H5F_ACC_RDONLY | An existing file is opened with read-only access. If the file does not exist, H5Fopen fails. (Default)
H5F_ACC_RDWR | An existing file is opened with read-write access. If the file does not exist, H5Fopen fails.

By default, H5Fopen opens a file for read-only access; passing H5F_ACC_RDWR allows read-write access to the file.

By default, H5Fcreate fails if the file already exists; only passing H5F_ACC_TRUNC allows the truncating of an existing file.

## File Creation and File Access Properties

File creation and file access property lists control the more complex aspects of creating and accessing files.

File creation property lists control the characteristics of a file such as the size of the userblock, a user-definable data block; the size of data address parameters; properties of the B-trees that are used to manage the data in the file; and certain HDF5 Library versioning information.

For more information, see File Creation Properties.

This section has a more detailed discussion of file creation properties. If you have no special requirements for these file characteristics, you can simply specify H5P_DEFAULT for the default file creation property list when a file creation property list is called for.

File access property lists control properties and means of accessing a file such as data alignment characteristics, metadata block and cache sizes, data sieve buffer size, garbage collection settings, and parallel I/O. Data alignment, metadata block and cache sizes, and data sieve buffer size are factors in improving I/O performance.

For more information, see File Access Properties.

This section has a more detailed discussion of file access properties. If you have no special requirements for these file access characteristics, you can simply specify H5P_DEFAULT for the default file access property list when a file access property list is called for.

Figure 10 - More sample file structures
UML model for an HDF5 file and its property lists

## Low-level File Drivers

The concept of an HDF5 file is actually rather abstract: the address space for what is normally thought of as an HDF5 file might correspond to any of the following at the storage level:

- Single file on a standard file system
- Multiple files on a standard file system
- Multiple files on a parallel file system
- Block of memory within an application's memory space
- More abstract situations such as virtual files

This HDF5 address space is generally referred to as an HDF5 file regardless of its organization at the storage level.

HDF5 accesses a file (the address space) through various types of low-level file drivers. The default HDF5 file storage layout is as an unbuffered permanent file which is a single, contiguous file on local disk. Alternative layouts are designed to suit the needs of a variety of systems, environments, and applications.

## Programming Model for Files

Programming models for creating, opening, and closing HDF5 files are described in the sub-sections below.

### Creating a New File

The programming model for creating a new HDF5 file can be summarized as follows:

- Define the file creation property list
- Define the file access property list
- Create the file

First, consider the simple case where we use the default values for the property lists. See the example below.

Creating an HDF5 file using property list defaults

file_id = H5Fcreate ("SampleFile.h5", H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT)
H5F_ACC_EXCL
#define H5F_ACC_EXCL
Definition H5Fpublic.h:31
H5P_DEFAULT
#define H5P_DEFAULT
Definition H5Ppublic.h:220
H5Fcreate
hid_t H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
Creates an HDF5 file.

Note: The example above specifies that H5Fcreate should fail if SampleFile.h5 already exists.

A more complex case is shown in the example below. In this example, we define file creation and access property lists (though we do not assign any properties), specify that H5Fcreate should fail if SampleFile.h5 already exists, and create a new file named SampleFile.h5. The example does not specify a driver, so the default driver, H5FD_SEC2, will be used.

Creating an HDF5 file using property lists

fcplist_id = H5Pcreate (H5P_FILE_CREATE)
<...set desired file creation properties...>
faplist_id = H5Pcreate (H5P_FILE_ACCESS)
<...set desired file access properties...>
file_id = H5Fcreate ("SampleFile.h5", H5F_ACC_EXCL, fcplist_id, faplist_id)
H5P_FILE_CREATE
#define H5P_FILE_CREATE
Definition H5Ppublic.h:52
H5P_FILE_ACCESS
#define H5P_FILE_ACCESS
Definition H5Ppublic.h:56
H5Pcreate
hid_t H5Pcreate(hid_t cls_id)
Creates a new property list as an instance of a property list class.

Notes:

1. A root group is automatically created in a file when the file is first created.
2. File property lists, once defined, can be reused when another file is created within the same application.

### Opening an Existing File

The programming model for opening an existing HDF5 file can be summarized as follows:

- Define or modify the file access property list including a low-level file driver (optional)
- Open the file

The code in the example below shows how to open an existing file with read-only access.

Opening an HDF5 file

faplist_id = H5Pcreate (H5P_FILE_ACCESS)
status = H5Pset_fapl_stdio (faplist_id)
file_id = H5Fopen ("SampleFile.h5", H5F_ACC_RDONLY, faplist_id)
H5F_ACC_RDONLY
#define H5F_ACC_RDONLY
Definition H5Fpublic.h:28
H5Pset_fapl_stdio
herr_t H5Pset_fapl_stdio(hid_t fapl_id)
Sets the standard I/O driver.
H5Fopen
hid_t H5Fopen(const char *filename, unsigned flags, hid_t fapl_id)
Opens an existing HDF5 file.

### Closing a File

The programming model for closing an HDF5 file is very simple:

- Close file

We close SampleFile.h5 with the code in the example below.

Closing an HDF5 file

status = H5Fclose (file_id)
H5Fclose
herr_t H5Fclose(hid_t file_id)
Terminates access to an HDF5 file.

Note that H5Fclose flushes all unwritten data to storage and that file_id is the identifier returned for SampleFile.h5 by H5Fopen.

More comprehensive discussions regarding all of these steps are provided below.

## Using h5dump to View a File

h5dump is a command-line utility that is included in the HDF5 distribution. This program provides a straight-forward means of inspecting the contents of an HDF5 file. You can use h5dump to verify that a program is generating the intended HDF5 file. h5dump displays ASCII output formatted according to the HDF5 DDL grammar.

The following h5dump command will display the contents of SampleFile.h5:

h5dump SampleFile.h5

If no datasets or groups have been created in and no data has been written to the file, the output will look something like the following:

HDF5 "SampleFile.h5" {
GROUP "/" {
}
}

Note that the root group, indicated above by /, was automatically created when the file was created.

h5dump is described on the h5dump page under Command-line Tools. The HDF5 DDL grammar is described in the document DDL in BNF for HDF5 2.0.0 and above.

## File Function Summaries

General library (Library General (H5) functions and macros), (Files (H5F) functions), file related (Property Lists (H5P) functions), and file driver (Property Lists (H5P) functions) are listed below.

General library functions and macros
Function | Purpose
--- | ---
H5check_version | Verifies that HDF5 library versions are consistent.
H5close | Flushes all data to disk, closes all open identifiers, and cleans up memory.
H5dont_atexit | Instructs the library not to install the atexit cleanup routine.
H5garbage_collect | Performs garbage collection (GC) on all free-lists of all types.
H5get_libversion | Returns the HDF library release number.
H5open | Initializes the HDF5 library.
H5set_free_list_limits | Sets free-list size limits.
H5_VERSION_GE | Determines whether the version of the library being used is greater than or equal to the specified version.
H5_VERSION_LE | Determines whether the version of the library being used is less than or equal to the specified version.

File functions
Function | Purpose
--- | ---
H5Fclear_elink_file_cache | Clears the external link open file cache for a file.
H5Fclose | Closes HDF5 file.
H5Fcreate | Creates new HDF5 file.
H5Fflush | Flushes data to HDF5 file on storage medium.
H5Fget_access_plist | Returns a file access property list identifier.
H5Fget_create_plist | Returns a file creation property list identifier.
H5Fget_file_image | Retrieves a copy of the image of an existing, open file.
H5Fget_filesize | Returns the size of an HDF5 file.
H5Fget_freespace | Returns the amount of free space in a file.
H5Fget_info | Returns global information for a file.
H5Fget_intent | Determines the read/write or read-only status of a file.
H5Fget_mdc_config | Obtains current metadata cache configuration for target file.
H5Fget_mdc_hit_rate | Obtains target file's metadata cache hit rate.
H5Fget_mdc_size | Obtains current metadata cache size data for specified file.
H5Fget_mpi_atomicity | Retrieves the atomicity mode in use.
H5Fget_name | Retrieves the name of the file to which the object belongs.
H5Fget_obj_count | Returns the number of open object identifiers for an open file.
H5Fget_obj_ids | Returns a list of open object identifiers.
H5Fget_vfd_handle | Returns pointer to the file handle from the virtual file driver.
H5Fis_hdf5 | Determines whether a file is in the HDF5 format.
H5Fmount | Mounts a file.
H5Fopen | Opens an existing HDF5 file.
H5Freopen | Returns a new identifier for a previously-opened HDF5 file.
H5Freset_mdc_hit_rate_stats | Resets hit rate statistics counters for the target file.
H5Fset_mdc_config | Configures metadata cache of target file.
H5Fset_mpi_atomicity | Sets the MPI atomicity mode.
H5Funmount | Unmounts a file.

File creation property list functions (H5P)

File creation property list functions (H5P)
Function | Purpose
--- | ---
H5Pset_userblock/H5Pget_userblock | Sets/retrieves size of userblock.
H5Pset_sizes/H5Pget_sizes | Sets/retrieves byte size of offsets and lengths used to address objects in HDF5 file.
H5Pset_sym_k/H5Pget_sym_k | Sets/retrieves size of parameters used to control symbol table nodes.
H5Pset_istore_k/H5Pget_istore_k | Sets/retrieves size of parameter used to control B-trees for indexing chunked datasets.
H5Pset_file_space_page_size/H5Pget_file_space_page_size | Sets or retrieves the file space page size used in paged aggregation and paged buffering.
H5Pset_file_space_strategy/H5Pget_file_space_strategy | Sets or retrieves the file space handling strategy, the persisting free-space and the free-space section size.
H5Pset_shared_mesg_nindexes/H5Pget_shared_mesg_nindexes | Sets or retrieves number of shared object header message indexes in file creation property list.
H5Pset_shared_mesg_index | Configures the specified shared object header message index.
H5Pget_shared_mesg_index | Retrieves the configuration settings for a shared message index.
H5Pset_shared_mesg_phase_change/H5Pget_shared_mesg_phase_change | Sets or retrieves shared object header message storage phase change thresholds.
H5Pget_version |

File access property list functions (H5P)

File access property list functions (H5P)
Function | Purpose
--- | ---
H5Pset_alignment/H5Pget_alignment | Sets/retrieves alignment properties.
H5Pset_cache/H5Pget_cache | Sets/retrieves metadata cache and raw data chunk cache parameters.
H5Pset_core_write_tracking/H5Pget_core_write_tracking | Sets/retrieves write tracking information for core driver.
H5Pset_elink_file_cache_size/H5Pget_elink_file_cache_size | Sets/retrieves the size of the external link open file cache from the specified file access property list.
H5Pset_evict_on_close/H5Pget_evict_on_close | Set/get the file access property list setting that determines whether an HDF5 object will be evicted from the library's metadata cache when it is closed.
H5Pset_gc_references/H5Pget_gc_references | Sets/retrieves garbage collecting references flag.
H5Pset_family_offset | Sets offset property for low-level access to a file in a family of files.
H5Pget_family_offset | Retrieves a data offset from the file access property list.
H5Pset_fclose_degree/H5Pget_fclose_degree | Sets/retrieves file close degree property.
H5Pset_file_image | Sets an initial file image in a memory buffer.
H5Pget_file_image | Retrieves a copy of the file image designated as the initial content and structure of a file.
H5Pset_file_image_callbacks/H5Pget_file_image_callbacks | Sets/gets the callbacks for working with file images.
H5Pset_file_locking/H5Pget_file_locking | Sets/retrieves file locking property values.
H5Pset_meta_block_size/H5Pget_meta_block_size | Sets the minimum metadata blocksize or retrieves the current metadata block size setting.
H5Pset_metadata_read_attempts/H5Pget_metadata_read_attempts | Sets/gets the number of read attempts from a file access property list.
H5Pset_mdc_config/H5Pget_mdc_config | Set/get the initial metadata cache configuration in the indicated file access property list.
H5Pset_mdc_image_config/H5Pget_mdc_image_config | Set/get the metadata cache image option for a file access property list.
H5Pset_mdc_log_options/H5Pget_mdc_log_options | Set/get the metadata cache logging options.
H5Pset_multi_type/H5Pget_multi_type | Sets/gets the type of data property for the MULTI driver.
H5Pset_object_flush_cb/H5Pget_object_flush_cb | Set/get the object flush property values from the file access property list.
H5Pset_page_buffer_size/H5Pget_page_buffer_size | Set/get the maximum size for the page buffer.
H5Pset_sieve_buf_size/H5Pget_sieve_buf_size | Sets/retrieves maximum size of data sieve buffer.
H5Pset_libver_bounds | Sets bounds on library versions, and indirectly format versions, to be used when creating objects.
H5Pget_libver_bounds | Retrieves library version bounds settings that indirectly control the format versions used when creating objects.
H5Pset_small_data_block_size | Sets the size of a contiguous block reserved for small data.
H5Pget_small_data_block_size | Retrieves the current small data block size setting.
H5Pset_vol | Sets the file VOL connector for a file access property list.
H5Pget_vol_cap_flags | Retrieves the capability flags for the VOL connector that will be used with a file access property list.
H5Pget_vol_id | Retrieves the identifier of the current VOL connector.
H5Pget_vol_info | Retrieves a copy of the VOL information for a connector.
H5Pset_mpi_params/H5Pget_mpi_params | Sets/retrieves the MPI communicator and info.
H5Pset_coll_metadata_write/H5Pget_coll_metadata_write | Sets/retrieves metadata write mode setting.

File driver property list functions (H5P)

File driver property list functions (H5P)
Function | Purpose
--- | ---
H5Pset_driver | Sets a file driver.
H5Pget_driver | Returns the identifier for the driver used to create a file.
H5Pget_driver_info | Returns a pointer to file driver information.
H5Pset_driver_by_name | Sets a file driver according to a given driver name.
H5Pset_driver_by_value | Sets a file driver according to a given driver value.
H5Pget_driver_config_str | Retrieves a string representation of the configuration for the driver.
H5Pset_fapl_core/H5Pget_fapl_core | Sets the driver for buffered memory files (in RAM) or retrieves information regarding the driver.
H5Pset_fapl_direct/H5Pget_fapl_direct | Sets up use of the direct I/O driver or retrieves the direct I/O driver settings.
H5Pset_fapl_family/H5Pget_fapl_family | Sets driver for file families, designed for systems that do not support files larger than 2 gigabytes, or retrieves information regarding driver.
H5Pset_fapl_hdfs/H5Pget_fapl_hdfs | .
H5Pset_fapl_ioc/H5Pget_fapl_ioc | Modifies/queries the file driver properties of the I/O concentrator driver.
H5Pset_fapl_log | The logging driver is a clone of the standard SEC2 (H5FD_SEC2) driver with additional facilities for logging metrics and activity to a file.
H5Pset_fapl_mirror/H5Pget_fapl_mirror | Modifies/queries the file driver properties of the mirror driver.
H5Pset_fapl_mpio/H5Pget_fapl_mpio | Sets driver for files on parallel file systems (MPI I/O) or retrieves information regarding the driver.
H5Pset_fapl_mpiposix/H5Pget_fapl_mpiposix | No longer available.
H5Pset_fapl_multi/H5Pget_fapl_multi | Sets driver for multiple files, separating categories of metadata and raw data, or retrieves information regarding driver.
H5Pset_fapl_onion/H5Pget_fapl_onion | Modifies/queries the file driver properties of the onion driver.
H5Pset_fapl_ros3/H5Pget_fapl_ros3 | Modifies/queries the file driver properties of the ros3 driver.
H5Pset_fapl_sec2 | Sets driver for unbuffered permanent files or retrieves information regarding driver.
H5Pset_fapl_split | Sets driver for split files, a limited case of multi driver with one metadata file and one raw data file.
H5Pset_fapl_splitter/H5Pget_fapl_splitter | Modifies/queries the file driver properties of the splitter driver.
H5Pset_fapl_stdio | Sets driver for buffered permanent files.
H5Pset_fapl_subfiling/H5Pget_fapl_subfiling | Modifies/queries the file driver properties of the subfiling driver.
H5Pset_fapl_windows | Sets the Windows I/O driver.
H5Pset_multi_type | Specifies type of data to be accessed via the MULTI driver enabling more direct access.
H5Pget_multi_type | Retrieves type of data property for MULTI driver.

## Creating or Opening an HDF5 File

This section describes in more detail how to create and how to open files.

New HDF5 files are created and opened with H5Fcreate; existing files are opened with H5Fopen. Both functions return an object identifier which must eventually be released by calling H5Fclose.

To create a new file, call H5Fcreate:

hid_t H5Fcreate (const char *name, unsigned flags, hid_t fcpl_id, hid_t fapl_id)
hid_t
int64_t hid_t
Definition H5Ipublic.h:60

H5Fcreate creates a new file named name in the current directory. The file is opened with read and write access; if the H5F_ACC_TRUNC flag is set, any pre-existing file of the same name in the same directory is truncated. If H5F_ACC_TRUNC is not set or H5F_ACC_EXCL is set and if a file of the same name exists, H5Fcreate will fail.

The new file is created with the properties specified in the property lists fcpl_id and fapl_id. fcpl is short for file creation property list. fapl is short for file access property list. Specifying H5P_DEFAULT for either the creation or access property list will use the library's default creation or access properties.

If H5Fcreate successfully creates the file, it returns a file identifier for the new file. This identifier will be used by the application any time an object identifier, an OID, for the file is required. Once the application has finished working with a file, the identifier should be released and the file closed with H5Fclose.

To open an existing file, call H5Fopen:

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

H5Fopen opens an existing file with read-write access if H5F_ACC_RDWR is set and read-only access if H5F_ACC_RDONLY is set.

fapl_id is the file access property list identifier. Alternatively, H5P_DEFAULT indicates that the application relies on the default I/O access parameters. Creating and changing access property lists is documented further below.

A file can be opened more than once via multiple H5Fopen calls. Each such call returns a unique file identifier and the file can be accessed through any of these file identifiers as long as they remain valid. Each of these file identifiers must be released by calling H5Fclose when it is no longer needed.

For more information, see File Access Properties.

For more information, see File Property Lists.

## Closing an HDF5 File

H5Fclose both closes a file and releases the file identifier returned by H5Fopen or H5Fcreate. H5Fclose must be called when an application is done working with a file; while the HDF5 Library makes every effort to maintain file integrity, failure to call H5Fclose may result in the file being abandoned in an incomplete or corrupted state.

To close a file, call H5Fclose:

herr_t H5Fclose (hid_t file_id)
herr_t
int herr_t
Definition H5public.h:269

This function releases resources associated with an open file. After closing a file, the file identifier, file_id, cannot be used again as it will be undefined.

H5Fclose fulfills three purposes: to ensure that the file is left in an uncorrupted state, to ensure that all data has been written to the file, and to release resources. Use H5Fflush if you wish to ensure that all data has been written to the file but it is premature to close it.

Note regarding serial mode behavior: When H5Fclose is called in serial mode, it closes the file and terminates new access to it, but it does not terminate access to objects that remain individually open within the file. That is, 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. To illustrate, assume that a file, fileA, contains a dataset, data_setA, and that both are open when H5Fclose is called for fileA. data_setA will remain open and accessible, including writable, until it is explicitly closed. The file will be automatically and finally closed once all objects within it have been closed.

Note regarding parallel mode behavior: Once H5Fclose has been called in parallel mode, access is no longer available to any object within the file.

## File Property Lists

Additional information regarding file structure and access are passed to H5Fcreate and H5Fopen through property list objects. Property lists provide a portable and extensible method of modifying file properties via simple API functions. There are two kinds of file-related property lists:

- File creation property lists
- File access property lists

In the following sub-sections, we discuss only one file creation property, userblock size, in detail as a model for the user. Other file creation and file access properties are mentioned and defined briefly, but the model is not expanded for each; complete syntax, parameter, and usage information for every property list function is provided in the Property Lists (H5P) section of the HDF5 Reference Manual.

For more information,

See also
  Properties and Property Lists in HDF5.

### Creating a Property List

If you do not wish to rely on the default file creation and access properties, you must first create a property list with H5Pcreate.

hid_t H5Pcreate (hid_t cls_id)

cls_id is the type of property list being created. In this case, the appropriate values are H5P_FILE_CREATE for a file creation property list and H5P_FILE_ACCESS for a file access property list.

Thus, the following calls create a file creation property list and a file access property list with identifiers fcpl_id and fapl_id, respectively:

fcpl_id = H5Pcreate (H5P_FILE_CREATE)
fapl_id = H5Pcreate (H5P_FILE_ACCESS)

Once the property lists have been created, the properties themselves can be modified via the functions described in the following sub-sections.

### File Creation Properties

File creation property lists control the file metadata, which is maintained in the superblock of the file. These properties are used only when a file is first created.

#### Userblock Size

herr_t H5Pset_userblock (hid_t plist, hsize_t size)
herr_t H5Pget_userblock (hid_t plist, hsize_t *size)
hsize_t
uint64_t hsize_t
Definition H5public.h:321
H5Pset_userblock
herr_t H5Pset_userblock(hid_t plist_id, hsize_t size)
Sets user block size.
H5Pget_userblock
herr_t H5Pget_userblock(hid_t plist_id, hsize_t *size)
Retrieves the size of a user block.

The userblock is a fixed-length block of data located at the beginning of the file and is ignored by the HDF5 library. This block is specifically set aside for any data or information that developers determine to be useful to their applications but that will not be used by the HDF5 library. The size of the userblock is defined in bytes and may be set to any power of two with a minimum size of 512 bytes. In other words, userblocks might be 512, 1024, or 2048 bytes in size.

This property is set with H5Pset_userblock and queried via H5Pget_userblock. For example, if an application needed a 4K userblock, then the following function call could be used:

status = H5Pset_userblock(fcpl_id, 4096)

The property list could later be queried with:

status = H5Pget_userblock(fcpl_id, size)

and the value 4096 would be returned in the parameter size.

Other properties, described below, are set and queried in exactly the same manner. Syntax and usage are detailed in the Property Lists (H5P) section of the HDF5 Reference Manual.

#### Offset and Length Sizes

This property specifies the number of bytes used to store the offset and length of objects in the HDF5 file. Values of 2, 4, and 8 bytes are currently supported to accommodate 16-bit, 32-bit, and 64-bit file address spaces.

These properties are set and queried via H5Pset_sizes and H5Pget_sizes.

#### Symbol Table Parameters

The size of symbol table B-trees can be controlled by setting the 1/2-rank and 1/2-node size parameters of the B-tree.

These properties are set and queried via H5Pset_sym_k and H5Pget_sym_k

#### Indexed Storage Parameters

The size of indexed storage B-trees can be controlled by setting the 1/2-rank and 1/2-node size parameters of the B-tree.

These properties are set and queried via H5Pset_istore_k and H5Pget_istore_k.

#### Version Information

Various objects in an HDF5 file may over time appear in different versions. The HDF5 Library keeps track of the version of each object in the file.

Version information is retrieved via H5Pget_version.

### File Access Properties

This section discusses file access properties that are not related to the low-level file drivers. File drivers are discussed separately later in this chapter. For more information,

See also
  Alternate File Storage Layouts and Low-level File Drivers.

File access property lists control various aspects of file I/O and structure.

#### Data Alignment

Sometimes file access is faster if certain data elements are aligned in a specific manner. This can be controlled by setting alignment properties via the H5Pset_alignment function. There are two values involved:

- A threshold value
- An alignment interval

Any allocation request at least as large as the threshold will be aligned on an address that is a multiple of the alignment interval.

#### Metadata Block Allocation Size

Metadata typically exists as very small chunks of data; storing metadata elements in a file without blocking them can result in hundreds or thousands of very small data elements in the file. This can result in a highly fragmented file and seriously impede I/O. By blocking metadata elements, these small elements can be grouped in larger sets, thus alleviating both problems.

H5Pset_meta_block_size sets the minimum size in bytes of metadata block allocations. H5Pget_meta_block_size retrieves the current minimum metadata block allocation size.

#### Metadata Cache

Metadata and raw data I/O speed are often governed by the size and frequency of disk reads and writes. In many cases, the speed can be substantially improved by the use of an appropriate cache.

H5Pset_cache sets the minimum cache size for both metadata and raw data and a preemption value for raw data chunks. H5Pget_cache retrieves the current values.

#### Data Sieve Buffer Size

Data sieve buffering is used by certain file drivers to speed data I/O and is most commonly when working with dataset hyperslabs. For example, using a buffer large enough to hold several pieces of a dataset as it is read in for hyperslab selections will boost performance noticeably.

H5Pset_sieve_buf_size sets the maximum size in bytes of the data sieve buffer. H5Pget_sieve_buf_size retrieves the current maximum size of the data sieve buffer.

#### Garbage Collection References

Dataset region references and other reference types use space in an HDF5 file's global heap. If garbage collection is on (1) and the user passes in an uninitialized value in a reference structure, the heap might become corrupted. When garbage collection is off (0), however, and the user reuses a reference, the previous heap block will be orphaned and not returned to the free heap space. When garbage collection is on, the user must initialize the reference structures to 0 or risk heap corruption.

H5Pset_gc_references sets the garbage collecting references flag.

## Alternate File Storage Layouts and Low-level File Drivers

The concept of an HDF5 file is actually rather abstract: the address space for what is normally thought of as an HDF5 file might correspond to any of the following:

- Single file on standard file system
- Multiple files on standard file system
- Multiple files on parallel file system
- Block of memory within application's memory space
- More abstract situations such as virtual files

This HDF5 address space is generally referred to as an HDF5 file regardless of its organization at the storage level.

HDF5 employs an extremely flexible mechanism called the virtual file layer, or VFL, for file I/O. A full understanding of the VFL is only necessary if you plan to write your own drivers see HDF5 Virtual File Layer in the HDF5 Technical Notes.

For our purposes here, it is sufficient to know that the low-level drivers used for file I/O reside in the VFL, as illustrated in the following figure. Note that H5FD_STREAM is not available with 1.8.x and later versions of the library.

I/O path from application to VFL and low-level drivers to storage

As mentioned above, HDF5 applications access HDF5 files through various low-level file drivers. The default driver for that layout is the POSIX driver (also known as the SEC2 driver), H5FD_SEC2. Alternative layouts and drivers are designed to suit the needs of a variety of systems, environments, and applications. The drivers are listed in the table below.

###
Supported file drivers

Supported file drivers
Driver Name | Driver Identifier | Description | Related API
--- | --- | --- | ---
POSIX | H5FD_SEC2 | This driver uses POSIX file-system functions like read and write to perform I/O to a single, permanent file on local disk with no system buffering. This driver is POSIX-compliant and is the default file driver for all systems. | H5Pset_fapl_sec2
Memory | H5FD_CORE | With this driver, an application can work with a file in memory for faster reads and writes. File contents are kept in memory until the file is closed. At closing, the memory version of the file can be written back to disk or abandoned. | H5Pset_fapl_core
Log | H5FD_LOG | This is the H5FD_SEC2 driver with logging capabilities. | H5Pset_fapl_log
Family | H5FD_FAMILY | With this driver, the HDF5 file's address space is partitioned into pieces and sent to separate storage files using an underlying driver of the user's choice. This driver is for systems that do not support files larger than 2 gigabytes. | H5Pset_fapl_family
Multi | H5FD_MULTI | With this driver, data can be stored in multiple files according to the type of the data. I/O might work better if data is stored in separate files based on the type of data. The Split driver is a special case of this driver. | H5Pset_fapl_multi / H5Pset_fapl_split
STDIO | H5FD_STDIO | This driver uses functions from the standard C stdio.h to perform I/O to a single, permanent file on local disk with additional system buffering. | H5Pset_fapl_stdio
Split | H5FD_SPLITTER | This file driver splits a file into two parts. One part stores metadata, and the other part stores raw data. This splitting a file into two parts is a limited case of the Multi driver. | H5Pset_fapl_splitter
Parallel | H5FD_MPIO | This is the standard HDF5 file driver for parallel file systems. This driver uses the MPI standard for both communication and file I/O. | H5Pset_fapl_mpio
Direct | H5FD_DIRECT | This is the H5FD_SEC2 driver except data is written to or read from the file synchronously without being cached by the system. | H5Pset_fapl_direct
Mirror | H5FD_MIRROR | Serial I/O to file using Unix “stdio” functions. | H5Pset_fapl_mirror
HDFS | H5FD_HDFS | Read-Only access to Hadoop Distributed File System (HDFS). | H5Pset_fapl_hdfs
ros3 | H5FD_ROS3 | Read-Only access to Amazon's S3 service. | H5Pset_fapl_ros3
Subfiling | H5FD_SUBFILING | Derived from other "stacked" VFDs such as the splitter, mirror, and family VFDs. | H5Pset_fapl_subfiling
IOC | H5FD_IOC | Relays VFD calls to one VFD, and write calls to another VFD. Maintains two files. | H5Pset_fapl_ioc
Onion | H5FD_ONION | Provide in-file provenance and revision/version control. | H5Pset_fapl_onion
Windows | H5FD_WINDOWS | This driver was modified in HDF5-1.8.8 to be a wrapper of the POSIX driver, H5FD_SEC2. This change should not affect user applications. | H5Pset_fapl_windows
Parallel POSIX | H5FD_MPIPOSIX | This driver is no longer available |
Stream | H5FD_STREAM | This driver is no longer available. |

For more information, see the HDF5 Reference Manual entries for the function calls shown in the column on the right in the table above.

Note that the low-level file drivers manage alternative file storage layouts. Dataset storage layouts (chunking, compression, and external dataset storage) are managed independently of file storage layouts.

If an application requires a special-purpose low-level driver, the VFL provides a public API for creating one. For more information on how to create a driver, see HDF5 Virtual File Layer in the HDF5 Technical Notes.

### Identifying the Previously‐used File Driver

When creating a new HDF5 file, no history exists, so the file driver must be specified if it is to be other than the default.

When opening existing files, however, the application may need to determine which low-level driver was used to create the file. The function H5Pget_driver is used for this purpose. See the example below.

Identifying a driver

hid_t H5Pget_driver (hid_t fapl_id)
H5Pget_driver
hid_t H5Pget_driver(hid_t plist_id)
Returns low-lever driver identifier.

H5Pget_driver returns a constant identifying the low-level driver for the access property list fapl_id. For example, if the file was created with the POSIX (aka SEC2) driver, H5Pget_driver returns H5FD_SEC2.

If the application opens an HDF5 file without both determining the driver used to create the file and setting up the use of that driver, the HDF5 Library will examine the superblock and the driver definition block to identify the driver. See the HDF5 File Format Specification Version 4.0 for detailed descriptions of the superblock and the driver definition block.

### The POSIX (aka SEC2) Driver

The POSIX driver, H5FD_SEC2, uses functions from section 2 of the POSIX manual to access unbuffered files stored on a local file system. This driver is also known as the SEC2 driver. The HDF5 Library buffers metadata regardless of the low-level driver, but using this driver prevents data from being buffered again by the lowest layers of the library.

The function H5Pset_fapl_sec2 sets the file access properties to use the POSIX driver. See the example below.

Using the POSIX, aka SEC2, driver

herr_t H5Pset_fapl_sec2 (hid_t fapl_id)
H5Pset_fapl_sec2
herr_t H5Pset_fapl_sec2(hid_t fapl_id)
Modifies the file access property list to use the H5FD_SEC2 driver.

Any previously-defined driver properties are erased from the property list.

Additional parameters may be added to this function in the future. Since there are no additional variable settings associated with the POSIX driver, there is no H5Pget_fapl_sec2 function.

### The Direct Driver

The Direct driver, H5FD_DIRECT, functions like the POSIX driver except that data is written to or read from the file synchronously without being cached by the system.

The functions H5Pset_fapl_direct and H5Pget_fapl_direct are used to manage file access properties. See the example below.

Using the Direct driver

herr_t H5Pset_fapl_direct(hid_t fapl_id, size_t alignment, size_t block_size, size_t cbuf_size)
herr_t H5Pget_fapl_direct(hid_t fapl_id, size_t *alignment, size_t *block_size, size_t *cbuf_size)
H5Pset_fapl_direct
herr_t H5Pset_fapl_direct(hid_t fapl_id, size_t alignment, size_t block_size, size_t cbuf_size)
Sets up use of the direct I/O driver.
H5Pget_fapl_direct
herr_t H5Pget_fapl_direct(hid_t fapl_id, size_t *boundary, size_t *block_size, size_t *cbuf_size)
Retrieves direct I/O driver settings.

H5Pset_fapl_direct sets the file access properties to use the Direct driver; any previously defined driver properties are erased from the property list. H5Pget_fapl_direct retrieves the file access properties used with the Direct driver. fapl_id is the file access property list identifier. alignment is the memory alignment boundary. block_size is the file system block size. cbuf_size is the copy buffer size.

Additional parameters may be added to this function in the future.

### The Log Driver

The Log driver, H5FD_LOG, is designed for situations where it is necessary to log file access activity.

The function H5Pset_fapl_log is used to manage logging properties. See the example below.

Logging file access

herr_t H5Pset_fapl_log (hid_t fapl_id, const char *logfile, unsigned int flags, size_t buf_size)
H5Pset_fapl_log
herr_t H5Pset_fapl_log(hid_t fapl_id, const char *logfile, unsigned long long flags, size_t buf_size)
Sets up the logging virtual file driver (H5FD_LOG) for use.

H5Pset_fapl_log sets the file access property list to use the Log driver. File access characteristics are identical to access via the POSIX driver. Any previously defined driver properties are erased from the property list.

Log records are written to the file logfile.

The logging levels set with the verbosity parameter are shown in the table below.

Logging levels
Level | Comments
--- | ---
0 | Performs no logging.
1 | Records where writes and reads occur in the file.
2 | Records where writes and reads occur in the file and what kind of data is written at each location. This includes raw data or any of several types of metadata (object headers, superblock, B-tree data, local headers, or global headers).

There is no H5Pget_fapl_log function.

Additional parameters may be added to this function in the future.

### The Windows Driver

The Windows driver, H5FD_WINDOWS, was modified in HDF5-1.8.8 to be a wrapper of the POSIX driver, H5FD_SEC2. In other words, if the Windows drivers is used, any file I/O will instead use the functionality of the POSIX driver. This change should be transparent to all user applications. The Windows driver used to be the default driver for Windows systems. The POSIX driver is now the default.

The function H5Pset_fapl_windows sets the file access properties to use the Windows driver. See the example below.

Using the Windows driver

herr_t H5Pset_fapl_windows (hid_t fapl_id)
H5Pset_fapl_windows
herr_t H5Pset_fapl_windows(hid_t fapl_id)
Sets the Windows I/O driver.

Any previously-defined driver properties are erased from the property list.

Additional parameters may be added to this function in the future. Since there are no additional variable settings associated with the POSIX driver, there is no H5Pget_fapl_windows function.

### The STDIO Driver

The STDIO driver, H5FD_STDIO, accesses permanent files in a local file system like the POSIX driver does. The STDIO driver also has an additional layer of buffering beneath the HDF5 Library.

The function H5Pset_fapl_stdio sets the file access properties to use the STDIO driver. See the example below.

Using the STDIO driver

herr_t H5Pset_fapl_stdio (hid_t fapl_id)

Any previously defined driver properties are erased from the property list.

Additional parameters may be added to this function in the future. Since there are no additional variable settings associated with the STDIO driver, there is no H5Pget_fapl_stdio function.

### The Memory (aka Core) Driver

There are several situations in which it is reasonable, sometimes even required, to maintain a file entirely in system memory. You might want to do so if, for example, either of the following conditions apply:

- Performance requirements are so stringent that disk latency is a limiting factor
- You are working with small, temporary files that will not be retained and, thus, need not be written to storage media

The Memory driver, H5FD_CORE, provides a mechanism for creating and managing such in memory files. The functions H5Pset_fapl_core and H5Pget_fapl_core manage file access properties. See the example below.

Managing file access for in-memory files

herr_t H5Pset_fapl_core (hid_t access_properties, size_t block_size, bool backing_store)
herr_t H5Pget_fapl_core (hid_t access_properties, size_t *block_size, bool *backing_store)
H5Pset_fapl_core
herr_t H5Pset_fapl_core(hid_t fapl_id, size_t increment, bool backing_store)
Modifies the file access property list to use the H5FD_CORE driver.
H5Pget_fapl_core
herr_t H5Pget_fapl_core(hid_t fapl_id, size_t *increment, bool *backing_store)
Queries core file driver properties.

H5Pset_fapl_core sets the file access property list to use the Memory driver; any previously defined driver properties are erased from the property list.

Memory for the file will always be allocated in units of the specified block_size.

The backing_store Boolean flag is set when the in-memory file is created. backing_store indicates whether to write the file contents to disk when the file is closed. If backing_store is set to 1 (true), the file contents are flushed to a file with the same name as the in-memory file when the file is closed or access to the file is terminated in memory. If backing_store is set to 0 (false), the file is not saved.

The application is allowed to open an existing file with the H5FD_CORE driver. While using H5Fopen to open an existing file, if backing_store is set to 1 and the flag for H5Fopen is set to H5F_ACC_RDWR, changes to the file contents will be saved to the file when the file is closed. If backing_store is set to 0 and the flag for H5Fopen is set to H5F_ACC_RDWR, changes to the file contents will be lost when the file is closed. If the flag for H5Fopen is set to H5F_ACC_RDONLY, no change to the file will be allowed either in memory or on file.

If the file access property list is set to use the Memory driver, H5Pget_fapl_core will return block_size and backing_store with the relevant file access property settings.

Note the following important points regarding in-memory files:

- Local temporary files are created and accessed directly from memory without ever being written to disk
- Total file size must not exceed the available virtual memory
- Only one HDF5 file identifier can be opened for the file, the identifier returned by H5Fcreate or H5Fopen
- The changes to the file will be discarded when access is terminated unless backing_store is set to 1

Additional parameters may be added to these functions in the future.

see HDF5 File Image section for information on more advanced usage of the Memory file driver, and see Modified Region Writes section for information on how to set write operations so that only modified regions are written to storage.

### The Family Driver

HDF5 files can become quite large, and this can create problems on systems that do not support files larger than 2 gigabytes. The HDF5 file family mechanism is designed to solve the problems this creates by splitting the HDF5 file address space across several smaller files. This structure does not affect how metadata and raw data are stored: they are mixed in the address space just as they would be in a single, contiguous file.

HDF5 applications access a family of files via the Family driver, H5FD_FAMILY. The functions H5Pset_fapl_family and H5Pget_fapl_family are used to manage file family properties. See the example below.

Managing file family properties

herr_t H5Pset_fapl_family (hid_t fapl_id,
hsize_t memb_size, hid_t member_properties)
herr_t H5Pget_fapl_family (hid_t fapl_id,
hsize_t *memb_size, hid_t *member_properties)
H5Pset_fapl_family
herr_t H5Pset_fapl_family(hid_t fapl_id, hsize_t memb_size, hid_t memb_fapl_id)
Sets the file access property list to use the family driver.
H5Pget_fapl_family
herr_t H5Pget_fapl_family(hid_t fapl_id, hsize_t *memb_size, hid_t *memb_fapl_id)
Returns file access property list information.

Each member of the family is the same logical size though the size and disk storage reported by file system listing tools may be substantially smaller. Examples of file system listing tools are

ls -l

on a Unix system or the detailed folder listing on an Apple or Microsoft Windows system. The name passed to H5Fcreate or H5Fopen should include a printf(3)-style integer format specifier which will be replaced with the family member number. The first family member is numbered zero (0).

H5Pset_fapl_family sets the access properties to use the Family driver; any previously defined driver properties are erased from the property list. member_properties will serve as the file access property list for each member of the file family. memb_size specifies the logical size, in bytes, of each family member. memb_size is used only when creating a new file or truncating an existing file; otherwise the member size is determined by the size of the first member of the family being opened.

H5Pget_fapl_family is used to retrieve file family properties. If the file access property list is set to use the Family driver, member_properties will be returned with a pointer to a copy of the appropriate member access property list. If memb_size is non-null, it will contain the logical size, in bytes, of family members.

Additional parameters may be added to these functions in the future.

#### Unix Tools and an HDF5 Utility

It occasionally becomes necessary to repartition a file family. A command-line utility for this purpose, h5repart, is distributed with the HDF5 library.

h5repart [-v] [-b block_size[suffix]] [-m member_size[suffix]] source destination

h5repart repartitions an HDF5 file by copying the source file or file family to the destination file or file family, preserving holes in the underlying UNIX files. Families are used for the source and/or destination if the name includes a printf-style integer format such as d. The -v switch prints input and output file names on the standard error stream for progress monitoring, -b sets the I/O block size (the default is 1KB), and -m sets the output member size if the destination is a family name (the default is 1GB). block_size and member_size may be suffixed with the letters g, m, or k for GB, MB, or KB respectively.

The h5repart utility is described on the Tools page of the HDF5 Reference Manual.

An existing HDF5 file can be split into a family of files by running the file through split(1) on a UNIX system and numbering the output files. However, the HDF5 Library is lazy about extending the size of family members, so a valid file cannot generally be created by concatenation of the family members.

Splitting the file and rejoining the segments by concatenation (split(1) and cat(1) on UNIX systems) does not generate files with holes; holes are preserved only through the use of h5repart.

### The Multi Driver

In some circumstances, it is useful to separate metadata from raw data and some types of metadata from other types of metadata. Situations that would benefit from use of the Multi driver include the following:

- In networked situations where the small metadata files can be kept on local disks but larger raw data files must be stored on remote media
- In cases where the raw data is extremely large
- In situations requiring frequent access to metadata held in RAM while the raw data can be efficiently held on disk

In either case, access to the metadata is substantially easier with the smaller, and possibly more localized, metadata files. This often results in improved application performance.

The Multi driver, H5FD_MULTI, provides a mechanism for segregating raw data and different types of metadata into multiple files. The functions H5Pset_fapl_multi and H5Pget_fapl_multi are used to manage access properties for these multiple files. See the example below.

Managing access properties for multiple files

herr_t H5Pset_fapl_multi (hid_t fapl_id, const H5FD_mem_t *memb_map, const hid_t *memb_fapl,
const char * const *memb_name, const haddr_t *memb_addr,
bool relax)
herr_t H5Pget_fapl_multi (hid_t fapl_id, const H5FD_mem_t *memb_map, const hid_t *memb_fapl,
const char **memb_name, const haddr_t *memb_addr, bool *relax)
H5FD_mem_t
enum H5F_mem_t H5FD_mem_t
Definition H5FDpublic.h:273
haddr_t
uint64_t haddr_t
Definition H5public.h:372
H5Pset_fapl_multi
herr_t H5Pset_fapl_multi(hid_t fapl_id, const H5FD_mem_t *memb_map, const hid_t *memb_fapl, const char *const *memb_name, const haddr_t *memb_addr, bool relax)
Sets up use of the multi-file driver.
H5Pget_fapl_multi
herr_t H5Pget_fapl_multi(hid_t fapl_id, H5FD_mem_t *memb_map, hid_t *memb_fapl, char **memb_name, haddr_t *memb_addr, bool *relax)
Returns information about the multi-file access property list.

H5Pset_fapl_multi sets the file access properties to use the Multi driver; any previously defined driver properties are erased from the property list. With the Multi driver invoked, the application will provide a base name to H5Fopen or H5Fcreate. The files will be named by that base name as modified by the rule indicated in memb_name. File access will be governed by the file access property list memb_properties.

See H5Pset_fapl_multi and H5Pget_fapl_multi in the HDF5 Reference Manual for descriptions of these functions and their usage.

Additional parameters may be added to these functions in the future.

### The Split Driver

The Split driver is a limited case of the Multi driver where only two files are created. One file holds metadata, and the other file holds raw data. The function H5Pset_fapl_split is used to manage Split file access properties. See the example below.

Managing access properties for split files

herr_t H5Pset_fapl_split (hid_t access_properties, const char *meta_extension,
hid_t meta_properties,const char *raw_extension, hid_t raw_properties)
H5Pset_fapl_split
herr_t H5Pset_fapl_split(hid_t fapl, const char *meta_ext, hid_t meta_plist_id, const char *raw_ext, hid_t raw_plist_id)
Emulates the old split file driver.

H5Pset_fapl_split sets the file access properties to use the Split driver; any previously defined driver properties are erased from the property list.

With the Split driver invoked, the application will provide a base file name such as file_name to H5Fcreate or H5Fopen. The metadata and raw data files in storage will then be named file_name.meta_extension and file_name.raw_extension, respectively. For example, if meta_extension is defined as .meta and raw_extension is defined as .raw, the final filenames will be file_name.meta and file_name.raw.

Each file can have its own file access property list. This allows the creative use of other lowlevel file drivers. For instance, the metadata file can be held in RAM and accessed via the Memory driver while the raw data file is stored on disk and accessed via the POSIX driver. Metadata file access will be governed by the file access property list in meta_properties. Raw data file access will be governed by the file access property list in raw_properties.

Additional parameters may be added to these functions in the future. Since there are no additional variable settings associated with the Split driver, there is no H5Pget_fapl_split function.

### The ROS3 Driver

The ROS3 (read-only S3) driver is used to enable read-only access to HDF5 files which are stored in Amazon's S3 web service (https://aws.amazon.com/s3/) or an S3 API-compatible storage system. This driver expects that HDF5 files will be stored in the storage system as a single object. It translates I/O read requests from the HDF5 library into the appropriate REST API requests that will retrieve the relevant parts of the HDF5 file needed by the read requests.

The functions H5Pset_fapl_ros3 and H5Pget_fapl_ros3 are used to manage file access properties for the H5FD_ROS3 driver. See the example below.

Managing access properties for ROS3

herr_t H5Pset_fapl_ros3(hid_t access_properties, const H5FD_ros3_fapl_t *fa)
herr_t H5Pget_fapl_ros3(hid_t fapl_id, H5FD_ros3_fapl_t *fa_out)
typedef struct H5FD_ros3_fapl_t {
int32_t version;
bool authenticate;
char aws_region[H5FD_ROS3_MAX_REGION_LEN + 1];
char secret_id[H5FD_ROS3_MAX_SECRET_ID_LEN + 1];
char secret_key[H5FD_ROS3_MAX_SECRET_KEY_LEN + 1];
} H5FD_ros3_fapl_t;
H5FD_ROS3_MAX_SECRET_ID_LEN
#define H5FD_ROS3_MAX_SECRET_ID_LEN
Definition H5FDros3.h:58
H5FD_ROS3_MAX_SECRET_KEY_LEN
#define H5FD_ROS3_MAX_SECRET_KEY_LEN
Definition H5FDros3.h:64
H5FD_ROS3_MAX_REGION_LEN
#define H5FD_ROS3_MAX_REGION_LEN
Definition H5FDros3.h:52
H5Pset_fapl_ros3
herr_t H5Pset_fapl_ros3(hid_t fapl_id, const H5FD_ros3_fapl_t *fa)
Modifies the specified File Access Property List to use the H5FD_ROS3 driver.
H5Pget_fapl_ros3
herr_t H5Pget_fapl_ros3(hid_t fapl_id, H5FD_ros3_fapl_t *fa_out)
Queries a File Access Property List for H5FD_ROS3 file driver properties.
H5FD_ros3_fapl_t
Configuration structure for H5Pset_fapl_ros3() / H5Pget_fapl_ros3().
Definition H5FDros3.h:240
H5FD_ros3_fapl_t::secret_id
char secret_id[128+1]
Definition H5FDros3.h:244
H5FD_ros3_fapl_t::version
int32_t version
Definition H5FDros3.h:241
H5FD_ros3_fapl_t::aws_region
char aws_region[32+1]
Definition H5FDros3.h:243
H5FD_ros3_fapl_t::secret_key
char secret_key[128+1]
Definition H5FDros3.h:245
H5FD_ros3_fapl_t::authenticate
bool authenticate
Definition H5FDros3.h:242

H5Pset_fapl_ros3 sets the file access properties managed by the H5FD_ROS3 driver and H5Pget_fapl_ros3 retrieves those file access properties.

The version field is used to specify the revision of the H5FD_ros3_fapl_t structure and currently must always be set to the macro value H5FD_CURR_ROS3_FAPL_T_VERSION.

The authenticate field is a boolean determining whether or not the driver should use credentials specified in the secret_id and secret_key fields of the structure. If true, credentials will be used from the structure. If false, the driver will instead look for credentials from standard AWS environment variables, configuration files and other locations. In this case, any values specified in the secret_id and secret_key fields will be ignored.

The aws_region field is used to specify the AWS region to use when accessing files opened through the File Access Property List with these properties set on it. If this field is an empty string, the driver will search for a specified AWS region in the standard AWS environment variables and configuration files. An AWS region must be specified with one of these mechanisms or an error will be returned when attempting to open a file with the H5FD_ROS3 driver.

### The Parallel Driver

Parallel environments require a parallel low-level driver. HDF5's default driver for parallel systems is called the Parallel driver, H5FD_MPIO. This driver uses the MPI standard for both communication and file I/O.

The functions H5Pset_fapl_mpio and H5Pget_fapl_mpio are used to manage file access properties for the H5FD_MPIO driver. See the example below.

Managing parallel file access properties

herr_t H5Pset_fapl_mpio (hid_t fapl_id, MPI_Comm comm, MPI_info info)
herr_t H5Pget_fapl_mpio (hid_t fapl_id, MPI_Comm *comm, MPI_info *info)
H5Pget_fapl_mpio
herr_t H5Pget_fapl_mpio(hid_t fapl_id, MPI_Comm *comm, MPI_Info *info)
Returns MPI IO communicator information.
H5Pset_fapl_mpio
herr_t H5Pset_fapl_mpio(hid_t fapl_id, MPI_Comm comm, MPI_Info info)
Stores MPI IO communicator information to the file access property list.

The file access properties managed by H5Pset_fapl_mpio and retrieved by H5Pget_fapl_mpio are the MPI communicator, comm, and the MPI info object, info. comm and info are used for file open. info is an information object much like an HDF5 property list. Both are defined in MPI_FILE_OPEN of MPI.

The communicator and the info object are saved in the file access property list fapl_id. fapl_id can then be passed to MPI_FILE_OPEN to create and/or open the file.

H5Pset_fapl_mpio and H5Pget_fapl_mpio are available only in the parallel HDF5 Library and are not collective functions. The Parallel driver is available only in the parallel HDF5 Library.

Additional parameters may be added to these functions in the future.

## Code Examples for Opening and Closing Files

### Example Using the H5F_ACC_TRUNC Flag

The following example uses the H5F_ACC_TRUNC flag when it creates a new file. The default file creation and file access properties are also used. Using H5F_ACC_TRUNC means the function will look for an existing file with the name specified by the function. In this case, that name is FILE. If the function does not find an existing file, it will create one. If it does find an existing file, it will empty the file in preparation for a new set of data. The identifier for the "new" file will be passed back to the application program. For more information,

See also
  File Access Modes.

Creating a file with default creation and access properties

hid_t file; // identifier
// Create a new file using H5F_ACC_TRUNC access, default
// file creation properties, and default file access
// properties.
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
// Close the file.
status = H5Fclose(file);
H5F_ACC_TRUNC
#define H5F_ACC_TRUNC
Definition H5Fpublic.h:30

### Example with the File Creation Property List

The example below shows how to create a file with 64-bit object offsets and lengths.

Creating a file with 64-bit offsets

hid_t create_plist;
hid_t file_id;
create_plist = H5Pcreate(H5P_FILE_CREATE);
H5Pset_sizes(create_plist, 8, 8);
file_id = H5Fcreate(“test.h5”, H5F_ACC_TRUNC, create_plist, H5P_DEFAULT);
.
.
.
H5Fclose(file_id);
H5Pset_sizes
herr_t H5Pset_sizes(hid_t plist_id, size_t sizeof_addr, size_t sizeof_size)
Sets the byte size of the offsets and lengths used to address objects in an HDF5 file.

### Example with the File Access Property List

This example shows how to open an existing file for independent datasets access by MPI parallel I/O:

Opening an existing file for parallel I/O

hid_t access_plist;
hid_t file_id;
access_plist = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_mpi(access_plist, MPI_COMM_WORLD, MPI_INFO_NULL);
// H5Fopen must be called collectively
file_id = H5Fopen(“test.h5”, H5F_ACC_RDWR, access_plist);
.
.
.
// H5Fclose must be called collectively
H5Fclose(file_id);
H5F_ACC_RDWR
#define H5F_ACC_RDWR
Definition H5Fpublic.h:29

## Working with Multiple HDF5 Files

Multiple HDF5 files can be associated so that the files can be worked with as though all the information is in a single HDF5 file. A temporary association can be set up by means of the H5Fmount function. A permanent association can be set up by means of the external link function H5Lcreate_external.

The purpose of this section is to describe what happens when the H5Fmount function is used to mount one file on another.

When a file is mounted on another, the mounted file is mounted at a group, and the root group of the mounted file takes the place of that group until the mounted file is unmounted or until the files are closed.

The figure below shows two files before one is mounted on the other. File1 has two groups and three datasets. The group that is the target of the A link has links, Z and Y, to two of the datasets. The group that is the target of the B link has a link, W, to the other dataset. File2 has three groups and three datasets. The groups in File2 are the targets of the AA, BB, and CC links. The datasets in File2 are the targets of the ZZ, YY, and WW links.

Two separate files

The figure below shows the two files after File2 has been mounted File1 at the group that is the target of the B link.

File2 mounted on File1

Note: In the figure above, the dataset that is the target of the W link is not shown. That dataset is masked by the mounted file.

If a file is mounted on a group that has members, those members are hidden until the mounted file is unmounted. There are two ways around this if you need to work with a group member. One is to mount the file on an empty group. Another is to open the group member before you mount the file. Opening the group member will return an identifier that you can use to locate the group member.

The example below shows how H5Fmount might be used to mount File2 onto File1.

Using H5Fmount

status = H5Fmount(loc_id, "/B", child_id, plist_id)
H5Fmount
herr_t H5Fmount(hid_t loc_id, const char *name, hid_t child, hid_t plist)
Mounts an HDF5 file.

Note: In the code example above, loc_id is the file identifier for File1, /B is the link path to the group where File2 is mounted, child_id is the file identifier for File2, and plist_id is a property list identifier. For more information,

See also
  HDF5 Groups.

See the entries for H5Fmount, H5Funmount, and H5Lcreate_external in the HDF5 Reference Manual.

Previous Chapter The HDF5 Library and Programming Model - Next Chapter HDF5 Groups

Navigate back: Main / HDF5 User Guide