온라인 파기 및 시행 착오를 거친 후, 나는 여전히 파이썬에서 f2py에 의해 Fortran 배열 배열을 전달하는 방법에 대해 궁금해합니다. f2py를 사용하여 Fortran 서브 루틴에 문자열 배열을 전달하는 방법
SUBROUTINE FOO(A)
CHARACTER*5,dimension(10),intent(inout):: A
PRINT*, "A=",A
END
가 그럼 난
f2py -m mystring -c string.f90
을 실행
은 나뿐만
string.f90
에서 포트란 서브 루틴이있다. 컴파일에 성공했습니다.
파이썬 세션이 test.py
에 있습니다
import mystring
import numpy as np
nobstot=10
xstring=np.empty(nobstot,dtype='S5')
xstring[0]="ABCDE"
mystring.foo(xstring)
실행 python test.py
, 나는 오류 메시지가 :
1-th dimension must be 5 but got 0 (not defined).
Traceback (most recent call last) :
File "test.py", line 6, in <module>
mystring.foo(xstring)
mystring.error: failed in converting 1st argument `a' of mystring.foo to C/Fortran array
f2py 컴파일 단계를의 gfortran와 GCC 컴파일러가 호출되었다.
이 >>> print mystring.foo.__doc__
후이 있었다 :
foo(a)
Wrapper for ``foo``.
Parameters
---------
a : in/output rank-2 array('S') with bounds (10,5)
그래서, 나뿐만 test.py
시도 : 다음 python test.py
을 실행
import mystring
import numpy as np
nobstot=10
xstring=np.empty((nobstot,5),dtype='S1')
print xstring.shape
xstring[0]="ABCDE"
mystring.foo(xstring)
을, 오류 메시지가 있었다 :
Traceback (most recent call last):
File "test.py", line 7, in <module>
mystring.foo(xstring)
ValueError: failed to initialize intent(inout) array -- input 'S' not compatible to 'c'
가 인사를 추가하지 마십시오 당신의 게시하다. 이름 옆에 귀하의 이름이 이미 아이콘 근처에 자동으로 표시됩니다. –
@Vladimire F. 알겠습니다. 도와 주셔서 정말로 고맙습니다. –