[R] how can I use R functions in Fortran 90
Guo-Hao Huang
guohao.huang at gmail.com
Tue Dec 29 07:23:21 CET 2009
You can read the manual below.
good luck!
http://www.biometrics.mtu.edu/CRAN/doc/manuals/R-exts.html#The-R-API
For example, suppose we want to call R's normal random numbers from FORTRAN.
We need a C wrapper along the lines of
#include <R.h>
void F77_SUB(rndstart)(void) { GetRNGstate(); }
void F77_SUB(rndend)(void) { PutRNGstate(); }
double F77_SUB(normrnd)(void) { return norm_rand(); }
to be called from FORTRAN as in
subroutine testit()
double precision normrnd, x
call rndstart()
x = normrnd()
call dblepr("X was", 5, x, 1)
call rndend()
end
Note that this is not guaranteed to be portable, for the return conventions
might not be compatible between the C and FORTRAN compilers used. (Passing
values via arguments is safer.)
with regards,
Guo-Hao Huang
--------------------------------------------------
From: "Anny Huang" <annylhuang at gmail.com>
Sent: Tuesday, December 29, 2009 1:45 PM
To: <r-help at r-project.org>
Subject: [R] how can I use R functions in Fortran 90
> Hi all,
>
> Is there a way that I can import R functions into Fortran? Especially, I
> want to generate random numbers from some not-so-common distributions
> (e.g.
> inverted chi square) but did not find any routines written in Fortran that
> deal with distributions other than uniform and normal.
>
> Thanks.
> Anny
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list