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 呼び出しに与えるベクトルを出力しますが、出力される値は完全に間違っています。ランダム変数を出力しているようです。
適当な材料が手に入ったら試してみたいのでアウトプットなし。