Browsing and Reading netCDF Files in IDL
QUESTION: Is there an easy way in IDL to find out what is inside a netCDF file, and to read the data and metadata (attributes) from the file? The scientific data formats seem complicated.
![]()
ANSWER: It is true that the scientific data formats (netCDF, CDF, and HDF) seem complicated, but they are less so after you spend a couple of days working with them. But even then, there are surprises.
I have been working with netCDF files recently and, like you, have found it difficult to know what is in the file. Most of the available IDL software I found on the Internet to read netCDF files required that I know the name of the variables in the files, and I don't always. So I wrote my own netCDF Browser to allow me to easily see what is in a netCDF file and to quickly read the data and metadata into IDL variables.
The Unidata folks, who maintain the netCDF library and netCDF standards, provide example netCDF data files for downloading. I have downloaded one such example file to use in this article.
I have put the ability to read and browse netCDF data files into an object of class NCDF_DATA. This gives me great flexibility in how I work with netCDF files, but at the cost of greater complexity. It is possible to use the object to work with the netCDF files through what I call a Browser Window or graphical user interface, but it is also possible to work with netCDF files in a programmable and non-interactive way, using the object's methods to read the data and metadata.
Most users, however, will probably want to use the IDL procedure front-end to the object, which avoids the complexities of object manipulation in IDL, and provides a straightforward and intuitive interface to the netCDF file. You can see an example of the Browser Window interface in the figure below, with the example netCDF file from above loaded into the object. The code to start this interface looks like this.
IDL> file = 'WMI_Lear.nc' IDL> nCDF_Browser, file
![]() |
| The netCDF Browser Window interface. |
The user clicks on the representation of the data and metadata in the window on the left, and information about the data or metadata appears in the window on the right. Buttons are available to read single variables, or the entire data file at once. When variables are read, they are read into IDL variables at the main IDL level. As shown in the figure below, the user has the opportunity to name the variables as he or she wishes. New data files can be loaded into the browser at any time by choosing the Open New File button. The user is permitted to have multiple Browser Windows open at once.
![]() |
| Individual variables or the entire data file can be read into IDL variables at the main IDL level. New data files can be opened from within the interface. |
The netCDF file browser programs require other programs from the Coyote Library. You can download all the Coyote programs required, as well as the browser code itself, in the file ncdf_browser.zip Additional documentation is provided in the code itself.
Additionally, Ben Tupper has written a 15 line program that saves three lines of typing, so that you can use the ncdf_data object in an IDL function. He kindly named the program FSC_READ_NCDF.
![]()
Version of IDL used to prepare this article: IDL 7.0.1.
![]()
Copyright © 2008 David W. Fanning
Last Updated 04 February 2008

