CDO news

extension to expr: Coordinates, Levels and new field operations

With CDO release 1.7.1 the expr (and the related _exprf, aexpr, aexprf) recieve on important update: the ability to include meta data into user defined computations

  • Calculating with horizontal coordinatres: With the two new functions clon(V) and clat(V) the user has access to the longitudes and latitudes of a given variable V. Suppose the both coordinate fields are given in degrees, this can be used to calculate a global wind field based on a global sin pattern
    cdo shaded,device=png -expr,'wind_u=sin(2*rad(clat(topo)))' -topo analytic_forcing 
    which leads to westward winds on northern and eastward winds on southern hemisphere

    If this is not enough, lets combine it with a cosin longitude pattern:
    cdo shaded,device=png -setunit,m/s -expr,'wind_u=sin(2*rad(clat(topo)))*cos(2*rad(clon(topo)))' -topo analytic_forcing
    to get circular regions with different wind directions
  • Calculating with vertical coordinates: With the new function clev(V), the vertical coordinates of a variable V can be read. Lets compute the potential temperator! Instead of looping over the list vertical levels
    for level in $(cdo showlevel -select,name=temp ifile); do
      cdo -f nc -expr,"pot_temp=temp*((100000/${level})^0.287)" -sellevel,${level} ifile potTemp_${level}.nc
    cdo merge pottemp_?????.nc pottemp_??????.nc
    rm pottemp_??????.nc pottemp_?????.nc 
    the whole procedure can be written in a single line without temporal files
    cdo expr,"pottemp=temp*((100000/clev(temp))^0.287);"  ifile
  • Calculating with temporary data: Variables starting with an underscore, will not be written into the result file. This can increase the readabiliy of the formulars, while keeping the output file clean
    cdo-dev -f nc -expr,'_xSquare = sin(rad(clat(topo)))^2; _ySquare = cos(rad(clat(topo)))^2; constant1=sqrt(_xSquare + _ySquare)' -topo
    cdo infov
        -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter name
         1 : 0000-00-00 00:00:00       0   259200       0 :      1.0000      1.0000      1.0000 : constant1     
  • Calculate with cdo-internal functions: Vertical and horizontal operations like fldmean, vertmean, fldstd or vertmax can now be used in formulars. Lets scale a temperature (K) with its maximum value
    cdo -f nc -infov -aexpr,'h=temp/fldmax(temp)'  -temp
        -1 :       Date     Time   Level Gridsize    Miss :     Minimum        Mean     Maximum : Parameter name
         1 : 0001-01-01 00:00:00       0   259200       0 :      220.85      276.72      317.30 : temp          
         2 : 0001-01-01 00:00:00       0   259200       0 :     0.69603     0.87210      1.0000 : h

For further options, please have a look here


  • Doing tan, exp, log ... with SSE2: SLEEF on
  • AMD recommended CPU-GPU aware C/C++ library for numerics which abstracts from OpenCL: Libra
  • CPU-GPU abstraction through pragmas, which uses OpenCL and CUDA as backend: CAPS
  • Comparison of HPC specific languages made by Iris Christadler form the PRACE project : pdf (all docs)

Some parallelization related documents

How to display fortran code within redmine

Use class="fortran" for the syntax option (see bottom of documentation) of the code tag:

MODULE mo_kind
  CHARACTER(len=*), PARAMETER, PRIVATE :: version = '$Id$'
  ! Floating point section
  ! ----------------------
  INTEGER, PARAMETER :: ps =   6
  INTEGER, PARAMETER :: rs =  37
  INTEGER, PARAMETER :: sp = SELECTED_REAL_KIND(ps,rs) !< single precission
  INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(pd,rd) !< double precission
END MODULE mo_kind

Some ruby doc

testest whys-poignant-guide-to-ruby.pdf


  1. mappings for use with icon_plot.ncl

Compile cdo with mingw

Ubuntu 10:

./configure --host=i586-mingw32msvc --with-threads=/home/ubuntu/Downloads/libs4cdo-0.0.7/build --with-hdf5=/home/ubuntu/Downloads/libs4cdo-0.0.7/build --with-netcdf=/home/ubuntu/Downloads/libs4cdo-0.0.7/build --prefix=/home/ubuntu/Downloads/libs4cdo-0.0.7/build --with-proj=/home/ubuntu/Downloads/libs4cdo-0.0.7/build LIBS='-L/home/ubuntu/Downloads/libs4cdo-0.0.7/build/lib -lsz' CPPFLAGS='-Dfseeko=fseek -Dftello=ftell' CFLAGS=-g



I created a ruby gem for use with CDO, see: Some simple examples can be found here and in the unit tests.

ICON plot

The script icon_plot.ncl is a single NCL program, which provides multiple plot types for data on ICON's grid. It is located in the ICON-repository under source:/trunk/icon-dev/scripts/postprocessing/tools/icon_plot.ncl. Most of the functionality is implemented in a library: icon_plot_lib.ncl located in source:/trunk/icon-dev/scripts/postprocessing/tools/icon_plot_lib.ncl. Both files are installed into the /pool/data/ICON/tools which is the default lookup location for the library. For different location like an icon checkout, use altLibDir, e.g. altLibDir='"/home/user/src/icon-dev/tools"'.


NCL 5.2.1 is the minimum version of NCAR's plotting language. 6.0.0 release is installed, so you might use this with

module rm ncl ; module load ncl/6.0.0-gccsys
CDO is also required because of internal remapping and other file investigations. It can be set to a non-standard path by the cdo command line option (see options).


User default settings

icon_plot.ncl optionally reads a configuration file named $HOME/.icon_plot.rc where default options can be set. Actually it is handled like an ordinary ncl file. This can be used to customize the altLibDir setting, e.g.:

[ram@thingol:~]cat .icon_plot.rc

One word about quoting

As you might have noticed: NCL command line options have to be quoted a lot. This can be annoying especially when used in scripts where values are variables, e.g. a simple variable name must be handled like this:

ncl icon_plot.ncl varName=\""$var"\"

This can by avoided by a script of Kalle called attachment:nclsh (attachment:nclsh-1.0.0.tar.gz also contains docs). This is now part of the regular ncl modules provided by CIS and available by default (not yet on DKRZ machines). It can be used instead of the regular ncl interpreter:

nclsh icon_plot.ncl -iFile=$HOME/data/icon/ -varName=$var -oFile=test -mapLLC=-30.0,-30.0 -mapURC=30,30 -maskName=wet_c -mapType=ortho +mapLine

It is well documented (see man nclsh or attachment:nclsh.pdf) and will help you to write your own plotting scripts using icon_plot.ncl and other NCL scripts.

Basic command line options

Required are options for
  1. Input/output files: Use the variable iFile for defining the input and oFile for the output file. It's extension depends on the output type, which can be set with oType. If oFile is left out, the output file will inherit its name from the input file.
  2. Variable selection: Depending on the plot mode you like to use, varName for scalar variables or vecVars for vector-variables must be uses.
Optional (default:0) parameter are
  1. Level selection: Levels can only be selected by their index. That's why, the corresponding variables is called levIndex. Please note that it starts with 0, like any other NCL indices.
  2. Time selection: Like levIndex, the variable timeStep can be used to select a certain timestep, again starting from 0.

There are many more parameters (docu) for mapping, transsections, selecting regions and masking, but these are the most fundamental ones. Lets start with the different plot modes.

Plot Types

For flexibility the selection of a specific plot mode is implemented by combining certain options.

Contour plots

Contour plot are the default plot mode. If only the require parameters are set, e.g. iFile and varName, a simple contour plot is created with

ncl icon_plot.ncl 'varName="T"' 'iFile="/home/ram/data/icon/"' 'oFile="test_icon_plot"' 'oType="png"' 
nclsh icon_plot.ncl -varName=T -iFile=/home/ram/data/icon/ -oFile=test_icon_plot -oType=png

This is a basic ocean temperature plot. The only additional parameter is oType, which used to set the output type to png. Captions are set to basic information like variable name, time and level information and input filename.

Vector plots

Plotting vectors is easy: Use vecVars instead of varName:

ncl icon_plot.ncl 'vecVars="U V"' 'iFile="/home/ram/data/icon/"' 'oFile="test_vector_atm0"' 'oType="png"' vecRefLength=0.01

