how can I use R functions in Fortran 90

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how can I use R functions in Fortran 90

Anny Huang
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]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: how can I use R functions in Fortran 90

Guo-Hao Huang

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" <[hidden email]>
Sent: Tuesday, December 29, 2009 1:45 PM
To: <[hidden email]>
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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: how can I use R functions in Fortran 90

Mike Prager
In reply to this post by Anny Huang
Anny Huang <[hidden email]> wrote:

> 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.

If you are interested in pure Fortran code for the problem, you
could look at routine G01FCF here:

http://gams.nist.gov/search.cgi?Pattern=chi+square&Boolean=AND&Match=Full&Limit=100&Show=Yes

GAMS (the Guide to Available Mathematical Software) has a lot of
good code.



--
Mike Prager, NOAA, Beaufort, NC
* Opinions expressed are personal and not represented otherwise.
* Any use of tradenames does not constitute a NOAA endorsement.

______________________________________________
[hidden email] 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.