This page explains how to read HDF-EOS5 grid data using HDF-EOS5 Fortran APIs. One Fortran program that reads a data field and dumps its elements is presented. This example is written in Fortran 77.
First of all, we assume that you have installed the HDF-EOS5 Fortran library correctly. Please make sure that you included -Df2cFortran in the compiler option when you built it. You may want to review our How to build HDF-EOS page.
We will use one OMI Aura data. Download the file explained in this page here.
An HDF-EOS5 file consists of multiple grid, swaths and points, and a grid object consists of dimensions, data fields and attributes. Assuming that we know the grid object name and the data field name, we can access the data field through the following steps:
The HDF-EOS5 API he5_gdopen
function opens an existing HDF-EOS5 file.
The first argument is the file name, and the second argument specifies the mode to access the file.
In our example, we just want to read the data. So the mode is the read-only mode.
This HDF-EOS5 file has the grid object ColumnAmountAerosol, which
should be opened using the he5_gdattach
function to access
all data fields, dimensions and attributes of the grid object.
he5_gdopen
function.
The second argument is the name of the grid object.
ColumnAmountAerosol has several data fields. Let's read data from
TerrainReflectivity data field.
One can find the datatype, the rank and dimension sizes
using the HDF View Java browser or
the h5dump command-line tool.
Assuming that we know the datatype, the rank and
dimension sizes of TerrainReflectivity, data can be read using the he5_gdrdfld
function.
he5_gdattach
function.
The second argument specifies the name of data field.
The third, fourth and fifth arguments are used to specify the range of elements.
Here, we specify the entire elements by setting starting point as (0, 0), stride
as (1, 1), and edge (1440, 720).
The last argument terrain
is the buffer for the
output; he5_gdrdfld
function fills this.
If you use a 64-bit machine, you need to change the type of integer*4 to integer*8 for start, stride and edge variables.
Note that passing insufficient buffer to the he5_gdrdfld
function results in buffer-overrun.
In this example, the data field is a 1440-by-720 array, and its datatype is the short(16-bit for most systems) integer.
After retrieving data, the grid object can be detached using the he5_gddetach
function.
Note that this function and the he5_gdattach
function form a pair. The descriptor returned
by the he5_gdattach
function is the argument of the he5_gddetach
function.
Now that we get all necessary data from the file, we can close the file.
he5_gdclose
function closes the file. Its argument is the descriptor returned by the
he5_gdopen
function.
Previously, all elements of TerrainReflectivity data field are stored at a variable called
terrain
. One can perform desired operations on this variable.
Let's print a few elements to check if the retrieved data looks correct.
As the above code omits some parts, see
here.
to get the full source code.
To build this program, users can use Makefile
like the following:
Makefile
, click here.
For more Fortran examples of accessing HDF-EOS5 grid files, click here.