nclsh icon_plot.ncl -vecVars=U,V -iFile=/home/ram/data/icon/ -oFile=test_vector_atm0 -oType=png -vecRefLength=0.01

To adjust the length of the reference vector, the variable vecRefLength is set to a smaller value.


ncl icon_plot.ncl 'vecVars="U V"' 'iFile="/home/ram/data/icon/"' 'oFile="test_vector_atm0"' 'oType="png"' vecRefLength=0.01  'mapType="NHps"'

nclsh icon_plot.ncl -vecVars=U,V -iFile=/home/ram/data/icon/ -oFile=test_vector_atm0 -oType=png -vecRefLength=0.01  -mapType=NHps

This leads to a limitation to the northern hemisphere:

NCL is able to plot vector field from regular gridded data only. That's why the input field is interpolated to a regular grid internally by CDO. For setting a resolution, the option resolution should be set. Its default is r90x45.

Overlay of scalar and vector variables

Contour and vector plots can be combined into a single plot by overlaying both. Following this approach, such an overlay plot will be created, if varName and vecVars are given:

ncl icon_plot.ncl 'varName="T"' 'iFile="/home/ram/data/icon/"' 'oFile="overlay_atm"' 'oType="png"' \
'vecVars="U V"' 'atmLev="m"' vecRefLength=0.04
nclsh icon_plot.ncl -varName=T -iFile=/home/ram/data/icon/ -oFile=overlay_atm -oType=png \
-vecVars=U,V -atmLev=m -vecRefLength=0.04

A new option atmLev is used in the above call. This is related to the input data, which is taken from an ICON atmosphere simulations. atmLev="m" tells the script to keep the data on the model level rather than perform interpolation into height (h) or pressure (p) levels. For ocean data, this can be left out. If we switch the projection to orthographic, it looks like this:

by adding 'mapType="ortho"' (nclsh: -mapType=ortho) to the above call.

Vertical sections

Data for sections have to be interpolated first. This is done internally and you do not have to care about it. Section plot are created, if a start and an endpoint of a section is given. Therefor the variables secLC (section-left-corner) and secRC (section-right-corner) have to be used. Theses variable have to be (lon,lat) arrays like secLC=(/20.,30./). As an example, 4 plot are show: one for ocean and 3 for atmosphere input based on model, height and pressure level taken from the aqua planet experiment:

Example call for section of atmosphere data on model levels:

ncl icon_plot.ncl 'varName="T"' 'iFile="/home/ram/data/icon/"' 'oFile="test_section_atmm"' 'oType="png"' \
    'secLC=(/0,80/)' 'secRC=(/0,-80/)' showSecMap=False secPoints=100 'atmLev="m"' 'tStrg="atm: model levels"'
nclsh icon_plot.ncl -varName=T -iFile=/home/ram/data/icon/ -oFile=test_section_atmm -oType=png \
    -secLC=0,80 -secRC=0,-80 +showSecMap -secPoints=100 -atmLev=m -tStrg="atm: model levels" 

secPoints is an option to set the accuracy of the plot. The representing of the location of the section is suppressed by setting showSecMap=False. Its default value is True:

The location of the section is not limited. More examples can be found here.

Display the ICON grid

Set the parameter showGrid to True and for scalar variables, the ICON grid is represented instead of the contour plot. For large grids, this can take a long time. See issues #1195 for example plots of edge-grid and vertex-grid. The command

nclsh $ICONPLOT -varName=T -iFile=$f  -ofile=t -showGrid  +mapLine -maskName=wet_c -tStrg='Ocean OMIP experiment' -rStrg=' ' -mapLLC=-100,-15 -mapURC=35,65
results in

Regional plots

Use the variables mapLLC (map-Lower-Left-Corner) and mapURC (map-Upper-Right-Corner) to select special regions of the earth. Here is a list of usefull examples:

