18.3.1 Reading from a RESQML HDF5 File
|For Standard||RESQML v2.0.1|
Reading data from an HDF5 file involves these steps:
(i) Open the file
(ii) Open the dataset and read the data
(iii) Close the file
- Open a RESQML HDF5 File
To open a RESQML HDF5 file, use the H5Fopen function from the H5F family of functions. Many options are available, but this example shows how to open a file for reading only.
hid_t FileID = H5Fopen(_FileNameH5F_ACC_RDONLY, H5P_DEFAULT);
- Open a Dataset and Read Data
Reading data from a Dataset involves a number of steps: (i) open the hierarchical groups containing the Dataset, (ii) open the Dataset, (iii) get the Dataspace information to determine the rank and dimensions of the data in the Dataset, (iv) read the data, and (v) close all the handles when done.
The path to the Dataset—including the groups it is contained in—is provided in the XML file. This path may be broken into group components, and each of these groups may be opened in turn. Alternatively, the complete path information may be passed to the dataset-opening function. This sample opens the dataset directly using the complete path information.
hid_t DatasetID = H5Dopen2(FileID, DatasetName, H5P_DEFAULT);
After the Dataset is open, you may query the Dataspace to get information on the rank and dimensions of the data. This information is usually also contained in the RESQML XML file, but you may still want to read it from the HDF5 file to verify the integrity of the file.
hid_t DataspaceID = H5Dget_space(DatasetID);int ndims = H5Sget_simple_extent_ndims(DataspaceID);if (ndims == ExpectedDimensionsRank)ndims = H5Sget_simple_extent_dims(DataspaceID, Dimensions, NULL);
Reading the data may be done all at once or in pieces called hyperslabs. Reading using hyperslabs can be more efficient in terms of memory usage, but for clarity the sample below reads all data into a memory buffer at once.
herr_t e = H5Dread(DatasetID, TypeID, H5S_ALL, H5S_ALL, H5P_DEFAULT, Buffer);