During a dataset I/O operation, the library transfers raw data between memory and the file. The memory can have a data type different than the file data type and can also be a different size (memory is a subset of the dataset elements, or vice versa). Therefore, to perform read or write operations, the application program must specify:
The steps to read to/write from a dataset are as follows:
H5Dread(dataset_id, mem_type_id, mem_space_id, file_space_id,
xfer_plist_id, buf );
or
H5Dwrite(dataset_id, mem_type_id, mem_space_id, file_space_id,
xfer_plist_id, buf);
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <hdf5.h>
#define FILE "dset.h5"
main() {
hid_t file_id, dataset_id; /* identifiers */
herr_t status;
int i, j, dset_data[4][6];
/* Initialize the dataset. */
for (i = 0; i < 4; i++)
for (j = 0; j < 6; j++)
dset_data[i][j] = i * 6 + j + 1;
/* Open an existing file. */
file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open an existing dataset. */
dataset_id = H5Dopen(file_id, "/dset");
/* Write the dataset. */
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset_data);
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
dset_data);
/* Close the dataset. */
status = H5Dclose(dataset_id);
/* Close the file. */
status = H5Fclose(file_id);
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hid_t H5Fopen (const char *name, unsigned flags, hid_t access_id)
hid_t H5Dopen (hid_t loc_id, const char *name)
herr_t H5Dwrite (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t xfer_plist_id, const void * buf)
herr_t H5Dread (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id,
hid_t file_space_id, hid_t xfer_plist_id, void * buf)
Fig. 6.1 'dset.h5' in DDL
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
}
}
}
}