How to Read HDF-EOS5 Grid data - More Examples

This page provides Makefile templates and more C and Fortran 77 examples on how to read HDF-EOS5 grid data using the HDF-EOS5 library.

How to Build C Programs

After you write a C program, you need to build the executable using a C compiler. One easy way to build the executable is to use h5cc, part of the HDF5external library.

We recommend that users create Makefile to build binaries from C sources. The following shows a skeleton of Makefile that can be used to build read_grid from read_grid.c.

Figure 1 A skeleton of Makefile
HDF5_DIR=<hdf5_path>
HDFEOS5_DIR=<hdfeos5_path>

CC=$(HDF5_DIR)/bin/h5cc

CFLAGS=-I$(HDFEOS5_DIR)/include
LDFLAGS=-L$(HDFEOS5_DIR)/lib
LIBS=-lhe5_hdfeos -lGctp

read_grid: read_grid.c
$(CC) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
The first two lines should be set according to the user's system. CFLAGS and LDFLAGS set paths to the HDF-EOS5 library. Users do not need to set paths to the HDF5 library here because h5cc sets them automatically. LIBS specifies libraries used by the program. Both he5_hdfeos and Gctp are from HDF-EOS5. Change read_grid to your own exectuable name.

If users do not use h5cc, many switches may be required based on how the HDF5 library and the HDF-EOS5 library are built.

After creating your own Makefile, type make or gmake to generate the executable program.

How to Build Fortran 77 Programs

As h5cc is used in C, h5fc, which is part of the HDF5 binary distribution, can be used to build a Fortran program. The following is a skeleton of Makefile that can be used to build read_grid from read_grid.f. We assumed GNU Fortran 77 compiler is available.

Figure 2 A skeleton of Makefile
HDF5_DIR=<hdf5_path>
HDFEOS5_DIR=<hdfeos5_path>

FC=$(HDF5_DIR)/bin/h5fc

FFLAGS=-fno-underscoring
LDFLAGS=-L$(HDFEOS5_DIR)/lib
LIBS=-lhe5_hdfeos -lGctp

read_grid: read_grid.f
$(FC) $(FFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
Similar to the C example, the first two lines should be adjusted. If the user does not want to use h5fc, several switches need to be passed to a compiler and a linker.

You may get linker errors regarding underscores. Probably, Fortran compilers provide several options about underscores, and users need to adjust the option. For example, we used -fno-underscoring option.

Note that h5fc is not created if the HDF5 library is built without Fortran. Still, users can build Fortran programs because the Fortran interfaces of the HDF-EOS5 library does not depend on HDF5's Fortran wrapper library. The following is one possible Makefile that builds read_grid from read_grid.f without using h5fc.

Figure 3 A skeleton of Makefile using a pure Fortran compiler
HDF5_DIR=<hdf5_path>
HDFEOS5_DIR=<hdfeos5_path>
SZIP_DIR=<szip_path>

FC=g77

FFLAGS=-fno-underscoring
LDFLAGS= -L$(HDFEOS5_DIR)/lib -L$(HDF5_DIR)/lib -L$(SZIP_DIR)/lib
LIBS=-lhe5_hdfeos -lGctp -lhdf5 -lsz

read_grid: read_grid.f
$(FC) $(FFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
In the above figure, we assumed g77external is available and the HDF5 library is built with the SZIPexternal library. If the HDF5 library is not built with the SZIP library, neither LDFLAGS nor LIBS needs to contain the SZIP library path.

If you want to build your Fortran program with non-GNU compiler like Intel Fortran compiler or PGI Fortran compiler, do not specify any FFLAGS option in your make file. The following is an example Makefile for Intel Fortran compiler.

Figure 4 A skeleton of Makefile using an Intel Fortran compiler
HDF5_DIR=<hdf5_path>
HDFEOS5_DIR=<hdfeos5_path>
SZIP_DIR=<szip_path>

FC=ifort # FC=pgf77 will also work for PGI fortran compiler.

FFLAGS=
LDFLAGS= -L$(HDFEOS5_DIR)/lib -L$(HDF5_DIR)/lib -L$(SZIP_DIR)/lib
LIBS=-lhe5_hdfeos -lGctp -lhdf5 -lsz

read_grid: read_grid.f
$(FC) $(FFLAGS) $(LDFLAGS) $< $(LIBS) -o $@

After creating your own Makefile, type make or gmake to generate the executable program.

An Aura OMI Level-3 Grid example

Download one file here. See C code or Fortran 77 code that reads the TerrainReflectivity data field from the ColumnAmountAerosol grid.

An Aura MLS Level-3 Grid example

Download one file here. See C code or Fortran 77 code that reads the L3dmValue data field from the Temperature grid.

An Aura TES Level-3 Grid example

Download one file here. See C code or Fortran 77 code that reads the CH4AtSurface data field from the NadirGrid grid.


Last modified: 11/11/2020
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by Subcontract number 4400528183 under Raytheon Contract number NNG15HZ39C, funded by NASA / Maintained by The HDF Group