Please, help us to better serve our user community by answering the following short survey: https://www.hdfgroup.org/website-survey/
HDF5  1.15.0
API Reference
 
Loading...
Searching...
No Matches
Creating Datasets in Groups

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


Datasets in Groups

We have shown how to create groups, datasets, and attributes. In this section, we show how to create datasets in groups. Recall that H5Dcreate creates a dataset at the location specified by a location identifier and a name. Similar to H5Gcreate, the location identifier can be a file identifier or a group identifier and the name can be relative or absolute. The location identifier and the name together determine the location where the dataset is to be created. If the location identifier and name refer to a group, then the dataset is created in that group.

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 a dataset in a particular group. It opens the file created in the previous example and creates two datasets:

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

File Contents

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

The contents of the file groups.h5 (groupsf.h5 for FORTRAN)

groups.h5 in DDL

HDF5 "groups.h5" {
GROUP "/" {
GROUP "MyGroup" {
GROUP "Group_A" {
DATASET "dset2" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 2, 10 ) / ( 2, 10 ) }
DATA {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
}
}
}
GROUP "Group_B" {
}
DATASET "dset1" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 3, 3 ) / ( 3, 3 ) }
DATA {
1, 2, 3,
1, 2, 3,
1, 2, 3
}
}
}
}
}
#define H5T_STD_I32BE
Definition H5Tpublic.h:305

groupsf.h5 in DDL

HDF5 "groupsf.h5" {
GROUP "/" {
GROUP "MyGroup" {
GROUP "Group_A" {
DATASET "dset2" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 10, 2 ) / ( 10, 2 ) }
DATA {
1, 1,
2, 2,
3, 3,
4, 4,
5, 5,
6, 6,
7, 7,
8, 8,
9, 9,
10, 10
}
}
}
GROUP "Group_B" {
}
DATASET "dset1" {
DATATYPE { H5T_STD_I32BE }
DATASPACE { SIMPLE ( 3, 3 ) / ( 3, 3 ) }
DATA {
1, 1, 1,
2, 2, 2,
3, 3, 3
}
}
}
}
}

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