2008 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF Utilities
4.3 NCO Utilities
As an example of third-party software built on top of Unidata's netCDF
libraries, the NCO package from Charlie Zender at the University of
California at Irvine is particularly useful. It's philosophy is to
handle any netCDF files (which is what is meant by generic).
NCO programs take arbitrary netCDF files as input and produce
netCDF files as output. Use of NCO interactively and in simple
scripts can often accomplish tasks that would otherwise require
programming. The latest version of NCO incorporates both MPI and
OpenMP parallel processing.
Currently there are 12 NCO utilities:
- ncap: Arithmetic processor (algebra, derived fields)
- ncatted: Attribute editor (change attributes)
- ncbo: Binary operator (subtraction, addition, ...)
- ncea: Ensemble averager (means, min/max, ...)
- ncecat: Ensemble concatenator (join files)
- ncflint: File interpolator
- ncks: Kitchen sink (sub-set, hyperslab, ...)
- ncpdq: Pack data, permute dimensions
- ncra: Record averager (means, min/max, ...)
- ncrcat: Record concatenator (join time-series)
- ncrename: Renamer (rename any metadata)
- ncwa: Weighted averager (average, mask, integrate, ...)
Some NCO Examples
- Create a new windspeed
variable from component wind variables, u and v:
ncap -O -s "windspeed=sqrt(u^2+v^2)" in.nc out.nc
- Compute monthly temperature anomalies from 1985 mean:
ncdiff -v T 85_0112.nc 85.nc t_anm_85_0112.nc
- Average five ensemble members (see documentation to average N ensemble
members):
ncea 85_0[1-5].nc 85.nc
- Concatenate five ensemble members into single file (see documentation to conatenate N ensemble
members):
ncecat 85_0[1-5].nc 85.nc
- Interpolate fields known at times 85 and 87 to time=86:
ncflint -i time,86 85.nc 87.nc 86.nc
- Print value of variable near specified coordinates. For
example to print the value of the variable "tos" nearest
longitude 203 degrees E and latitude 19.5 degree N from the file
sst.nc:
ncks -H -v tos -d lon,203.0 -d lat,19.5 sst.nc
- Extract variables time and pressure from file in.nc and write to
out.nc, including any needed dimensions, coordinate variables, and
variable attributes:
ncks -v time,pressure in.nc out.nc
- Pack all variables in file in.nc and store the results in out.nc,
using scale_factor and add_offset attributes:
ncpack in.nc out.nc
- Re-order in.nc to dimension order lon,lat,time:
ncpdq -a lon,lat,time in.nc out.nc
- Average timeseries across five files:
ncra 85_0[1-5].nc 85.nc
- Concatenate timeseries across five files:
ncrcat 85_0[1-5].nc 85.nc
- Globally average file, weighting variables by area:
ncwa -w area -a lat,lon in.nc out.nc
NetCDF-4 note:
NCO currently supports netCDF-4 atomic data
types and compression, and NCO can read and write netCDF-4 data that
uses the classic model.
2008 Unidata NetCDF Workshop for Developers and Data Providers > NetCDF Utilities