我写了一个Fortran子程序来计算数组的大小,我想直接在R中得到结果.但是,我没有得到预期的结果.
首先,我建立了size95.f95
文件
subroutine fsize(x, n)
double precision, intent(in):: x(:)
integer, intent(out) :: n
n = size(x)
end subroutine fsize
然后在Windows的CMD上编译,
R CMD SHLIB size95.f95
虽然,在我加载并测试了一个10个元素的向量在R中,我得到的长度为1而不是10.
x <- 1:10
dyn.load("size95.dll")
dotCall64::.C64("fsize",
SIGNATURE = c("double", "integer"),
INTENT = c("r", "w"),
x=x, n=dotCall64::integer_dc(1))
# $x
# NULL
#
# $n
# [1] 1
所需的输出应该是
# $x
# NULL
#
# $n
# [1] 10