How to Read HDF-EOS5 Swath data - More Examples

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

How to Build C Programs

After you write a C program, you need to build a binary using a C compiler. One easy way to build the binary 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_swath from read_swath.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_swath: read_swath.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 HDF5external 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_swath to your own executable name.

If users do not use h5cc, many switches may be required based on how the HDF5external 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 HDF5external binary distribution, can be used to build the program. The following shows a skeleton of Makefile that can be used to build read_swath from read_swath.f. We assume that the 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_swath: read_swath.f
$(FC) $(FFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
Similar to the C example, the first two lines should be adjusted. If the users do 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_swath from read_swath.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_swath: read_swath.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 HIRDLS Aura Level 2 Swath Example

Download one file here. See C code or Fortran 77 code that reads the CloudTopPressure data field, the Longitude field and the Latitude field from the HIRDLS swath.

An MLS Aura Level 2 Swath Example

Download one file here. You can see C code or Fortran 77 code that reads the L2gpValue data field, the Longitude field and the Latitude field from the BrO swath.

An OMI Aura Level 2 Swath Example

Download one file here. See C code or Fortran 77 code that reads the EffectiveCloudFraction data field, the Longitude field, the Latitude field from the ColumnAmountAerosol swath.

An TES Aura Level 2 Swath Example

Download one file here. See C code or Fortran 77 code that reads the TropopausePressure data field, the Longitude field, the Latitude field from the AncillaryNadirSwath swath.


Last modified: 04/26/2010
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by Subcontract number 114820 under Raytheon Contract number NNG10HP02C, funded by NASA / Maintained by The HDF Group