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" <annylhu...@gmail.com>
Sent: Tuesday, December 29, 2009 1:45 PM
To: <r-help@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@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.


______________________________________________
R-help@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.

Reply via email to