I am using f2py to compile a numeric module for use with a Python script. I cut my code to the minimum example below:
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)
The commands used to compile and run are as follows (note that I am using cmd on Windows):
gfortran -c fd.f f2py.py -c -m it --compiler=mingw32 fd.o itimes.f reprun.py
Output:
th - it 1.50520876326836550E-163 th - fd 1.50520876326836550E-163
My first assumption is that th somehow is not passed correctly with the reprun.py routine. However, I do not understand this behavior, since the full version of the code includes other inputs, all of which are passed correctly. I couldn't get him to do the same when calling from Fortran, so I assume it has something to do with the Python / Fortran interface. Can anyone explain why this is happening?
EDIT: Replacing th = 200 in the editor with th = 200.0 gives the following result:
th - it 1.19472349365371216E-298 th - fd 1.19472349365371216E-298
astay13
source share