This tutorial will introduce the three levels of the HDF-Java products: the HDF-Java wrapper (or Java Native Interfaces to the standard HDF libraries), the HDF-Java object package, and the HDFView. The Java wrapper provides standard Java APIs that allow applications to call the C HDF libraries from Java. The HDF-Java object package implements HDF data objects, e.g. Groups and Datasets, in an object-oriented form and makes it easy for applications to use the libraries. The HDFView is a visual tool for browsing and editing HDF4 and HDF5 files.
4. Java Wrapper
Pure Java
Library
HDF
Java Native
Interface
a programming framework
that allows Java code to call
and be called by
applications and libraries
written in other languages
HDF
October 15-17, 2008
HDF and HDF-EOS Workshop XII
4
5. Pure Java Library
• Pros:
− True platform independence
− Direct access to file (no data
conversion between C and Java)
Pure Java
Library
• Cons:
HDF
October 15-17, 2008
− Substantial amount of work to
implement
− Hard to maintain (new features or
format changes)
HDF and HDF-EOS Workshop XII
5
6. HDF JNI
• Pros:
HDF
Java Native
Interface
HDF
October 15-17, 2008
− Easy to implement
− Easy to maintain
• Cons:
− Requires data conversion between C
and Java
− HDF JNI is platform dependent
HDF and HDF-EOS Workshop XII
6
8. Java Wrapper: C versus Java
hid_t H5Fcreate (
const char *name,
unsigned flags,
hid_t create_id,
hid_t access_id );
public static native int H5Fcreate (
String name,
int flags,
int create_id,
int access_id);
hid_t H5Fopen (
const char *name,
unsigned flags,
hid_t access_id );
public static native int H5Fopen (
String name,
int flags,
int access_id);
herr_t H5Fclose (
hid_t file_id );
public static native int H5Fclose (
int file_id);
C
October 15-17, 2008
Java
HDF and HDF-EOS Workshop XII
8
10. Java Wrapper: simple dataset read
int fid, did, sid, tid, rank;
long dims[], maxDims[];
Object theData;
fid = H5.H5Fopen( fname, HDF5Constants.H5F_ACC_RDWR,
did = H5.H5Dopen(fid, dname);
sid = H5.H5Dget_space(did);
tid = H5.H5Dget_type(did);
rank = H5.H5Sget_simple_extent_ndims(sid);
HDF5Constants.H5P_DEFAULT );
dims = new long[rank];
maxDims = new long[rank];
H5.H5Sget_simple_extent_dims(sid, dims, maxDims);
theData = allocateArray(tid, dims);
H5.H5Dread( did, tid, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, theData);
H5.H5Sclose(sid);
H5.H5Tclose(tid);
H5.H5Dclose(did);
H5.H5Fclose(fid);
October 15-17, 2008
HDF and HDF-EOS Workshop XII
10
11. Object Package: the easy way
theData = Dataset.read();
October 15-17, 2008
HDF and HDF-EOS Workshop XII
11
12. Object Package: main purposes
• Simplifies access to HDF files
• Separates applications from libraries
− Modular design
− Client server model
• Makes testing and maintenance easy
October 15-17, 2008
HDF and HDF-EOS Workshop XII
12
13. Object Package: levels of objects
Abstract classes
Implementation
October 15-17, 2008
Common Objects
ncsa.hdf.object
jhdfobj.jar
HDF4
ncsa.hdf.object.h4
jhdf4obj.jar
HDF and HDF-EOS Workshop XII
HDF5
ncsa.hdf.object.h5
jhdf5obj.jar
13
14. Object Package: abstract classes
FileFormat
HObject
Dataset
Group
ScalarDS
October 15-17, 2008
HDF and HDF-EOS Workshop XII
CompoundDS
14
15. Object Package: HDF4 implementation
Group
H4Group
ScalarDS
H4SDS
H4GRImage
CompounDS
H4Vdata
H4File
FileFormat
October 15-17, 2008
HDF and HDF-EOS Workshop XII
15
16. Object Package: HDF5 implementation
Group
ScalarDS
H5Group
H5ScalarDS
CompounDS
H5CompoundDS
H5File
FileFormat
October 15-17, 2008
HDF and HDF-EOS Workshop XII
16
17. Object Package: file create
import ncsa.hdf.object.*;
public class H5FileCreate
{
private static String fname = "H5FileCreate.h5";
public static void main( String args[] ) throws Exception
{
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
fileFormat.createFile(fname, FileFormat.FILE_CREATE);
}
}
October 15-17, 2008
HDF and HDF-EOS Workshop XII
17
22. What are the HDF-Java products?
HDF-Java
HDF
Java
Wrapper
October 15-17, 2008
Object
Package
HDF and HDF-EOS Workshop XII
Viewer
Editor
22
23. Thank You!
This report is based upon work supported in part by a Cooperative
Agreement with the National Aeronautics and Space Administration (NASA)
under NASA Awards NNX06AC83A and NNX08AO77A. Any opinions,
findings, and conclusions or recommendations expressed in this material are
those of the author(s) and do not necessarily reflect the views of the National
Aeronautics and Space Administration.
October 15-17, 2008
HDF and HDF-EOS Workshop XII
23