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
Creating an Group

Navigate back: Main / Getting Started with HDF5 / Learning the Basics

# Creating an group

An HDF5 group is a structure containing zero or more HDF5 objects. The two primary HDF5 objects are groups and datasets. To create a group, the calling program must:

1. Obtain the location identifier where the group is to be created.
2. Create the group.
3. Close the group.

To create a group, the calling program must call H5Gcreate. To close the group, H5Gclose must be called. The close call is mandatory.

For example:

C

group_id = H5Gcreate(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
status = H5Gclose (group_id);
H5P_DEFAULT
#define H5P_DEFAULT
Definition H5Ppublic.h:220
H5Gcreate
#define H5Gcreate
Definition H5version.h:1324
H5Gclose
herr_t H5Gclose(hid_t group_id)
Closes the specified group.

Fortran

CALL h5gcreate_f (loc_id, name, group_id, error)
CALL h5gclose_f (group_id, error)

# Programming Example

## Description

See Examples from Learning the Basics for the examples used in the Learning the Basics tutorial.

The example shows how to create and close a group. It creates a file called `group.h5` in C (`groupf.h5` for FORTRAN), creates a group called MyGroup in the root group, and then closes the group and file.

For details on compiling an HDF5 application: [ Compiling HDF5 Applications ]

## File Contents

Shown below is the contents and the definition of the group of `group.h5` (created by the C program). (The FORTRAN program creates the HDF5 file `groupf.h5` and the resulting DDL shows the filename `groupf.h5` in the first line.)

The Contents of group.h5.

group.h5 in DDL

HDF5 "group.h5" {
GROUP "/" {
GROUP "MyGroup" {
}
}
}

Previous Chapter Creating an Attribute - Next Chapter Creating Groups using Absolute and Relative Names

Navigate back: Main / Getting Started with HDF5 / Learning the Basics