NCO

From GHER

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...

Contents

Compute field mean value

Use ncwa (weighted average)

ncwa -a lon lat input.nc output.nc

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' input.nc output.nc

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 in1.nc out1.nc

If you execute

ncdump out1.nc 

you will see the line

time = UNLIMITED ; // (1 currently)

Add a time variable

ncap2 -O -s 'time=10' out1.nc out1.nc
  • -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 out123.nc

Modification of the attributes

Use ncatted (attributed editor)

Modify values of an attribute

ncatted -a missing_value,TSM,m,d,-999 northsea_TSM.nc

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

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 results.nc

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




ncdap does not work with nco.

wget http://ftp.gnu.org/gnu/texinfo/texinfo-4.13.tar.gz
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
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