memoring - その他

f2Py

fortranのサブルーチンをpythonで使う。例えば
subroutine test(in)

real, dimension(:), intent(in) :: in
real, intent(out) :: out(size(in))

out = in*5.0
のようなサブルーチンtest.f90を使う場合。
$ f2py -c -m mytest test.f90
とするとmytest.soというライブラリができるので
import mytest

out = mytest.test(in)
のようにpythonから呼ぶことができる。

f2pyで使用可能なコンパイラを調べる

$ f2py -c --help-fcompiler
コンパイラは、
$ f2py -fcompiler=gnu
で指定できる。