最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

与R一起在Fortran中处理实数

SEO心得admin35浏览0评论
本文介绍了与R一起在Fortran中处理实数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在处理与R一起使用的Fortran中的实数时遇到麻烦.以下代码用Fortran编写:

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 lol lol = 10.0 End

我用命令R CMD SHLIB realtest.f进行编译.如果我在R中以以下方式运行共享库:

I compile with the command R CMD SHLIB realtest.f. If I run the shared object in R as:

dyn.load("realtest.so") res <- .Fortran("realtest",lol= as.numeric(1.2))

lol的结果值为1.2,但应该为10.如果我用Integers进行整件事,我会得到正确的值10.

The resulting value of lol is 1.2, but it should have been 10. If I do the whole thing with Integers instead, I get the correct value 10.

推荐答案

尝试使用double precision代替real;以下对我有用:

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

从R

dyn.load("realtest.so") res <- .Fortran("realtest", x = as.double(1.2)) res # $x # [1] 10
发布评论

评论列表(0)

  1. 暂无评论