hdf images hdf images

HDF5 Tutorial:   Learning The Basics
Reading from or Writing to a Subset of a Dataset

Contents:


Reading from or Writing to a Subset of a Dataset

HDF5 allows you to read from or write to a portion or subset of a dataset. This is done by selecting a subset of the dataspace of the dataset, and then using that selection to read from or write to the dataset. There are two types of selections in HDF5, hyperslab selections and element selections, specified with the H5Sselect_hyperslab / h5sselect_hyperslab_f and H5Sselect_elements /h5sselect_elements_f calls, respectively:

This tutorial topic shows how to write to a simple subset of data in a dataset and describes how to experiment with different shapes and sizes of subsets to write. It also includes an example of reading blocks of data from the dataset.

See the Advanced Tutorial topics for a more complex example and an example of using element selection.

Programming Example

Description

This example creates an 8 x 10 integer dataset in an HDF5 file. It then selects and writes to a 3 x 4 subset of the dataset created with Dimension 0 offset by 1 and Dimension 1 offset by 2. (In this discussion, Dimension 0 is vertical, and Dimension 1 is horizontal.) The following table shows the dataset that gets written originally, and the subset of data that gets modified afterwards.

    Contents of Original 
      Dataset Created
  Contents of Dataset After
  3 x 4 Subset Written
  1 1 1 1 1 2 2 2 2 2   
  1 1 1 1 1 2 2 2 2 2
  1 1 1 1 1 2 2 2 2 2
  1 1 1 1 1 2 2 2 2 2
  1 1 1 1 1 2 2 2 2 2
  1 1 1 1 1 2 2 2 2 2
  1 1 1 1 1 2 2 2 2 2
  1 1 1 1 1 2 2 2 2 2
 1 1 1 1 1 2 2 2 2 2  
 1 1 5 5 5 5 2 2 2 2
 1 1 5 5 5 5 2 2 2 2
 1 1 5 5 5 5 2 2 2 2
 1 1 1 1 1 2 2 2 2 2
 1 1 1 1 1 2 2 2 2 2
 1 1 1 1 1 2 2 2 2 2
 1 1 1 1 1 2 2 2 2 2

To obtain the example, download: