用Fortran和R语言处理实数
我在Fortran中处理reals时遇到问题,我将其与R一起使用。以下代码是用Fortran编写的:用Fortran和R语言处理实数,r,fortran,R,Fortran,我在Fortran中处理reals时遇到问题,我将其与R一起使用。以下代码是用Fortran编写的: Subroutine realtest(lol) implicit none Real lol lol = 10.0 End 我使用命令R CMD SHLIB realtest.f编译。如果我以以下方式运行R中的共享对象: dyn.load("realtest.so") res <- .Fortran("realtest",lol= as.numeric(1.2)) dyn.load(
Subroutine realtest(lol)
implicit none
Real lol
lol = 10.0
End
我使用命令R CMD SHLIB realtest.f
编译。如果我以以下方式运行R中的共享对象:
dyn.load("realtest.so")
res <- .Fortran("realtest",lol= as.numeric(1.2))
dyn.load(“realtest.so”)
res由于R使用双精度浮点数,您应该将lol
声明为real*8
。尝试使用双精度
而不是real
;以下是我的作品:
! realtest.f90
!
subroutine realtest(x)
implicit none
double precision, intent(inout) :: x
x = 10.0
end subroutine realtest
从R
dyn.load("realtest.so")
res <- .Fortran("realtest", x = as.double(1.2))
res
# $x
# [1] 10
dyn.load(“realtest.so”)
res请不要添加任何签名和感谢以及类似于您的帖子。你的名字已经自动放在你的帖子下面了。还要注意,real*8
不是标准的Fortran。