jomulder / BFpack

BFpack can be used for testing statistical hypotheses using the Bayes factor, a Bayesian criterion originally developed by sir Harold Jeffreys.
https://bfpack.info/
14 stars 4 forks source link

Use R random number generator inside Fortran #17

Open cjvanlissa opened 4 years ago

cjvanlissa commented 4 years ago

Here is some code that I found, that might be helpful:

myrandom.c:

#include <R.h>
#include <Rmath.h>

void F77_SUB(fseedi)(void)
{
   GetRNGstate();
}

void F77_SUB(fseedo)(void)
{
   PutRNGstate();
}

void F77_SUB(myrbeta)(double* px, double* pa, double* pb)
{
        *px = rbeta(*pa, *pb);
}

and example.f

       subroutine example(x, a, b)
       implicit double precision (a-h,o-z)
       call fseedi()
       call myrbeta(x, a, b)
       call fseedo()
       end