Handling reals in Fortran together with R

前端 未结 2 1260
南方客
南方客 2021-01-25 13:28

I am having trouble handling reals in Fortran, which I use together with R. The following code is written in Fortran:

Subroutine realtest(lol)
implicit none
Real         


        
相关标签:
2条回答
  • 2021-01-25 13:44

    Try using double precision instead of real; the following works for me:

    ! realtest.f90
    !
    subroutine realtest(x)
        implicit none
    
        double precision, intent(inout) :: x
        x = 10.0
    end subroutine realtest
    

    From R,

    dyn.load("realtest.so") 
    res <- .Fortran("realtest", x = as.double(1.2))
    res
    # $x
    # [1] 10
    
    0 讨论(0)
  • 2021-01-25 13:55

    You should declare lol as real*8 since R uses double-precision floating-point number.

    0 讨论(0)
提交回复
热议问题