Converting grads files to NetCDF from within R using CDO

A while back I wrote a blog post on the R package I wrote for reading and manipulating grads data. The library is quite basic, and does not support a number of grads data file options:

  • Using one ctl file, and multiple binary files
  • Some variables have only one vertical level

When I faced data that had these properties, I had a choice to either expand my readGrads library, or convert the data to some other format which was easier to read into R. I chose to convert the data to NetCDF and then reading it using the excellent ncdf library. Luckily I did not have to write a grads to NetCDF conversion tool myself, but I used the cdo tool. This program is “a collection of command line Operators to manipulate and analyse Climate and NWP model Data” (quote from the website). Converting a grads file to NetCDF can be done using the following command:

As I wanted to perform this conversion from within R, I created a function which uses cdo through a system call. The grads2nc function looks like:

With this function loaded into the R session, the conversion can be performed using:

Tagged with: , , ,
Posted in R stuff
2 Comments » for Converting grads files to NetCDF from within R using CDO
  1. wanderer says:

    Hi Paul

    So the command is:
    cdo -f nc import_binary in_grads.ctl

    But we are not specifying the actual binary data file. So for example I have data.grd and metadata.ctl file. How do I convert the data.grd file to netcdf format.

    Thanks in anticipation.

Leave a Reply

Your email address will not be published. Required fields are marked *


To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    Markdown is turned off in code blocks:
     [This is not a link](

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">