NetCDF operators (NCO)

This page provides an example of how to use NetCDF Operators (NCO) with SILO NetCDF files.

Software and data requirements

The NetCDF Operators (NCO) toolkit is a suite of command-line programs to interact with NetCDF files. You can download pre-built binaries or compile from source.

Example 1. Display the metadata

The ncdump tool can be used to view the metadata within a NetCDF file. For example, to view the file structure and attributes of the 1981 monthly rainfall data:

  1. Download the monthly rainfall data for 1981. This can be done using a variety of methods.
  2. Run the the following command:

    ncdump -h

    This shows the structure of the file (time, lat and lon coordinates) and ancillary information such as the data packing parameters (scale_factor, add_offset). The truncated output of the previous example is:

    netcdf \1981.monthly_rain {
    	lat = 681 ;
    	lon = 841 ;
    	time = UNLIMITED ; // (12 currently)
    	double lat(lat) ;
    		lat:long_name = "latitude" ;
    		lat:standard_name = "latitude" ;
    		lat:units = "degrees_north" ;
    		lat:axis = "Y" ;
    	double lon(lon) ;
    		lon:long_name = "longitude" ;
    		lon:standard_name = "longitude" ;
    		lon:units = "degrees_east" ;
            	lon:axis = "X" ;
    	double time(time) ;
    		time:units = "days since 1981-01-01" ;
    		time:calendar = "standard" ;
    		time:axis = "T" ;
    	short monthly_rain(time, lat, lon) ;
    		monthly_rain:_FillValue = -32768s ;
    		monthly_rain:long_name = "Monthly rainfall" ;
    		monthly_rain:units = "mm" ;
    		monthly_rain:scale_factor = 0.1 ;
    		monthly_rain:add_offset = 0. ;
    // global attributes:
    		<global metadata follows>

Example 2. Compute seasonal climatologies

The NetCDF record averager (ncra) can be used to compute seasonal means.

For example, to compute the 1981-2000 summer (Dec-Jan-Feb) seasonal average:

  1. Download monthly rainfall files for 1980 to 2000. This can be done using a variety of methods.
  2. Run the record averager:
    ncra -F -d time,12,,12,3 \ \ \ \ \ \ \ \ \ \ \

    This will write the output to file

    The arguments are as follows:

    -F invokes FORTRAN-style indexing (indices start at 1, not 0), and -d time,12,,12,3 selects data starting at time-slice 12 (December in the first file, 1981), continuing to the end (December in the last file, 2000) using a stride of 12 (looping over every year), and in each "sub-cycle" extracting 3 datasets (Dec, Jan, Feb).

Note on specifying input files

On UNIX systems the list of input files can be abbreviated using regular expressions. Using the Bash shell, the list can be expressed as:

198[123456789] 199[0123456789]

NCO also has an option that enables it to generate the list of input files, providing the filename contains a numeric suffix immediately before the file-type suffix. To use this option, the SILO annual files must first be renamed from <year>.<variable>.nc to <variable>.<year>.nc, so the time index (year) is immediately before the ".nc" suffix. Using this feature, the climatology example becomes:

ncra -F -d time,12,,12,3 -n 19,4,1 \

where the -n option instructs ncra to load 20 files, each having a 4-digit numeric suffix, starting with file and incrementing the numeric index by 1 to access each successive file.

This feature is useful when computing long-term averages requiring many input files.

Creative Commons Attribution 4.0 International (CC BY 4.0) ( )
Last updated
18 Sep 2017