HDF5
1.15.0.f39b228
API Reference
|
Navigate back: Main / Getting Started with HDF5 / Learning the Basics
Attributes are small datasets that can be used to describe the nature and/or the intended usage of the object they are attached to. In this section, we show how to create, read, and write an attribute.
Creating an attribute is similar to creating a dataset. To create an attribute, the application must specify the object which the attribute is attached to, the datatype and dataspace of the attribute data, and the attribute creation property list.
The steps to create an attribute are as follows:
To create and close an attribute, the calling program must use H5Acreate and H5Aclose. For example:
C
Fortran
Attributes may only be read or written as an entire object; no partial I/O is supported. Therefore, to perform I/O operations on an attribute, the application needs only to specify the attribute and the attribute's memory datatype.
The steps to read or write an attribute are as follows.
To read and/or write an attribute, the calling program must contain the H5Aread and/or H5Awrite routines. For example:
C
Fortran
The High Level HDF5 Lite APIs (H5LT,H5LD) include functions that simplify and condense the steps for creating and reading datasets. Please be sure to review them, in addition to this tutorial.
See Examples from Learning the Basics for the examples used in the Learning the Basics tutorial.
The example shows how to create and write a dataset attribute. It opens an existing file dset.h5
in C (dsetf.h5
in FORTRAN), obtains the identifier of the dataset /dset
, defines the attribute's dataspace, creates the dataset attribute, writes the attribute, and then closes the attribute's dataspace, attribute, dataset, and file.
For details on compiling an HDF5 application: [ Compiling HDF5 Applications ]
H5Acreate creates an attribute which is attached to the object specified by the first parameter, and returns an identifier.
H5Awrite writes the entire attribute, and returns the status of the write.
When an attribute is no longer accessed by a program, H5Aclose must be called to release the attribute from use. An H5Aclose/h5aclose_f call is mandatory.
Shown below is the contents and the attribute definition of dset.h5
(created by the C program).
dset.h5 in DDL
Shown below is the contents and the attribute definition of dsetf.h5
(created by the FORTRAN program).
dsetf.h5 in DDL
HDF5 Attribute Definition
Navigate back: Main / Getting Started with HDF5 / Learning the Basics