Problem mit f2py und Common-Blöcken
Verfasst: Samstag 19. Juli 2008, 12:07
Hallo, ich bin gerade dabei mich in f2py einzuarbeiten . Leider komm ich gerade bei einem Testbeispiel nicht weiter.
Irgendwie mag f2py die Commonblöcke in Fortran nicht
Folgenden Fortran-Code möchte ich mit f2py in Python übersetzen.
Dies mach ich mit
f2py test.f -m test -h test.pyf
gefolgt von
f2py -c test.pyf test.f --f90exec=/usr/bin/gfortran
Wie ihr seht bekomme ich den Fehler, dass nint nicht deklariert ist. Leider weiß ich momentan nicht wie ich das Problem lösen könnte ohne den kompletten Quelltext umzustrukturieren.
Mit gfortran, pathf90 und ifort kann ich den Quelltext problemlos übersetzen, also denke ich, dass der Fehler bei f2py liegt.
Wer kann mir helfen???
Irgendwie mag f2py die Commonblöcke in Fortran nicht
Folgenden Fortran-Code möchte ich mit f2py in Python übersetzen.
Code: Alles auswählen
program test
c
integer nint
common /sizes/ NINT
c
real work(10)
c
nint = 10
c
call set(work)
c
call output(work)
c
end
c
c---------------
c
subroutine set(work)
c
integer nint
common /sizes/ nint
c
integer i
real work(nint)
c
do 10 i=1,nint
work(i)=real(i)**2
10 continue
c
end
c-------------------------
c
subroutine output(work)
c
integer nint
common /sizes/ nint
c
integer i
real work(nint)
c
do 10 i=1,nint
print*,work(i)
10 continue
c
end
c
f2py test.f -m test -h test.pyf
Code: Alles auswählen
Reading fortran codes...
Reading file 'test.f' (format:fix,strict)
Post-processing...
Block: test
Block: test
Block: set
Block: output
Post-processing (stage 2)...
Saving signatures to file "./test.pyf"
f2py -c test.pyf test.f --f90exec=/usr/bin/gfortran
Code: Alles auswählen
running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
building extension "test" sources
creating /tmp/tmpYFlHNR
creating /tmp/tmpYFlHNR/src.linux-i686-2.5
f2py options: []
f2py: test.pyf
Reading fortran codes...
Reading file 'test.pyf' (format:free)
Post-processing...
Block: test
Block: set
Block: output
Post-processing (stage 2)...
Building modules...
Building module "test"...
Constructing wrapper function "set"...
set(work)
Constructing wrapper function "output"...
output(work)
Constructing COMMON block support for "sizes"...
nint
Wrote C/API module "test" to file "/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c"
Fortran 77 wrappers are saved to "/tmp/tmpYFlHNR/src.linux-i686-2.5/test-f2pywrappers.f"
adding '/tmp/tmpYFlHNR/src.linux-i686-2.5/fortranobject.c' to sources.
adding '/tmp/tmpYFlHNR/src.linux-i686-2.5' to include_dirs.
copying /usr/lib/python2.5/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmpYFlHNR/src.linux-i686-2.5
copying /usr/lib/python2.5/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmpYFlHNR/src.linux-i686-2.5
adding '/tmp/tmpYFlHNR/src.linux-i686-2.5/test-f2pywrappers.f' to sources.
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
customize GnuFCompiler
Could not locate executable g77
Could not locate executable f77
customize IntelFCompiler
Found executable /usr/bin/gfortran
Found executable /usr/bin/ifort
customize LaheyFCompiler
Could not locate executable lf95
lahey: no Fortran 77 compiler found
lahey: no Fortran 77 compiler found
customize PGroupFCompiler
Could not locate executable pgf77
pg: no Fortran 77 compiler found
Could not locate executable pgf90
pg: no Fortran 77 compiler found
customize AbsoftFCompiler
absoft: no Fortran 77 compiler found
absoft: no Fortran 77 compiler found
customize NAGFCompiler
Found executable /usr/bin/f95
customize VastFCompiler
customize GnuFCompiler
customize CompaqFCompiler
Could not locate executable fort
compaq: no Fortran 77 compiler found
compaq: no Fortran 77 compiler found
customize IntelItaniumFCompiler
customize IntelEM64TFCompiler
customize Gnu95FCompiler
Found executable /usr/bin/gfortran
customize Gnu95FCompiler
customize Gnu95FCompiler using build_ext
building 'test' extension
compiling C sources
C compiler: gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC
creating /tmp/tmpYFlHNR/tmp
creating /tmp/tmpYFlHNR/tmp/tmpYFlHNR
creating /tmp/tmpYFlHNR/tmp/tmpYFlHNR/src.linux-i686-2.5
compile options: '-I/tmp/tmpYFlHNR/src.linux-i686-2.5 -I/usr/lib/python2.5/site-packages/numpy/core/include -I/usr/include/python2.5 -c'
gcc: /tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c: In Funktion »f2py_rout_test_set«:
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:150: Fehler: »nint« nicht deklariert (erste Benutzung in dieser Funktion)
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:150: Fehler: (Jeder nicht deklarierte Bezeichner wird nur einmal aufgeführt
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:150: Fehler: für jede Funktion in der er auftritt.)
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c: In Funktion »f2py_rout_test_output«:
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:232: Fehler: »nint« nicht deklariert (erste Benutzung in dieser Funktion)
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c: In Funktion »f2py_rout_test_set«:
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:150: Fehler: »nint« nicht deklariert (erste Benutzung in dieser Funktion)
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:150: Fehler: (Jeder nicht deklarierte Bezeichner wird nur einmal aufgeführt
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:150: Fehler: für jede Funktion in der er auftritt.)
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c: In Funktion »f2py_rout_test_output«:
/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c:232: Fehler: »nint« nicht deklariert (erste Benutzung in dieser Funktion)
error: Command "gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/tmp/tmpYFlHNR/src.linux-i686-2.5 -I/usr/lib/python2.5/site-packages/numpy/core/include -I/usr/include/python2.5 -c /tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.c -o /tmp/tmpYFlHNR/tmp/tmpYFlHNR/src.linux-i686-2.5/testmodule.o" failed with exit status 1
Mit gfortran, pathf90 und ifort kann ich den Quelltext problemlos übersetzen, also denke ich, dass der Fehler bei f2py liegt.
Wer kann mir helfen???