GDL

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 . It also supports OPeNDAP via netCDFexternal interface.

1. Installation

Depending on computer systems users used, installing GDL may be easy. For example, there are numerous packaged versions of GDL available for various OSes. For example, you can install GDL for CentOS 6 using yum install gdl.

If your you want to try map support, you need to build GDL from source code. The packaged GDL doesn't include map support.

However, building from source is very difficult and we don't recommend it. GDL is still in beta (0.9.x) release and map support may not work as documented by the GDL team. In addition, building GDL from source code requires PLplot[1], GNU Scientific Library (GSL)[2], GNU Readline Library[3] and other optional packages. Please note that HDF4 library should be built with --disable-netcdf option if you want to support OPeNDAP via NetCDF.

2. How to Access HDF4, HDF5, and OPeNDAP

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.

2.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.

2.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[4] to convert the AMSR-E HDF-EOS2 file to an HDF5 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.

2.3. Read an OPeNDAP Data

To read a remote data via OPeNDAP, a different set of functions that resemble NetCDF API should be used. Figure 3 shows code that opens an OPeNDAP AIRS data and reads a 3-D variable.

Figure 3. GDL code reading OPeNDAP data
; Open OPeNDAP URL.
fid = NCDF_OPEN('http://eosdap.hdfgroup.uiuc.edu:8080/opendap/data/NASAFILES/hdf4/AIRS.2002.08.01.L3.RetStd_H031.v4.0.21.0.G06104133732.hdf')
vid = NCDF_VARID(fid, 'Temperature_MW_A')

; Retrieve fill value attribute.
NCDF_ATTGET, fid, vid, '_FillValue', fillvalue
PRINT, fillvalue

; Retrieve data.
NCDF_VARGET, fid, vid, data

; Retrieve lat/lon data.
vid = NCDF_VARID(fid, 'Longitude')
NCDF_VARGET, fid, vid, lon
vid = NCDF_VARID(fid, 'Latitude')
NCDF_VARGET, fid, vid, lat

3. How to Draw a Plot

IDL provides functions for plotting data on a map such as MAP_SET but GDL does not support this by default. However, basic plotting functions are supported pretty well.

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 code in Figure 4.

Figure 4. Code drawing a contour plot
levels=254
LOADCT, 33, NCOLORS=levels, BOTTOM=1
CONTOUR, tbocean, /FILL, NLEVELS=levels
Figure 5 shows the result of the above code. The above plot is not informative due to the lack of location information and world map. Now, let's plot data with lat/lon using the Figure 3 code. GDL's CONTOUR can accept lat/lon with data as shown in Figure 6.

Figure 6. Code drawing a contour plot with lat/lon over map
levels=254
LOADCT, 33, NCOLORS=levels, BOTTOM=1
MAP_SET, POSITION=[0.05, 0.06, 0.82, 0.80]
CONTOUR, dataf, lon, lat, /FILL, NLEVELS=levels, POSITION=[0.05, 0.06, 0.82, 0.80], /XST, /YST, XTICKINT=45, YTICKINT=30
MAP_SET, POSITION=[0.05, 0.06, 0.82, 0.80], /NOERASE
MAP_CONTINENTS, COLOR=WHITE
The complete code is available here. Figure 7 shows the result of the above code. Please pay attention to the tick-marks of X-axis and Y-axis because they now represent the lat/lon values in degrees. Please note that GDL can also process the Coyote's color bar library used in our comprehensive IDL example. You can compare Figure 7 with the example IDL plot in Figure 8.

4. References


Last modified: 01/24/2014
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