Skip to content
Prev 300995 / 398503 Next

translating IDL to R

R can do all this, but you'll need to get into specifics a little
more. Most of your code is covered by R's ?read.table, ?data.frame,
?array, ?file and ?Extract.  See the ncdf (or ncdf4 or RNetCDF)
package for examples that will look quite similar to the IDL code that
opens a NetCDF file.

You could do a more or less direct translation of this IDL code to R,
but for us to help easily we probably need example data files. These
are fairly basic I/O and array manipulation operations, and The
Introduction to R and R Import/Export manuals cover that well.

A small example translation:

 nlon = 720 ## number of grid points by longitude
 nlat = 360 ## number of grid points by latitude
 gfedmly = array(0.0, c(nlon,nlat)) ## array containing monthly emissions
 gfeddly = array(0.0, c(nlon,nlat)) ## array containing daily emissions

To start populating those arrays from your files we would need much
more detail about them, and as ever with arrays you need to be aware
of the orientation conventions, and depending on your data you should
explore the spatial support functions in sp and raster and rgdal. See
the R Spatial Task View, you'll find much more integrated support in R
than this IDL code shows and it's probably easier for you to jump
straight into that level.


Cheers, Mike.
On Tue, Jul 24, 2012 at 9:55 AM, Tom Roche <Tom_Roche at pobox.com> wrote: