Main navigation

How to use the HDF and HDF5 Libraries

Installed location:

  • HDF4 is installed in: /u/local/apps/hdf/current
  • HDF5 is installed in: /u/local/apps/hdf5/current

How to run HDF4 from a C program

In your program include the appropriate HDF header files and call the: appropriate HDF functions.

To compile and link enter:

gcc pgm.c -I$HDF_HOME/include -L$HDF_HOME/lib -lmfhdf -ldf -ljpeg -lz -o pgm

  • Replace pgm.c with the name of the file containing your source code
  • Replace pgm with the name of the executable to be created
  • Set HDF_HOME /u/local/apps/hdf/current

If you omit -static, you will have to set the LD_LIBRARY_PATH environment variable at run time to include $HDF_HOME/lib.

You can either set an environment variable or replace $HDF_HOME in the command shown above.

How to run HDF4 from a Fortran program

In your program include the appropriate HDF header files and call the appropriate HDF functions.

To compile and link enter:

ifort pgm.f90 -I$HDF_HOME/include -L$HDF_HOME/lib -lmfhdf -ldf -ljpeg -lz -o pgm

  • Replace pgm.f90 with the name of the file containing your source code
  • Replace pgm with the name of the executable to be created
  • Set HDF_HOME /u/local/apps/hdf/current

You can either set an environment variable or replace $HDF_HOME in the command shown above.

See also http://www.hdfgroup.org/training/HDFtraining/tutorial/compile.html compiling instructions from the HDF group.

An exmaple of compiling http://www.hdfgroup.org/training/HDFtraining/examples/sd_create.f” on the Hoffman2 Cluster:

$ ifort sd_create.f -L/u/local/apps/hdf/current/lib -lmfhdf -ldf -ljpeg -lz
$ a.out

... sd.hdf created
... data1 created
... data written out
... file closed

How to run HDF5 from a C program

In your program include the appropriate HDF header files and call the: appropriate HDF5 functions.

To compile and link using the gcc compiler enter:

gcc pgm.c -I$HDF5_HOME/include -L$HDF5_HOME/lib -lhdf5_hl -lhdf5 -lz -lm -static -o pgm

or:

h5cc pgm.c -o pgm

To compile and link using the Intel compiler enter:

icc pgm.c -I$HDF5_HOME/include -L$HDF5_HOME/lib -lhdf5_hl -lhdf5 -lz -lm -static-intel -o pgm

  • Replace pgm.c with the name of the file containing your source code
  • Replace pgm with the name of the executable to be created
  • Set HDF5_HOME /u/local/apps/hdf5/current

If you omit -static, you will have to set the LD_LIBRARY_PATH environment variable at run time to include $HDF5_HOME/lib.

You can either set an environment variable or replace $HDF5_HOME in the command shown above.

How to run HDF5 from a Fortran 90 program

In your program include the appropriate HDF5 header files and call the: appropriate HDF functions.

To compile and link enter:

ifort pgm.f90 -L$HDF5_HOME/lib -lhdf5_fortran -lhdf5 -lz -lm -static-intel -o pgm

or:

h5fc pgm.f90 -static-intel -o pgm

  • Replace pgm.f90 with the name of the file containing your source code
  • Replace pgm with the name of the executable to be created
  • Set HDF5_HOME /u/local/apps/hdf5/current

If you omit -static, you will have to set the LD_LIBRARY_PATH environment variable at run time to include $HDF5_HOME/lib.

You can either set an environment variable or replace $HDF5_HOME in the command shown above.

How to run HDF5 from a Fortran 77 program

HDF5 cannot be called from Fortran 77.

Report Typos and Errors
UCLA OIT

© 2016 UC REGENTS TERMS OF USE & PRIVACY POLICY