[Rd] Calling Fortran90 code from R

From: Hartwig Deneke <hartwig.deneke_at_gmail.com>
Date: Tue, 29 Dec 2009 10:26:40 +0100

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

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 29 Dec 2009 - 09:30:11 GMT

This archive was generated by hypermail 2.2.0 : Tue 29 Dec 2009 - 12:51:16 GMT