我想在 R 中使用 fortran 程序,但在运行 R 程序时出现错误。fortran 代码具有二维的 REAL 变量。fortran 的测试代码如下所示:test_inside_program.f90:
program testprogram
implicit none
interface
SUBROUTINE testm(testvar, thelength)
IMPLICIT NONE
REAL, INTENT(IN), DIMENSION(:) :: testvar
INTEGER, INTENT(IN) :: thelength
END SUBROUTINE testm
end interface
REAL, DIMENSION(:),ALLOCATABLE :: testvar
INTEGER :: i
allocate(testvar(3))
DO i = 1,2
testvar(i) = i
ENDDO
call testm(testvar, 3)
write(*,*) 'program finished'
end program testprogram
SUBROUTINE testm(testvar,thelength)
IMPLICIT NONE
INTEGER, INTENT(IN) :: thelength
REAL, INTENT(IN), DIMENSION(:) :: testvar
write(*,*) 'program cont. X'
write(*,*)' THe testvar 1st variable is', testvar
END SUBROUTINE testm
我想从 R 调用子程序 testm。当然我想保持尺寸。因此我在 R 中生成了以下测试代码:test.r
dyn.load("test_inside_program.so")
is.loaded("testm")
dd <- c(5,2,3)
.Fortran("testm",as.single(dd),as.integer(3))
我会很感激你的帮助!我生成.so
R CMD SHLIB test_inside_program.f90