Subroutine argument not passed correctly from Python to Fortran

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 
+3
source share
1 answer

Include the itime routine in the module. Here is what I did:

itimes.f90:

 module itime contains subroutine itimes(th) use fd implicit none real(dp) th write(*,*) 'th - it',th call lprsmf(th) end subroutine itimes end module 

compile and run:

 gfortran -c fd.f90 c:\python27_w32\python.exe c:\python27_w32\scripts\f2py.py -c -m it --compiler=mingw32 fd.f90 itimes.f90 

run runun.py:

 import it th = 200 it.itime.itimes(th) 

exit:

  th - it 200.00000000000000 th - fd 200.00000000000000 
+1
source

All Articles