Jump to: navigation, search

nco is a powerful tool for the manipulation of NetCDF files in command line.

It can be easily applied to output generated by Diva, for example to

  • modify the attribute,
  • change the variable name,
  • average fields,
  • concatenate files...


Compute field mean value

Use ncwa (weighted average)

ncwa -a lon lat

will compute the spatial mean (based on variables lon and lat).

If a mask (land-sea for example) has to be specified:

ncwa -a x,y -B 'error_field>=0'

where the argument after -B is the condition for a point to be considered in the average.

Add a time record

ncecat -O -u time

If you execute


you will see the line

time = UNLIMITED ; // (1 currently)

Add a time variable

ncap2 -O -s 'time=10'
  • -O stands for overwrite
  • -s stands for script and means the command is used with in-line script.

Concatenate files

ncrcat out[1-3].nc

Modification of the attributes

Use ncatted (attributed editor)

Modify values of an attribute

ncatted -a missing_value,TSM,m,d,-999

replaces the attribute missing_value of the variable TSM by -999 in the file

Add a missing_value attribute to a file

This example is particularly useful when one wants to set the _FillValue to -99 (or -999, ...) in a NetCDF file generated by Diva.

ncatted -a _FillValue,analyzed_field,c,f,-99

The benefit is that ncview automatically detect the missing value and does not plot it.

ncdap does not work with nco.

tar xf texinfo-4.13.tar.gz 
cd texinfo-4.13
./configure --prefix $HOME/opt/texinfo-4.13 
make -j 3
make install
cd ..

adapt .bash_profile

export PATH="$HOME/opt/netcdf-4.0/bin:$HOME/opt/texinfo-4.13/bin:$PATH"

./configure --prefix $HOME/opt/nco-4.0.0 NETCDF_INC=$NETCDFINCLUDE NETCDF_LIB=$NETCDFDIR
make check
make install
export PATH="$HOME/opt/netcdf-4.0/bin:$HOME/opt/nco-4.0.0/bin:$HOME/opt/texinfo-4.13/bin:$PATH"
Personal tools