Nach einigen Online-Graben und Trial-Fehler, frage ich mich immer noch, wie übergeben Arrays von Strings von Python zu Fortran von f2py.Wie man Zeichenketten an Fortran Subroutine mit f2py übergeben
Ich habe die Fortran-Unterprogramm in string.f90
als:
SUBROUTINE FOO(A)
CHARACTER*5,dimension(10),intent(inout):: A
PRINT*, "A=",A
END
Dann laufe ich f2py -m mystring -c string.f90
. Das Kompilieren war erfolgreich.
Die Python-Sitzung in test.py
ist:
import mystring
import numpy as np
nobstot=10
xstring=np.empty(nobstot,dtype='S5')
xstring[0]="ABCDE"
mystring.foo(xstring)
Run python test.py
, ich habe die Fehlermeldung:
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
Im f2py Kompilieren Schritt die gfortran und gcc-Compiler wurden aufgerufen.
Nach >>> print mystring.foo.__doc__
gab es:
foo(a)
Wrapper for ``foo``.
Parameters
---------
a : in/output rank-2 array('S') with bounds (10,5)
So habe ich versucht, test.py
wie:
import mystring
import numpy as np
nobstot=10
xstring=np.empty((nobstot,5),dtype='S1')
print xstring.shape
xstring[0]="ABCDE"
mystring.foo(xstring)
Dann python test.py
laufen, wird die Fehlermeldung lautet:
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'
nicht Grüße Fügen Sie zu Ihrem Post. Ihr Name wird automatisch in der Nähe Ihres Symbols unter Ihre Frage gestellt. –
@Vladimire F. Verstanden. Vielen dank für Deine Hilfe. –