/** @page LBFileOrg HDF5 File Organization Navigate back: \ref index "Main" / \ref GettingStarted / \ref LearnBasics
/
signifies the root group.
\li /foo
signifies a member of the root group called foo.
\li /foo/zoo
signifies a member of the group foo, which in turn is a member of the root group.
Navigate back: \ref index "Main" / \ref GettingStarted / \ref LearnBasics
@page LBAPI The HDF5 API
Navigate back: \ref index "Main" / \ref GettingStarted / \ref LearnBasics
API | DESCRIPTION |
---|---|
H5 | Library Functions: general-purpose H5 functions |
H5A | Annotation Interface: attribute access and manipulation routines |
H5D | Dataset Interface: dataset access and manipulation routines |
H5E | Error Interface: error handling routines |
H5F | File Interface: file access routines |
H5G | Group Interface: group creation and operation routines |
H5I | Identifier Interface: identifier routines |
H5L | Link Interface: link routines |
H5O | Object Interface: object routines |
H5P | Property List Interface: object property list manipulation routines |
H5R | Reference Interface: reference routines |
H5S | Dataspace Interface: dataspace definition and access routines |
H5T | Datatype Interface: datatype creation and manipulation routines |
H5Z | Compression Interface: compression routine(s) |
File Interface: | #H5Fopen |
Dataset Interface: | #H5Dopen |
File Interface: | h5fopen_f |
Dataset Interface: | h5dopen_f |
File Interface: | H5.H5Fopen |
Dataset Interface: | H5.H5Dopen |
"import h5py / import numpy"
"#include hdf5.h"
"USE HDF5"
and call h5open_f and h5close_f to initialize and close the HDF5 FORTRAN interface
"import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;"
hdf5.h
contains definitions and declarations and must be included
in any program that uses the HDF5 library.
HDF5
contains definitions and declarations and must be used in any
program that uses the HDF5 library. Also note that #H5open MUST be called at the beginning of an HDF5 Fortran
application (prior to any HDF5 calls) to initialize the library and variables. The #H5close call MUST be at
the end of the HDF5 Fortran application.
\li #H5Fcreate creates an HDF5 file and returns the file identifier./
.
\li #H5Fclose terminates access to an HDF5 file.h5dump
, which displays the file contents in human-readable form. The output of h5dump
is an ASCII
display formatted according to the HDF5 DDL grammar. This grammar is defined, using Backus-Naur Form, in the
\ref DDLBNF114.
To view the HDF5 file contents, simply type:
\code
h5dump \image html imgLBFile.gif |
file.h5
, as generated by h5dump
. The HDF5 file called file.h5
contains a group called /
, or the root group. (The file called filef.h5
, created by the FORTRAN version of the example,
has the same output except that the filename shown is filef.h5
.)
\code
HDF5 "file.h5" {
GROUP "/" {
}
}
\endcode
\subsection subsecLBFileExampleDDL File Definition in DDL
The simplified DDL file definition for creating an HDF5 file. For simplicity, a simplified DDL is used in this tutorial. A
complete and more rigorous DDL can be found in the \ref DDLBNF114.
The following symbol definitions are used in the DDL:
\code
::= defined as
Datatype | Description |
---|---|
H5T_STD_I32LE | Four-byte, little-endian, signed, two's complement integer |
H5T_STD_U16BE | Two-byte, big-endian, unsigned integer |
H5T_IEEE_F32BE | Four-byte, big-endian, IEEE floating point |
H5T_IEEE_F64LE | Eight-byte, little-endian, IEEE floating point |
H5T_C_S1 | One-byte, null-terminated string of eight-bit characters |
Native Datatype | Corresponding C or FORTRAN Type |
---|---|
C | |
H5T_NATIVE_INT | int |
H5T_NATIVE_FLOAT | float |
H5T_NATIVE_CHAR | char |
H5T_NATIVE_DOUBLE | double |
H5T_NATIVE_LDOUBLE | long double |
Fortran | |
H5T_NATIVE_INTEGER | integer |
H5T_NATIVE_REAL | real |
H5T_NATIVE_DOUBLE | double precision |
H5T_NATIVE_CHARACTER | character |
dset.h5
in the C version (dsetf.h5
in Fortran), defines the dataset dataspace, creates a
dataset which is a 4x6 integer array, and then closes the dataspace, the dataset, and the file.
For details on compiling an HDF5 application: [ \ref LBCompiling ]
\subsection subsecLBDsetCreateProgRem Remarks
#H5Screate_simple creates a new simple dataspace and returns a dataspace identifier.
#H5Sclose releases and terminates access to a dataspace.
C
\code
dataspace_id = H5Screate_simple (rank, dims, maxdims);
status = H5Sclose (dataspace_id );
\endcode
FORTRAN
\code
CALL h5screate_simple_f (rank, dims, dataspace_id, hdferr, maxdims=max_dims)
or
CALL h5screate_simple_f (rank, dims, dataspace_id, hdferr)
CALL h5sclose_f (dataspace_id, hdferr)
\endcode
#H5Dcreate creates an empty dataset at the specified location and returns a dataset identifier.
#H5Dclose closes the dataset and releases the resource used by the dataset. This call is mandatory.
C
\code
dataset_id = H5Dcreate(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Dclose (dataset_id);
\endcode
FORTRAN
\code
CALL h5dcreate_f (loc_id, name, type_id, dataspace_id, dset_id, hdferr)
CALL h5dclose_f (dset_id, hdferr)
\endcode
Note that if using the pre-defined datatypes in FORTRAN, then a call must be made to initialize and terminate access to the pre-defined datatypes:
\code
CALL h5open_f (hdferr)
CALL h5close_f (hdferr)
\endcode
H5open must be called before any HDF5 library subroutine calls are made;
H5close must be called after the final HDF5 library subroutine call.
See the programming example for an illustration of the use of these calls.
\subsection subsecLBDsetCreateContent File Contents
The contents of the file dset.h5 (dsetf.h5 for FORTRAN) are shown below:
\image html imgLBDsetCreate.gif |
dset.h5 in DDL | dsetf.h5 in DDL |
---|---|
\code HDF5 "dset.h5" { GROUP "/" { DATASET "dset" { DATATYPE { H5T_STD_I32BE } DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) } DATA { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } } } \endcode | \code HDF5 "dsetf.h5" { GROUP "/" { DATASET "dset" { DATATYPE { H5T_STD_I32BE } DATASPACE { SIMPLE ( 6, 4 ) / ( 6, 4 ) } DATA { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } } } \endcode |
/dset
, writes the dataset to the file, then reads
the dataset back. It then closes the dataset and file.
Note that #H5S_ALL is passed in for both the memory and file dataspace parameters in the read and write calls.
This indicates that the entire dataspace of the dataset will be read or written to. #H5S_ALL by itself does not
necessarily have this meaning. See the \ref RM entry for #H5Dread or #H5Dwrite for more information on using #H5S_ALL.
For details on compiling an HDF5 application:
[ \ref LBCompiling ]
\subsection secLBDsetRWExRem Remarks
#H5Fopen opens an existing file and returns a file identifier.
#H5Dopen opens an existing dataset with the specified name and location.
#H5Dwrite writes raw data from an application buffer to the specified dataset, converting from the datatype and
dataspace of the dataset in memory to the datatype and dataspace of the dataset in the file. Specifying #H5S_ALL
for both the memory and file dataspaces indicates that the entire dataspace of the dataset is to be written to.
#H5S_ALL by itself does not necessarily have this meaning. See the \ref RM entry for #H5Dwrite for more information
on using #H5S_ALL.
#H5Dread reads raw data from the specified dataset to an application buffer, converting from the file datatype and
dataspace to the memory datatype and dataspace. Specifying #H5S_ALL for both the memory and file dataspaces
indicates that the entire dataspace of the dataset is to be read. #H5S_ALL by itself does not necessarily have
this meaning. See the \ref RM entry for #H5Dread for more information on using #H5S_ALL.
\subsection secLBDsetRWExCont File Contents
Shown below is the contents of dset.h5 (created by the C program).
dset.h5 in DDL
\code
HDF5 "dset.h5" {
GROUP "/" {
DATASET "dset" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) }
DATA {
1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24
}
}
}
}
\endcode
Shown below is the contents of dsetf.h5 (created by the FORTRAN program).
dsetf.h5 in DDL
\code
HDF5 "dsetf.h5" {
GROUP "/" {
DATASET "dset" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 6, 4 ) / ( 6, 4 ) }
DATA {
1, 7, 13, 19,
2, 8, 14, 20,
3, 9, 15, 21,
4, 10, 16, 22,
5, 11, 17, 23,
6, 12, 18, 24
}
}
}
}
\endcode
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:
[ \ref LBCompiling ]
\subsection secLBAttrCreateRWExRem Remarks
#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.
\subsection secLBAttrCreateRWExCont File Contents
Shown below is the contents and the attribute definition of dset.h5
(created by the C program).
dset.h5 in DDL
\code
HDF5 "dset.h5" {
GROUP "/" {
DATASET "dset" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 4, 6 ) / ( 4, 6 ) }
DATA {
1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24
}
ATTRIBUTE "attr" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 2 ) / ( 2 ) }
DATA {
100, 200
}
}
}
}
}
\endcode
Shown below is the contents and the attribute definition of dsetf.h5
(created by the FORTRAN program).
dsetf.h5 in DDL
\code
HDF5 "dsetf.h5" {
GROUP "/" {
DATASET "dset" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 6, 4 ) / ( 6, 4 ) }
DATA {
1, 7, 13, 19,
2, 8, 14, 20,
3, 9, 15, 21,
4, 10, 16, 22,
5, 11, 17, 23,
6, 12, 18, 24
}
ATTRIBUTE "attr" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 2 ) / ( 2 ) }
DATA {
100, 200
}
}
}
}
}
\endcode
\subsection secLBAttrCreateRWExDDL Attribute Definition in DDL
HDF5 Attribute Definition
\code