gfortranでDLL作成
gfortran --shared -o hoge.dll hoge.f90
でDLL作成
subroutine plus(a,b,c)
double precision,intent(in) :: a,b
double precision,intent(out) :: c
c=a+b
end subroutine plus
Rでplus.dllを使用したい場合
注意点:subroutineであること
引数の型は強制的に変換する事
dyn.load("plus.dll")
plus <- function(a,b){
.Fortran("plus",
arg1=as.double(a),
arg2=as.double(b),
arg3=double(1)
)
}
引数が行列の時は
arg1=matrix(as.integer(a),nrow=2,ncol=2)
戻り値が行列の時は、
arg3=matrix(double(4),nrow=2,ncol=2)
とでもする
最終更新:2008年01月10日 22:03