Trop. Atlantic 'mapLLC=(/-60, -25/)' 'mapURC=(/ 25,25/)'
North Polar 'mapLLC=(/-200, 20/)' 'mapURC=(/160,90/)'
North Atlantic 'mapLLC=(/-100,-15/)' 'mapURC=(/ 35,65/)'
Labrador/Panama 'mapLLC=(/-200, -5/)' 'mapURC=(/ 35,85/)'
North Atlantic/Eurasia 'mapLLC=(/ -80, -5/)' 'mapURC=(/ 75,85/)'
Asia 'mapLLC=(/ 20,-15/)' 'mapURC=(/160,85/)'


Masking can be done in two different ways:
  1. Manually mask the data with CDO before running the plot scripts, i.e. use the ifthen operator or perform a division with the mask variable:
     cdo div -selname,mask_variable
  2. Let the plot script perform the masking using the NCL's mask function. Therefor the commandline variables maskName and maskFile have to be used. If the mask variable is part of the regular input file, maskFile can be left out.

Both methods have their pros and cons. Whereas the second methods works fine for all types of horizontal representation, the first produces better results for vertical cross sections.


Data on other grids

Although icon_plot.ncl is implemented for ICON, it can be used for data an regular grids, too. In this case, internal interpolation is not performed.


Movies can be generated out of a se to png images. One simple version to do this, is to use the ImageMagick command convert:

convert  rotating_overlay_4*png -set delay 10 t.gif

created an animated gif, which looks like this:

For more examples of using convert for animations, see here. Depending on the speed of the machine and the number of images, this commands can run a minutes, e.g. the above call took about 50sec on my machine. This can be sped up with a real movie encoder. I prefer mencoder because of the good quality and reasonable file size. With

 mencoder "mf://rotating_overlay_4*.png" -mf fps=10 -o rotate_aqpl.avi  -profile mpeg4-mq
the movie creation takes 3 seconds and file size is 3.8MB instead of 6.7MB gif animation. I used a preset of options written down in mencoder configuration file:
[ram@thingol:~]cat .mplayer/mencoder.conf

profile-desc="MPEG4 encoding" 

profile-desc="HQ MPEG4 encoding" 

ffmpeg is another encoder. It's very fast but the results do not gain the quality of mencoder (might be limitted by my knowledge of ffmpeg).

ffmpeg -r 10 -qscale 1 -i '' out.avi
only runs 2 seconds. ffmpeg can generate html5 conform videos, which can be directly played with an appropriate browser. Use
ffmpeg -i rotate_aqpl.avi -s svga rotate_aqpl.webm

You can test it with a html file with the following content:
<html><body><video controls="controls"><source src="" type="video/webm"/></video></body></html>

Because the ICON is a closed project, you have to login to the redmine server with the same session before.


  • For getting a preview instead of write a file, use x11 for output type:
  • For ICON input set isIcon=True or -isIcon. This will speed up the plot generation.

All options

icon_plot.ncl has built-in documentation of all options. Use

ncl icon_plot.ncl help=True 
nclsh icon_plot.ncl -help

Ideas for some new operators

scientific/social perspective

reputation comes with authorship

  1. [->] we have to respect authorship (just like we do with articles)
  2. [->] real collaboration (sharing/developing code) means we have to share authorship (unlike to articles, which to do not change over time)

Need for transparency and well defined collaboration - licenses do not fully solve the problem...

developer perspective

  1. model lifetime is huge compared to hardware cycles and even project lifetimes
  2. [->] model have to be encoded human portable
  3. [*] using long lasting language standard is part of the solution and the problem
    • ++ FORTRAN, MPI, OpenMP and C (more in infrastructure): good compiler support, stable + rich development environment
    • -- missing features of new tools
  4. Students are not nec. trained in FORTRAN, because there are many other options. Don't we loose them? Phd students try to avoid programming models...

Question is: How to keep a stable development flexible?

  1. We love the DRY principe: One piece of code is responsable for one piece of functionality
    But this conflicts with flexibility

whys-poignant-guide-to-ruby.pdf (8.27 MB) Ralf Mueller, 2011-05-19 15:29

instError.tar.gz (29.1 MB) Ralf Mueller, 2011-07-12 13:17

energy-over-time.rb Magnifier (1.34 KB) Ralf Mueller, 2011-10-18 15:19

