我使用f2py编译一个数值模块,供Python脚本使用。我将代码简化为下面的最小示例:
财务总监:
module fd
! Double precision real kind
integer, parameter :: dp = selected_real_kind(15)
contains
subroutine lprsmf(th)
implicit none
real(dp) th
write(*,*) 'th - fd',th
end subroutine lprsmf
end module fd
时间。f:
^{pr2}$在reprun.py公司名称:
import it
th = 200
it.itimes(th)
用于编译和运行的命令如下(请注意,我在Windows下使用cmd
):
gfortran -c fd.f
f2py.py -c -m it --compiler=mingw32 fd.o itimes.f
reprun.py
输出为:
th - it 1.50520876326836550E-163
th - fd 1.50520876326836550E-163
我的第一个猜测是th
以某种方式没有从reprun.py
正确地传递到子例程{
编辑:替换th = 200
reprun.pywith th = 200.0
生成以下输出:
th - it 1.19472349365371216E-298
th - fd 1.19472349365371216E-298
将itimes子例程也包装在一个模块中。以下是我所做的:
itimes.f90:
编译和运行:
^{pr2}$跑reprun.py公司名称:
^{3}$输出:
相关问题 更多 >
编程相关推荐