我正在使用f2py编译供Python脚本使用的数字模块。我减少了我的代码下面的小例子:子程序参数没有从Python正确传递到Fortran
fd.f:
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
itimes.f:
subroutine itimes(th)
use fd
implicit none
real(dp) th
write(*,*) 'th - it',th
call lprsmf(th)
end subroutine itimes
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
子程序itimes
。但是,我不理解这种行为,因为完整版本的代码包含其他输入,所有这些都是正确传递的。从Fortran调用itime时,我无法让它做同样的事情,所以我假设它与Python/Fortran接口有关。任何人都可以提供有关这种行为发生的原因吗?
编辑:在reprun.py与th = 200.0
更换th = 200
产生以下的输出:
th - it 1.19472349365371216E-298
th - fd 1.19472349365371216E-298
我对Python或f2py一无所知,但如果用th = 200.0替换th = 200,会发生什么? –
@HighPerformanceMark,请参阅编辑。这仍然是一种垃圾价值,但是不同。 – astay13