### HDF 5 Tutorial Examples in Java

These files are Java versions of the example programs used in the HDF-5 tutoral:
http://hdf.ncsa.uiuc.edu/training/hdf5/

The examples here correspond to the examples explained in the first 13 sections of the tutorial.

Lesson | Topic | C file | Java file
Lesson 4 | Create an HDF-5 file. | h5_crtfile.c | CreateFile.java
Lesson 5 | Create a Dataset in an HDF-5 file | h5_crtdat.c | CreateDataset.java
Lesson 6 | Write and Read data in a dataset | h5_rdwt.c | DatasetRdWt.java
Lesson 7 | Create an attribute. | h5_crtatt.c | CreateAttribute.java
Lesson 8 | Create a group. | h5_crtgrp.c | CreateGroup.java
Lesson 9 | Using Absolute and relative paths | h5_crtgrpar.c | CreateGroupAR.java
Lesson 10 | Create a dataset in a group. | h5_crtgrpd.c | CreateGroupDataset.java
Lesson 11 | Using Compound Datatypes | h5_compound.c | Compound.java
Lesson 12 | Selection of a hyperslab. | h5_hyperslab.c | Hyperslab.java
Lesson 13 | Selection of elements. | h5_copy.c | Copy.java

Some Explanation About Tutorial Examples

The Java tutorial programs try to stay close to the corresponding C program. The main function's structure almost same as C program, with one call for each HDF5 library function. For example, where the C program has a call to H5Fopen(), the Java program has a call to H5Fopen_wrap().

The wrapper functions call the HDF-5 library using the Java HDF-5 Interface (JHI5). The HDF-5 C interface returns error codes; these are represented by Java Exceptions in the JHI5. The wrapper function catches the exception and prints a message.

For example, the H5Fopen_wrap() method calls the JHI5, and catches any exceptions which may occur:

       public static int H5Fopen_wrap (String name, int flags, int access_id)
       {
          int file_id = -1;    // file identifier
          try
          {
             // Create a new file using default file properties.
             file_id = H5.H5Fopen (name, flags, access_id);
          }
          catch (HDF5Exception hdf5e)
          {
             System.out.println
                 ("DatasetRdWt.H5Fopen_wrap() with HDF5Exception: "
                  + hdf5e.getMessage());
          }
          catch (Exception e)
          {
             System.out.println
                 ("DatasetRdWt.H5Fopen_wrap() with other Exception: "
                  + e.getMessage());
          }
          return file_id;
       }

The National Center for Supercomputing Applications
University of Illinois at Urbana-Champaign

hdfhelp@ncsa.uiuc.edu