[Rd] Calling Fortran90 code from R

Hartwig Deneke hartwig.deneke at gmail.com
Tue Dec 29 10:26:40 CET 2009


Dear all,

I am currently trying to create a package wrapping Fortran90 code, the
RRTMG radiative transfer model( http://rtweb.aer.com/rrtm_frame.html).
I am doing this on a Linux workstation, with gcc/gfortran, in case
this matters. The code heavily relies on F90 features, in particular
modules, which seem to clash with R's assumptions for calling compiled
code.

What I have done:
-compiled the files to mod/object files using gfortran
-am able to create a dynamic link library "librrtmg.so"

Further experiments:
- dyn.load('librrtmg.so') works
-. with "objdump -T librrtmg.so", I have found the following function
symbols to call:
    1. __rrtmg_lw_init_MOD_rrtmg_lw_ini (the initialization of the code)
    2. __rrtmg_öw_rad_MOD_rrtmg_lw (the actual main function I want
to call to do the calculations)
- These symbols are found via "is.loaded", but only without specifying
"type='FORTRAN'" (I have experimented with upper/lowercase letters as
well as dropping the leading underscores)
- I have not been able to call these routines via the ".Fortran" interface.
- I do managed to call a simple F90 subroutine (with similar argument
list, for experimentation) via the ".C" interface. However, I am not
able to  pass 2D field of type "DOUBLE", but always get a crash.

Is there any official way for calling Fortran90 libraries which I
missed (I have both searched through the documentation and this list)?
Any advice how to go about this? My best idea at the moment seems to
be to write a simple C wrapper for the Fortran routines, and call the
wrapper from R. If needed, I can also post some code from my
experiments. I'd actually like to get something which could be
submitted to CRAN out of this (are there any other packages depending
on Fortran90 code?)

Thanks in advance for any help,
Hartwig Deneke



More information about the R-devel mailing list