Reading GRIB Data into IDL

QUESTION: I have an assignment to analyze some data in IDL, but the data is in GRIB format, and I see no way to read this data into IDL directly. How can I analyze GRIB data in IDL?

ANSWER: The short answer is “Don't use GRIB data. Go get the same data in the often available netCDF format. IDL has plenty of tools and support for dealing with netCDF data files.”

The long answer is slightly more complicated. You have a couple of choices.

The standard way of working with GRIB files is with the program wgrib. This program can often be spawned from IDL and data passed from it to IDL via pipes and so forth. See the SPAWN command on-line documentation for the details. This is mostly a UNIX solution to the problem.

A second alternative is to download the IDL_GRIB DLL, written by Andy Pursch, and offered on the IDL User Contribution page of the ITTVIS web site. This will work for version 6.3 of IDL and later. Just install the DLL in the proper location of your IDL distribution and you can query and read GRIB files directly into IDL variables.

A third alternative is to convert your GRIB files into netCDF files yourself. Here is how Bill Gallery suggests you do it.

I use the NCAR Command Language (ncl) package from NCAR to convert GRIB files to NetCDF format. I find NetCDF files much easier to use, with good support in IDL. After converting to NetCDF you can use ncdump to get a summary of the file contents or use David Fanning new IDL NetCDF file browser to view the contents.

Note that the resulting NetCDF file will be two or three times larger than the GRIB file.

The ncl program is available for most platforms, including LINUX and Windows (cygwin). The two ncl programs you want to use are:
  1. ncl_filedump: like ncdump, dumps a summary of the GRIB file
  2. ncl_convert2nc: converts a GRIB (GRIB1 or GRIB2) file to NetCDF format.


Sylwester Arabas informs me today (17 February 2010) that GDL, version 0.9rc4 and higher, supports read-only access to GRIB files (edition 1 and 2 of the GRID format) via the ECMWF GRIB API. He writes this.

As with netCDF or HDF in IDL, GDL provides almost one-to-one equivalents of the routines from the underlying API. As a result, one can use GDL to convert a GRIB file into an IDL save file, a netCDF file or a simple binary or text file. Or you can simply process or visualise the file contents.

The README_GRIB and files from GDL give a short description of the GRIB features in GDL, and present some example codes. When compiling GDL from source, you need to specify the --with-grib option to the configure script. The Fedora package of GDL 0.9rc4 is configured with support for GRIB files built in.


IDL 8.1 introduced a library of routines (similar to the netCDF or HDF libraries) that allows the user to read and write GRIB files. These routines are UNIX only and do not run on Windows or Macintosh computers. It is expected that a limited-version of the routines might be available for Windows in the mid-2012 time frame.

Version of IDL used to prepare this article: IDL 7.0.1.

Web Coyote's Guide to IDL Programming