[R] how to call C from Fortran?

Prof Brian D Ripley ripley at stats.ox.ac.uk
Fri Feb 1 17:23:46 CET 2002


On Fri, 1 Feb 2002, Liaw, Andy wrote:

> Dear R-help,
>
> In the R-ext manual, section 5.6 ("Calling C from FORTRAN and vice versa"),
> it seems like only the "vice versa" part is covered.  Can someone explain
> (or give an example) on how to do this?  In particular:
>
> o  Is it possible to call the R RNG from Fortran?
> o  Is it possible to call the utility routines such as sorting and ranking?

No, no (directly)

You need to write wrappers in C, declaring entry points with F77_SUB (so
it is covered in that section).

void F77_SUB(forrnd)(double *result)
{
   result[0] = unif_rand();
}

should do the job for the first (untested).

You may be able to define Fortran functions in C, but that is highly
platform-dependent (including compiler-dependent), as return conventions
are not standardized, and on Windows not even documented.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list