Version 3 (modified by nicolasmartin, 3 years ago) (diff)

Data utilities with netcdf

Last edition: 03/30/17 01:29:23 by nicolasmartin

You can find here an example of bash script to manipulate netcdf files (in this example forcing core2 files).

(In this example we extract coordinates and put them in grid_orca2.nc file and then we apply ncpdq to choosen variable).

This is necessary because "npdq" command change all variables, but in this case we don't want to have glamt, gphit, time "short" type.

# remove useless variable from file
ncks -O -x -v V_10.15JUNE2009_orca2.nc v_10.15JUNE2009_orca2.nc 

# exctracting coordinates variables from file, put in output file (grid_orca2.nc)
ncks -v glamt,gphit,time v_10.15JUNE2009_orca2.nc grid_orca2.nc

# exctracting variables from file
ncks -O -C -v V_10_MOD v_10.15JUNE2009_orca2.nc v_10.15JUNE2009_orca2.nc

# compress all variables of v_10.15JUNE2009_orca2.nc file,
# now variables of v_10.15JUNE2009_orca2.nc are "short" type
# (add offset and scale factor)
ncpdq -O -C -P all_xst v_10.15JUNE2009_orca2.nc v_10.15JUNE2009_orca2.nc 

# append grid_orca2.nc file to v_10.15JUNE2009_orca2.nc file to have initial file
# with variable V_10_MOD "short" type and coordinates variables unchanged
ncks -A grid_orca2.nc v_10.15JUNE2009_orca2.nc