メモ帳
参考サイト
http://docs.python.jp/contrib/ctypes/tutorial_jp.html
http://docs.python.jp/2/library/ctypes.html
Fortran ソース・プログラム
module m_common implicit none !DEC$ ATTRIBUTES DLLEXPORT :: n !DEC$ ATTRIBUTES DLLEXPORT :: a integer, bind(c, name = 'n') :: n = 10 real(8), bind(c, name = 'a') :: a(1000) = 0.0 contains subroutine init() bind(c, name = 'init') !DEC$ ATTRIBUTES DLLEXPORT :: init integer :: i print *, 'init', n do i = 1, n a(i) = log(real(i + 1)) print *, i, a(i) end do end subroutine init end module m_common
Python
from ctypes import * mod = CDLL("./x64/release/fvar.dll") m = c_int.in_dll(mod, "n") #scalar variable mod.init() m.value = 20 mod.init() x = (c_double*10).in_dll(mod, 'a') #array x[0:10]