t-vert-TC33-NoAt.mp4 (1.41 MB) Ralf Mueller, 2011-10-21 15:07

overlay_atm_ortho.png (351 KB) Ralf Mueller, 2012-01-25 11:10

overlay_atm.png (278 KB) Ralf Mueller, 2012-01-25 11:10

test_vector_atm0.png (141 KB) Ralf Mueller, 2012-01-25 11:10

test_vector_atm1.png (114 KB) Ralf Mueller, 2012-01-25 11:10

test_section_oce_withMap.png (87.5 KB) Ralf Mueller, 2012-01-25 11:10

test_section_atmp.png (65.5 KB) Ralf Mueller, 2012-01-25 11:10

test_section_atmm.png (75.6 KB) Ralf Mueller, 2012-01-25 11:10

test_section_atmh.png (82.2 KB) Ralf Mueller, 2012-01-25 11:10

test_icon_plot.png (128 KB) Ralf Mueller, 2012-01-25 11:10

test_section_oce.png (73.9 KB) Ralf Mueller, 2012-01-25 11:10

rotate_aqpl.gif (6.66 MB) Ralf Mueller, 2012-01-25 11:11

ompi_northAtl-grid.png (260 KB) Ralf Mueller, 2012-04-30 20:46 (3.09 MB) Ralf Mueller, 2012-08-06 16:29

cdo.tgz (34.7 KB) Ralf Mueller, 2012-10-18 09:41

cdo.exe (7.05 MB) Ralf Mueller, 2012-10-18 09:45

cdo-current-win32.tgz (3.11 MB) Ralf Mueller, 2012-10-18 10:08 (3.11 MB) Ralf Mueller, 2012-11-13 09:00

cdo-cur.tar.gz (5.88 MB) Ralf Mueller, 2013-03-28 12:56 (7.84 MB) Ralf Mueller, 2013-04-08 14:52 (7.5 MB) Ralf Mueller, 2013-04-24 17:14

cats.rb Magnifier (1.55 KB) Ralf Mueller, 2013-05-22 22:57 (3.09 MB) Ralf Mueller, 2013-09-19 10:33

cdo-1.6.2rc6.tar.gz (6.01 MB) Ralf Mueller, 2013-10-31 16:05 (18.4 MB) Ralf Mueller, 2014-03-27 09:12 (3.08 MB) Ralf Mueller, 2014-09-22 10:20 (2.98 MB) Ralf Mueller, 2014-09-22 10:29

main.f90 Magnifier (835 Bytes) Ralf Mueller, 2014-12-10 11:06

PKGBUILD (1015 Bytes) Ralf Mueller, 2015-01-22 14:53

cdo.exe - cdo binary build with cygwin (9.83 MB) Ralf Mueller, 2015-01-23 13:31

cdo.exe.gz - 1.6.8 cygwin statically linked (5.47 MB) Ralf Mueller, 2015-03-30 14:22

cdo.exe - cygwin on 64bit windows7 - dynamically linked (6.95 MB) Ralf Mueller, 2015-04-24 14:54

cdo.exe - cygwin on 64bit win7, statically linked, hdf5-1.8.14 (9.67 MB) Ralf Mueller, 2015-06-08 13:34

Stammbaum Wolken Clan.txt Magnifier (599 Bytes) Ralf Mueller, 2015-07-02 16:51

clanPlot.rb Magnifier (526 Bytes) Ralf Mueller, 2015-07-02 17:30 (93 Bytes) Ralf Mueller, 2015-09-21 13:17 (600 Bytes) Ralf Mueller, 2015-09-21 13:19

ramsprofile.png (58.6 KB) Ralf Mueller, 2015-11-09 11:33

analytic_forcing_wind_u.png (62.6 KB) Ralf Mueller, 2016-02-19 14:56

analytic_forcing_wind_u_regions.png (117 KB) Ralf Mueller, 2016-02-19 15:04

cdo.exe - 1.7.2 without so (17.3 MB) Ralf Mueller, 2016-06-29 10:11

partSomething.jpg (111 KB) Ralf Mueller, 2016-07-27 10:31

installed-packages.txt Magnifier (5.96 KB) Ralf Mueller, 2017-07-17 13:08