wiki:Documentation/nco

Version 1 (modified by zpoussi, 9 years ago) (diff)

--

Manual

Please have a look at if you want to make some operations on netcdf files : http://nco.sourceforge.net/#Definition

The manual can be downloaded as a pdf : http://nco.sourceforge.net/nco.pdf

You may have a look at one of the associated forum if you encounter some problems when using it. http://sourceforge.net/projects/nco/forums/forum/9830

Consulting netcdf files on a dods server

For netcdf files available on an OpenDAP/DODS server, one can see the format by adding .dds at the end of the file. Exemple : http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/database/climato/CRU_precipitation.nc.dds

More explanation on http://docs.opendap.org/index.php/QuickStart and http://www.opendap.org/pub/dods/ps-docs/guide.pdf

Specific notes for the dods in Jussieu

To activate the dods fonctionnality, one should use the URL : http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/ rather than http://dods.ipsl.jussieu.fr/

For exemple, to see the characteristics of the CRU precipitation file : http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/database/climato/CRU_precipitation.nc.dds

Or to get a subset of it : http://dods.ipsl.jussieu.fr/cgi-bin/nph-dods/database/climato/CRU_precipitation.nc.html

More info on http://wiki.ipsl.jussieu.fr/wiki_ipsl/ServeurDODSintro

Example of use

commande NetCDF Arithmetic Processor ncap

<code>

ncap -s "C_tot=VEGET_MAX*(CARBON_PASSIVE+CARBON_ACTIVE+LITTER);C_tot@missing_value=CARBON_PASSIVE@missing_value" soilc_af2002.nc my_soilc_af2002.nc

</code>

commande ncrcat

concatenate the variables file_{23..32}.nc changing 2 digits on the number by step of 1

<code>

ncrcat -n 10,2,1 file_23.nc file_global.nc

</code>

commande ncwa

Calculate the mean over various dimensions.

commande ncatted

o, meaning Overwrite (other possible options : a c d m ) a global attribute entitled nbyear which is a double d (other possible options : f d l s c b)

<code>

ncatted -O -a nbyear,global,o,d,$ny stomate_forcing_all.nc

</code>

Pour modifier rapidement l'année de départ (!attention aux calendriers grégoriens pour lesquels on n'a pas le droit de procéder de la sorte!!!), c'est time_counter:units qui est interprété par ferret et non time_counter:origin. Cf /home/orchidee01/pbrender/ORCHIDEE/MERGE_PP/AGOUFOU_SPINUP_PP/SPINUP_COMPLET_v3/change_date

<code>

#!/bin/bash ncrcat -O run_100?/stomate_history.nc MA_Ago_stomate_history.nc

n_or=$( ncdump -h MA_Ago_stomate_history.nc |grep time_origin| grep -m 1 -o -E \".*\"|sed "s/2005/$[2005-109]/"|sed 's/"g') n_unit=$( ncdump -h MA_Ago_stomate_history.nc |grep time_counter:units| grep -m 1 -o -E \".*\"|sed "s/2005/$[2005-109]/"|sed 's/"g')

ncatted -O -a time_origin,time_counter,o,c,"${n_or}" MA_Ago_stomate_history.nc ncatted -O -a units,time_counter,o,c,"${n_unit}" MA_Ago_stomate_history.nc

</code>

Sélection d'une partie d'un fichier netcdf

<code>

ncks -d tstep,0,17519 wankame_gapfilled.nc wankama_gapfilled_2005.nc

</code>

Conversion to ascii and reverse

Pour rapide examen de la structure

<code>

ncdump -c

</code>

Pour l'extraction ascii d'une variable

<code>

ncdump -v temp -f fortran -n name > output.cdl

</code>

Pour récupérer un fichier netcdf à partir de la fraction extraite

<code>

ncgen -b -o my_new_name output.cdl

</code>

Utile aussi quand on rencontre un problème sur une commande par exemple ncatted. Ie pour faire des corrections à la main !

ncview

<code>

ncview

</code>

Installation : <code>

sudo apt-get install xorg-dev netcdfg-dev ./configure --x-libraries=/usr/lib make sudo make install

</code>

Voir aussi cdat et vcdat comme utilitaires de visualisation rapide

ncap2

<code>

ncap2 -O -v -s 'gpp_moy=(GPP*VEGET_MAX).avg($PFT)' stomate_history.nc my_history.nc

</code>

Voir exemples de commandes sur : http://nco.sourceforge.net/ncap2.in

ncpdq

ncpdq makes it possible to concatenate files along any dimension, not just the record dimension. First, use ncpdq to convert the dimension to be concatenated (i.e., extended with data from other files) into the record dimension. As a concrete example, say that files x_01.nc, x_02.nc, ... x_10.nc contain time-evolving datasets from spatially adjacent regions. The time and spatial coordinates are time and x, respectively. Initially the record dimension is time. Our goal is to create a single file that contains joins all the spatially adjacent regions into one single time-evolving dataset.

<code>

for idx in 01 02 03 04 05 06 07 08 09 10; do # Bourne Shell ncpdq -a x,time x_${idx}.nc foo_${idx}.nc # Make x record dimension done ncrcat foo_??.nc out.nc # Concatenate along x ncpdq -a time,x out.nc out.nc # Revert to time as record dimension

</code>