NCSA

[ HDF5 Tutorial Top ]

Creating an HDF5 file


Contents:


What is an HDF5 file?

An HDF5 file is a binary file which contains scientific data and supporting metadata. The two primary objects stored in an HDF5 file are groups and datasets. Groups and datasets will be discussed in the other sessions.

To create a file, the program application must specify a file name, file access mode, file creation property list, and file access property list.

The steps to create and close an HDF5 file are as follows:

  1. Specify the file creation and access property lists if necessary.
  2. Create a file.
  3. Close the file and close the property lists if necessary.
To create an HDF5 file, the calling program must contain the following calls:
   file_id = H5Fcreate(filename, access_mode, create_id, access_id);

   H5Fclose(file_id); 

Programming Example

Description

The following example demonstrates how to create and close an HDF5 file. It creates a file called 'file.h5', and then closes the file.
[
Download h5_crtfile.c ]
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


#include <hdf5.h>
#define FILE "file.h5"

main() {

   hid_t       file_id;   /* file identifier */
   herr_t      status;

   /* Create a new file using default properties. */
   file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);

   /* Terminate access to the file. */
   status = H5Fclose(file_id); 
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Remarks

File Contents

HDF has developed tools to examine the contents of HDF5 files. The tool used in this tutorial is the HDF5 dumper, h5dump. h5dump is a tool that displays the file contents in human readable form to an ASCII file in DDL. DDL (Data Description Language) is a language that describes HDF5 objects in Backus-Naur Form. To view the file contents, type:
   h5dump <filename> 
Figure 4.1 describes the file contents of 'file.h5' using a directed graph. Each HDF5 object is represented by a rectangle and the arrows indicate the structure of the contents. In Fig. 4.2, 'file.h5' contains a group object named '/' (the root group).

Fig. 4.1   Contents of 'file.h5'


Figure 4.2 is the text-description of 'file.h5' generated by h5dump. The HDF5 file called 'file.h5' contains a group called '/'.

Fig. 4.2   'file.h5' in DDL


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

File Definition in DDL

Figure 4.3 is 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 HDF5 User's Guide. See the
References section of this tutorial.

Fig. 4.3   HDF5 File Definition

The explanation of the symbols used in the DDL:


        ::=               defined as
        <tname>           a token with the name tname
        <a> | <b>         one of <a> or <b>
        <a>*              zero or more occurrences of <a>
The simplified DDL file definition:
        <file> ::= HDF5 "<file_name>" { <root_group> }

        <root_group> ::= GROUP "/" { <group_attribute>* <group_member>* }

        <group_attribute> ::= <attribute>

        <group_member> ::= <group> | <dataset>


NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

hdfhelp@ncsa.uiuc.edu
Last Modified: August 27, 1999