[ HDF5 Tutorial Top ]

References to Dataset Regions


Contents:


References to Dataset Regions

Previously you learned about creating, reading, and writing dataset selections. Here you will learn how to store dataset selections in a file, and how to read them back using references to dataset regions.

A dataset region reference points to the dataset selection by storing the relative file address of the dataset header and the global heap offset of the referenced selection. The selection referenced is located by retrieving the coordinates of the areas in the selection from the global heap. This internal mechanism of storing and retrieving dataset selections is transparent to the user. A reference to a dataset selection (a region) is constant for the life of the dataset.

Creating and Storing References to Dataset Regions

The following steps are involved in creating and storing references to dataset regions:
  1. Create a dataset in which to store the dataset regions (the selections).

  2. Create selections in the dataset(s). The dataset(s) should already exist in the file.

  3. Create references to the selections and store them in a buffer.

  4. Write the dataset region references to the file.

  5. Close all objects.

Reading References to Dataset Regions

The following steps are involved in reading references to dataset regions and referenced dataset regions (selections).
  1. Open and read the dataset containing references to the dataset regions. The datatype H5T_STD_REF_DSETREG must be used during the read operation.

  2. Use H5Rdereference / h5rdeference_f to obtain the dataset identifier from the read dataset region reference. OR Use H5Rget_region / h5rget_region_f to obtain the dataspace identifier for the dataset containing the selection from the read dataset region reference.

  3. Obtain information about the selection or read selected data from the dataset.

  4. Close all objects when they are no longer needed.

Programming Example

Description

The example below first creates a dataset in the file. Then it creates a dataset to store references to the dataset regions (selections). The first selection is a 6 x 6 hyperslab. The second selection is a point selection in the same dataset. References to both selections are created and stored in the buffer and then written to the dataset in the file.

After creating the dataset and references, the program reads the dataset containing the dataset region references. It reads data from the dereferenced dataset and displays the number of elements and raw data. Then it reads two selections, a hyperslab selection and a point selection. The program queries a number of points in the hyperslab and their coordinates and displays them. Then it queries a number of selected points and their coordinates and displays the information.

To obtain the example, download:

NOTE: To download a tar file of the examples, including a Makefile, please go to the References page.

Following is the output from the examples:

Output of C Example

Selected hyperslab: 
0 0 0 3 3 4 0 0 0 
0 0 0 3 4 4 0 0 0 
Selected points: 
1 0 0 0 0 0 0 0 6 
0 0 0 0 0 0 5 0 0 
Output of FORTRAN Example
 Hyperslab selection

 3*0,  2*3,  4,  3*0
 3*0,  3,  2*4,  3*0

 Point selection

 1,  7*0,  6
 6*0,  5,  2*0

Remarks

File Contents

HDF5 File Created by C Example

Fig. A   REF_REG.h5 in DDL


HDF5 "REF_REG.h5" {
GROUP "/" {
   DATASET "MATRIX" {
      DATATYPE { H5T_STD_I32BE }
      DATASPACE { SIMPLE ( 2, 9 ) / ( 2, 9 ) }
      DATA {
         1, 1, 2, 3, 3, 4, 5, 5, 6,
         1, 2, 2, 3, 4, 4, 5, 6, 6
      }
   }
   DATASET "REGION_REFERENCES" {
      DATATYPE { H5T_REFERENCE }
      DATASPACE { SIMPLE ( 2 ) / ( 2 ) }
      DATA {
         DATASET 0:744 {(0,3)-(1,5)}, DATASET 0:744 {(0,0), (1,6), (0,8)}
      }
   }
}
}

HDF5 File Created by FORTRAN Example:

Fig. B   FORTRAN.h5 in DDL


HDF5 "FORTRAN.h5" {
GROUP "/" {
   DATASET "MATRIX" {
      DATATYPE { H5T_STD_I32BE }
      DATASPACE { SIMPLE ( 9, 2 ) / ( 9, 2 ) }
      DATA {
         1, 1,
         1, 2,
         2, 2,
         3, 3,
         3, 4,
         4, 4,
         5, 5,
         5, 6,
         6, 6
      }
   }
   DATASET "REGION_REFERENCES" {
      DATATYPE { H5T_REFERENCE }
      DATASPACE { SIMPLE ( 2 ) / ( 2 ) }
      DATA {
         DATASET 0:744 {(3,0)-(5,1)}, DATASET 0:744 {(0,0), (6,1), (8,0)}
      }
   }
}
}
Notice how the raw data in the dataset with the dataset regions is displayed. Each element of the raw data consists of a reference to the dataset (DATASET number1:number2) and its selected region. If the selection is a hyperslab, the corner coordinates of the hyperslab are displayed. For the point selection, the coordinates of each point are displayed.


NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

hdfhelp@ncsa.uiuc.edu

Last Modified: June 22, 2001