How to Read HDF-EOS2 Swath data - More Examples

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

HDF-EOS2 swath data demonstrated by these examples are from products distributed by NASA GES DISC, NSIDC, LP DAAC and LaRC.

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 h4cc, which is part of the HDF4external binary distribution.

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
HDF4_DIR=<hdf4_path>
HDFEOS2_DIR=<hdfeos2_path>

CC=$(HDF4_DIR)/bin/h4cc

CFLAGS=-I$(HDFEOS2_DIR)/include
LDFLAGS=-L$(HDFEOS2_DIR)/lib
LIBS=-lhdfeos -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-EOS2 library. Users do not need to set paths to the HDF4 library here because h4cc sets them automatically. LIBS specifies libraries used by the program. Both hdfeos and Gctp are from HDF-EOS2. Change read_swath to your own executable name.

If users do not use h4cc, many switches may be required based on how the HDF4 library and the HDF-EOS2 library are built.

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

How to Build Fortran 77 Programs

As h4cc is used in C, h4fc, which is part of the HDF4 binary distribution, can be used to compile an HDF-EOS2 Fortran 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
HDF4_DIR=<hdf4_path>
HDFEOS2_DIR=<hdfeos2_path>

FC=$(HDF4_DIR)/bin/h4fc

FFLAGS=-fno-underscoring
LDFLAGS=-L$(HDFEOS2_DIR)/lib
LIBS=-lhdfeos -lGctp

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

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

Figure 3 A skeleton of Makefile using a pure Fortran compiler
HDF4_DIR=<hdf4_path>
HDFEOS2_DIR=<hdfeos2_path>
SZIP_DIR=<szip_path>

FC=g77

FFLAGS=-fno-underscoring
LDFLAGS= -L$(HDFEOS2_DIR)/lib -L$(HDF4_DIR)/lib -L$(SZIP_DIR)/lib
LIBS=-lhdfeos -lGctp -lmfhdf -ldf -lsz -ljpeg -lz

read_swath: read_swath.f
$(FC) $(FFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
We assumed g77external is available and the HDF4 library is built with the SZIPexternal library. If the HDF4 library is not built with the SZIP library, neither LDFLAGS nor LIBS needs to contain the SZIP library.

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
HDF4_DIR=<hdf4_path>
HDFEOS2_DIR=<hdfeos2_path>
SZIP_DIR=<szip_path>

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

FFLAGS=
LDFLAGS= -L$(HDFEOS2_DIR)/lib -L$(HDF4_DIR)/lib -L$(SZIP_DIR)/lib
LIBS=-lhdfeos -lGctp -lmfhdf -ldf -lsz -ljpeg -lz

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

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

AE_L2A - AMSR-E/Aqua L2A Global Swath Spatially-Resampled Brightness Temperatures

This data product is distributed by NSIDC. Download one file here. See C code or Fortran 77 code that reads the 23.8H_Approx._Res.3_TB_(not-resampled) data field, the Longitude field and the Latitude from the Low_Res_Swath swath.

MAC03S0 - MODIS/Aqua Geolocation Fields 1km 5-Min 1A Narrow Swath Subset along CloudSat

This data product is distributed by GES-DISC. Download one file here. See C code or Fortran 77 code that reads the Height data field, the Longitude field and the Latitude field from the MODIS_Swath_Type_GEO swath.

NOAA-17 AMSU - Advanced Microwave Sounding Unit-A (AMSU-A) Swath from NOAA-17

This data product is distributed by GHRC. Download one file here. See C code or Fortran 77 code that reads the 23800.37 MHz data field, the Longitude field and the Latitude field from the Orbit 2805 swath.

MOP02 - MOPITT Derived CO and CH4 V003

This data product is distributed by LaRC. Download one file here. See C code or Fortran 77 code that reads the CO Total Column data field, the Longitude field and the Latitude field from the MOP02 swath.


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