파이썬 스크립트에서 사용할 수 있도록 숫자 모듈을 컴파일하는 데 f2py를 사용하고 있습니다.서브 루틴 인수가 파이썬에서 포트란으로 올바르게 전달되지 않음
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
어떻게 든 itimes
서브 루틴을 reprun.py
에서 제대로 전달되지 않는 것입니다. 그러나 코드의 정식 버전에는 다른 입력이 포함되어 있으며이 코드는 모두 올바르게 전달되므로이 동작을 이해할 수 없습니다. Fortran에서 itimes를 호출 할 때 똑같은 일을 할 수 없었기 때문에, 파이썬/포트란 인터페이스와 관련이 있다고 가정하고 있습니다. 누구든지이 문제가 발생하는 이유에 대한 통찰력을 제공 할 수 있습니까?
편집 :가 th = 200.0
와 reprun.py에 th = 200
교체는 다음과 같은 출력을 얻을 수 :
th - it 1.19472349365371216E-298
th - fd 1.19472349365371216E-298
파이썬이나 f2py에 대해서는 아무 것도 모른다. 그러나 th = 200을 th = 200.0으로 바꾸면 어떻게 될까? –
@HighPerformanceMark, 편집 참조. 여전히 정크 값이지만 다른 값입니다. – astay13