来自R的Fortran电话:找不到出错的地方

时间:2013-07-14 12:22:31

标签: r fortran90 subroutine

我正试图从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调用的向量但是打印出来的值是完全错误的。它似乎打印随机变量。

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

0 个答案:

没有答案