This page explains how to read data fields and geolocation fields from HDF-EOS5 swath data using HDF-EOS5 C APIs. The example used below will simply read the entire elements in one data field and two geolocation fields, and dump several elements. To get the full source code, see here.
An HDF-EOS5 file consists of multiple grids, swaths and points. A swath object consists of dimensions, data fields, attributes, geolocation fields and dimension maps. Note that a swath object can have geolocation fields and dimension maps, which are not allowed in a grid object. Geo-location fields provide spatial and/or temporal information about data fields.
In most cases, a swath object has at least two geolocation fields: Longitude and Latitude. As their names indicate, both fields are about geolocations where physical data (represented by data fields) were measured.
Briefly speaking, dimension maps can be used to save space by keeping only small number of elements in geolocation fields. The trade-off is that associating geolocation fields with data fields is complicated. For more information about the dimension map, refer to HDF-EOS5 Data Model, File Format and Library.
We will use one OMI Aura data. Download the file explained in this page here. This file does not use dimension maps.
Assuming that we know the swath object name, the data field name, and the geolocation field name, we can access the data field through the following steps:
The following file contains the declarations of the API functions used in this example.
The HDF-EOS5 API HE5_SWopen
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 one swath object ColumnAmountAerosol.
We open this swath object using the HE5_SWattach
function to access
all its data fields,attributes and geolocation fields.
HE5_SWopen
function.
The second argument is the name of swath object.
ColumnAmountAerosol has several data fields. Let's read data from
AerosolIndexUV data field.
One can find the datatype, rank and dimension sizes
using the HDF View Java browser or
the h5dump command-line tool.
Assuming that we know the datatype, rank and
dimension sizes of this data field, data can be read using the HE5_SWreadfield
function.
HE5_SWattach
function.
The second argument specifies the name of the data field.
The third, fourth and fifth arguments can specify a subset of the data field.
Filling them with NULL
implies reading the entire elements of the data field.
The last argument indexuv
is the buffer for the
output; the value of the data field is saved in this buffer after the HE5_SWreadfield
function
is called.
Note that passing insufficient buffer to the HE5_SWreadfield
function results in buffer-overrun.
In this example, the data field is a 1644-by-60 array, and its datatype is the short (16-bit in most systems) integer.
ColumnAmountAerosol swath has several geolocation fields including Time,
Longitude and Latitude. We will retrieve elements from Longitude
and Latitude. The same API, HE5_SWreadfield
, can be used
to read data in a geolocation field.
After retrieving data, the swath object can be detached using the HE5_SWdetach
function.
Note that this function and the HE5_SWattach
function form a pair. The descriptor returned
by the HE5_SWattach
function is the argument of the HE5_SWdetach
function.
Now that we get all necessary data from the file, we can close the file.
The HE5_SWclose
function closes the opened file. Its argument is the descriptor returned by the
HE5_SWopen
function.
We have read one data field AerosolIndexUV, and two geolocation fields,
Longitude and Latitude, and stored them at indexuv
, longitude
and latitude
, respectively. One can print their values as follows:
Also, one needs to note that data fields can have more dimensions than geolocation fields. For example, the data field AerosolOpticalThicknessMW is a 1644-by-60-by-14 array. Given that Longitude and Latitude are 1644-by-60 arrays, we can conclude that the first two dimensions of the data field are related to both Longitude and Latitude, and the third dimension is related to something else. This implies that 14 elements are measured at the same location.
To get the full source code, see here. For more C examples of accessing HDF-EOS5 swath data and how to build this code, check here.