내 최종 게임은 필자가 작성한 여러 가지 Fortran 스크립트를 가져 와서 Python을 통해 인터페이스하는 것입니다. 스크립트 자체는 상대적으로 간단합니다. 본질적으로 배열보다 복잡한 프로그래밍 구조가 없어도 많은 수학이 가능합니다. 그러나, 나는 이것에 아주 새롭다, 그래서 나는 그것을 밖으로 시도하고있는 작은 시험 원본이있다.f2py Fortran 모듈에서 변수 복구하기
주요 스크립트 (축약 된 형태) 다음과 같습니다 :
subroutine addwake
use geometry
implicit none
integer::i,j,k,m
real(kind=8),allocatable::xn2(:,:),yn2(:,:),zn2(:,:)
real(kind=8)::avg,m1,m2,m0
character(50)::namefile
!f2py intent(out) i,j,k,m
!f2py intent(out),allocatable xn2,yn2,zn2
!f2py intent(out) avg,m1,m2,m0
!f2py intout(out) namefile
! Check if surface node arrays are allocated
if(allocated(xn))then
deallocate(xn,yn,zn)
end if
! Read in sectional point distribution
...
end subroutine addwake
이 내 슬픔의 근원 모듈 (geometry.f95)를 사용합니다.
module geometry
implicit none
! panel coordinates and connectivity
integer::jmax,kmax
integer::npts_wake
real(kind=8)::dspan
real(kind=8),allocatable::xn(:,:),yn(:,:),zn(:,:)
!f2py intent(out) jmax,kmax,npts_wake
!f2py intent(out) dspan
!f2py intent(out),allocatable xn,yn,zn
end module geometry
나는 f2py -c -m wake geometry.f95 addwake.f95
를 통해 직접 코드를 컴파일하고 실행하기 위해 파이썬 인터프리터로 이동합니다. 그것은 잘 실행, 내게 기대 출력 (주문 숫자 목록과 텍스트 파일),하지만 난 내 통합 프레임 워크에서 할 수 있어야 할 것입니다 변수 값을 추출하려고합니다. 나는 그 때, 나는 다음과 같은 결과를 얻을 : 나는 각 변수는 한 줄에 정의되도록 geometry.f95에 f2py 선언을 변경하는 경우
>>> print wake.geometry.xn
[[ 2.01331785 2.01331785 2.01331785 2.01331785 2.01331785]
[ 2.00308232 2.00308232 2.00308232 2.00308232 2.00308232]
[ 1.99284679 1.99284679 1.99284679 1.99284679 1.99284679]
...,
[ 0.979798 0.979798 0.979798 0.979798 0.979798 ]
[ 0.989899 0.989899 0.989899 0.989899 0.989899 ]
[ 1. 1. 1. 1. 1. ]]
>>> print wake.geometry.yn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: yn
>>> print wake.geometry.zn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: zn
을, 나는 세 가지 변수의 속성 오류가 발생합니다. 나는 여기에서 꽤 난처하게된다, 어떤 생각이라도?