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

Leave a Reply