Hello everyone,

I'm updating the 'astrochron' R package, and I am trying to remove the Fortran 
intrinsic RANDOM_NUMBER from source code, and replace it with R's rand_unif.  
I've followed this approach:

https://cran.r-project.org/doc/manuals/R-exts.html#Calling-C-from-Fortran-and-vice-versa

but on complication I get:

/error: implicit declaration of function 'rand_unif' is invalid in C99 
[-Werror,-Wimplicit-function-declaration]//
//double F77_SUB(getunif)(void) { return rand_unif(); /

I've created the C wrapper, and then call it from the Fortran code as such:

_C-wrapper:_

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

    void F77_SUB(getseed)(void) { GetRNGstate(); }
    void F77_SUB(putseed)(void) { PutRNGstate(); }
    double F77_SUB(getunif)(void) { return rand_unif(); }

_Called from the Fortran as:_

          double precision getunif, e

          CALL getseed()

          e = getunif()

          CALL putseed()

Here is link to the full package with the above code implemented:

https://drive.google.com/file/d/1VyfFoWTAtCSYIqB3CZ8i--xL5E4_qz2w/view?usp=sharing

The relevant source is in /src/asm1.8cR.f and src/getunif.c

Many thanks for any advice!

All the best,

  Stephen Meyers

        [[alternative HTML version deleted]]

______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel

Reply via email to