GDL

1. Overview

GNU Data Language (GDL) is a free clone of Interactive Data Language ( IDLexternal ), which is an interpreted language used to manipulate scientific data and draw plots. GDL partially supports both HDF4external and HDF5external . Additionally, it supports netCDFexternal .

2. Installation

Depending on computer systems users used, installing GDL may be easy. For example, Linux Ubuntu provides the GDL package. Other popular Linux systems may also provide the GDL package.

If your system does not have GDL installed, you need to build GDL from source code. Building GDL from source code requires PLplot[1] and GNU Scientific Library (GSL)[2]. In particular, building PLplot was not easy, and it generated two errors that required manual fixes. First, it could not detect correct paths for Python executables, libraries and include files. We had to manually specify them. Second, when installing PLplot, a missing .mod files error occurred. We had to manually copy three .mod files from the bindings/f95 directory.

Installing the current version of GDL requires special attention if HDF4 or HDF5 is built with SZIPexternal . In this case, the configure script will fail. Users have to patch the configure script to link the HDF4 or HDF5 library with SZIP. Based on personal email communications with a GDL developer, the next release of GDL may fix the configuration problem (release date should be after Sep. 8th, 2009).

If netCDF-4external built with HDF5 is used, the configure script should be fixed further because GDL assumes that netCDF does not depend on HDF5, which is no longer true if netCDF-4 is built with HDF5. In the configure.in file, netCDF-4 rule should be located after HDF5 rule. Also, the user should add -lhdf5_hl to LIBS for HDF5 rule because netCDF-4 uses them. Since GDL uses HDF5 1.6 API, H5_USE_16_API should be defined for the preprocessor if it is linked with HDF5 1.8 or later.

Please note that a GDL developer notified us in email that the above netCDF-4/HDF5 configure script problem is resolved in GDL 0.9rc4.

3. How to Use

Since GDL has only a thin abstraction layer, it exposes format-specific differences to users. For example, all HDF4-related function names start with HDF while all HDF5-related function names start with H5. Both HDF4 and HDF5 are partially supported.

3.1. Read an HDF4 File

Figure 1 is an example of code that reads data from an HDF4 SDS and stores all values in the tbocean variable. These statements can be typed under the GDL environment. We will use one AMSR-E AE_RnGdexternal file from NSIDC. You can download the file explained in this page from here.

Figure 1 GDL code reading data from an SDS in an HDF4 file
FILE_NAME="AMSR_E_L3_RainGrid_B05_200707.hdf"
SDS_NAME="TbOceanRain"

// Open an HDF4 file and an SDS in it
sd_id = HDF_SD_START(FILE_NAME, /read)
sds_index = HDF_SD_NAMETOINDEX(sd_id, SDS_NAME)
sds_id = HDF_SD_SELECT(sd_id, sds_index)

// Read data from the SDS
HDF_SD_GETDATA, sds_id, tbocean

// Close the SDS and the file
HDF_SD_ENDACCESS, sds_id
HDF_SD_END, sd_id

One GDL function is mapped to one HDF4 C API as the above example shows. For example, HDF_SD_START() is equivalent to SDstart(). For more detailed information, refer to the HDF4 reference manual.

3.2. Read an HDF5 File

To read an HDF5 file, a different set of functions that resemble HDF5 C API should be used. We used the HDF4-to-HDF5 Conversion tool[3] to convert the AMSR-E HDF-EOS2 file to anHDF5 file. The converted file was renamed to AMSR_E_L3_RainGrid_B05_200707.h5. Users can download this HDF5 file from here. Figure 2 shows code that opens an HDF5 file and reads all values in a dataset. Although this is equivalent to Figure 1, the code is very different because the file formats are different.

Figure 2 GDL code reading data from a dataset in an HDF5 file
FILE_NAME="AMSR_E_L3_RainGrid_B05_200707.h5"
DATASET_NAME="/MonthlyRainTotal_GeoGrid/Data Fields/TbOceanRain"

// Open an HDF5 file and a dataset in it
file_id = H5F_OPEN(FILE_NAME)
dset_id = H5D_OPEN(file_id, DATASET_NAME)

// Read data from the dataset
tbocean = H5D_READ(dset_id)
space_id = H5D_GET_SPACE(dset_id)
dimensions = H5S_GET_SIMPLE_EXTENT_DIMS(space_id)

// Close the dataset and the file
H5S_CLOSE, space_id
H5D_CLOSE, dset_id
H5F_CLOSE, file_id

Similar to the HDF4 interface, one GDL function is mapped to one HDF5 C API, which means that users need to know how to use HDF5 C API.

3.3. Draw a Plot

IDLexternal provides functions such as MAP_SET for mapping points on the earth's surface, but GDL does not implement this, as of June 2008. GDL can draw contours and surfaces, but it lacks the ability to shade surfaces.

After reading data from a file by using the code shown in either Figure 1 or Figure 2, a contour can be drawn by the following command:

Figure 4 shows the result of the above command. The result is not very readable due to the lack of the earth’s surface and shading.

4. References


Last modified: 04/06/2010
About Us | Contact Info | Archive Info | Disclaimer
Sponsored by NASA Cooperative Agreement Grant Number NNX08AO77A / Maintained by The HDF Group