Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Fortran functions from R

Tags:

r

fortran

It is straight forward to call a Fortran subroutine from R using .Fortran and there are examples available online. However, I haven't found any direct way to call a Fortran function from R.

Currently, I use an interface for that, which gets the Fortran function and uses it in a subroutine, but it is very time consuming to do so for all external functions.

Is there an elegant way to call Fortran functions directly from R?

like image 365
Moji Avatar asked Sep 18 '25 10:09

Moji


1 Answers

With .Fortran (and .C) it is not possible to use Fortran functions, as noted in the documentation:

Note that the compiled code should not return anything except through its arguments: C functions should be of type void and Fortran subprograms should be subroutines.

Using .Call (and .External) it is possible to call Fortran functions, but it's fair to say that doing this makes writing a subroutine wrapper for the Fortran function look trivial: minimally you'll be writing a C wrapper to be invoked in the middle (making this another "indirect" Fortran function call - directly calling a Fortran function will require even more effort).

like image 184
francescalus Avatar answered Sep 20 '25 00:09

francescalus