0

我正在尝试从 R 调用 Fortran 90 子例程。我使用创建了共享库

$ ifort -shared -fpic zerounoMatrix.f90 -o zerounoMatrix.so

我用 R 代码调用它

x_axis_pts<-seq(min(xy[,1]),max(xy[,1]),by=min(dx,dy))
y_axis_pts<-seq(min(xy[,1]),max(xy[,2]),by=min(dx,dy))

as.integer(length(x_axis_pts))->lxpts
as.integer(length(y_axis_pts))->lypts
as.integer(length(xy[,1]))->nrow_xy

Mzerouno<-matrix(0,nrow=as.integer(lypts),ncol=as.integer(lxpts))

dyn.load("zerounoMatrix.so")

Mzerouno=.Fortran("zerounomatrix",x_pnts=as.vector(x_axis_pts),
                                  y_pnts=as.vector(y_axis_pts),
                                  lxpnts=as.integer(lxpts),
                                  lypnts=as.integer(lypts),
                                  xy=as.matrix(xy,nrow=dim(xy)[1],ncol=dim(xy)[2]),
                                  nrow_xy=as.integer(nrow_xy))

我调用的子程序有这个声明:

subroutine zerounoMatrix(x_pnts,y_pnts,lxpnts,lypnts,xy,nrow_xy)

 implicit none
 integer, intent(in) :: lxpnts,lypnts, nrow_xy

 real, dimension(lxpnts), intent(in) :: x_pnts
 real, dimension(lypnts), intent(in) :: y_pnts
 real, dimension(nrow_xy,2), intent(in) :: xy

为了测试子程序是否接收到正确的输入,我打印(在子程序内)我给 fortran 调用的向量,但打印出来的值完全错误。它似乎打印随机变量。

没有输出,因为如果获得正确的成分,我想先尝试。

4

0 回答 0