[f2py] mailing lists, bug, and .f2py_f2cmap, Oh My!
Hi, I have one short question, a possible bug report, and one longer question: 1. (short question) Which mailing list is appropriate for f2py discussion: numpydiscussion or f2pyusers? 2. (bug report?) I'm using numpy from svn (revision 4410). When using f2py to compile, I got an error: File "/home/pschmitt/usr/local/lib/python2.5/sitepackages/numpy/f2py/rules.py", line 1228, in buildmodule for l in '\n\n'.join(funcwrappers2)+'\n'.split('\n'): TypeError: cannot concatenate 'str' and 'list' objects I made what I think should be a fix: $ svn diff numpy/numpy/f2py/rules.py Index: numpy/numpy/f2py/rules.py ===================================================================  numpy/numpy/f2py/rules.py (revision 4410) +++ numpy/numpy/f2py/rules.py (working copy) @@ 1219,7 +1219,7 @@ f.write('! This file is autogenerated with f2py (version:%s)\n'%(f2py_version)) f.write('! It contains Fortran 90 wrappers to fortran functions.\n') lines = []  for l in '\n\n'.join(funcwrappers2)+'\n'.split('\n'): + for l in ('\n\n'.join(funcwrappers2)+'\n').split('\n'): if len(l)>72 and l[0]==' ': lines.append(l[:72]+'&\n &') l = l[72:] but I'm not sure if this is what Pearu wanted with that block of code.... Should I submit a bug report??? 3. (Longer question) I have 3 source files: a) types_QG.f90, which specifies the "types_QG" module: "integer, parameter :: WP=4, intdim=selected_int_kind(8)" b) fftpack.f which is a f77 program to perform fourier transforms in 1D c) fft_lib.f90 which is a f90 program (a f90 module, actually) that uses fftpack.f to do 1,2 or 3D fourier transforms. I want access to access the functions in fft_lib.f90 via Python... So I use f2py! :) I just learned about ".f2py_f2cmap" to handle fortran90 <type spec> (kind=KIND(..)) statements and I'm trying to implement it into my code [http://cens.ioc.ee/projects/f2py2e/FAQ.html#qwhatiffortran90codeusest...]. f2py successfully applies the f2py_f2cmap: make fft gfortran fPIC c types_QG.f90 gfortran fPIC c fftpack.f f2py2.5 fcompiler=gfortran m fft_lib c types_QG.o fftpack.o fft_lib.f90 Reading .f2py_f2cmap ... Mapping "real(kind=wp)" to "float" Mapping "real(kind=WP)" to "float" Mapping "integer(kind=intdim)" to "int" Succesfully applied user defined changes from .f2py_f2cmap ... However, f2py complains about the "kind=" syntax in every single function I have defined in the module within fft_lib.f90. The errors look something like this:
/tmp/tmpeP_IaX/src.linuxi6862.5/fft_libf2pywrappers2.f90:9.16:
real(kind=wp) a(2,2,2) 1 Error: Parameter 'wp' at (1) has not been declared or is a variable, which does not reduce to a constant expression
If I remove every function from the fft_lib.f90 source code, f2py succesfully compiles the Python module, and I can call all the subroutines in fft_lib. Any ideas on what's going on with f2py, the "kind" statement, .f2py_f2cmap, and functions within a f90 module? Thanks, Pete
Here's a simple example to document my problem: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!! types.f90 !!! !!!!!!!!!!!!!!!!!!!!! module types integer, parameter :: WP=4, intdim=selected_int_kind(8) end module types ! end types.f90 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!! hello.f90 !!! !!!!!!!!!!!!!!!!!!!! module hello use types contains subroutine foo (a, b) real(WP), intent(inout) :: a integer(intdim) :: b print*, "Hello from subroutine 'foo'!" a = a * 5.0 print*, " a*5.0=", a print*, " b=", b end subroutine foo function bar(a,b) result(c) real(WP) :: a, b, c print*, "hello from function 'bar'!" c = a*b print*, " a*b=", c end function end module hello !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ################################## ### .f2py_f2cmap: ### {'integer':{'intdim':'int'},'real':{'WP':'float'}} ################################## ################################## ### build the library with gfortran & f2py ### gfortran fPIC c types.f90 f2py2.5 fcompiler=gfortran m hello c types.o hello.f90 Now, the f2py2.5 command fails with errors like:
/tmp/tmpdugvMz/src.linuxi6862.5/hellof2pywrappers2.f90:7.16:
real(kind=wp) a 1 Error: Parameter 'wp' at (1) has not been declared or is a variable, which does not > reduce to a constant expression
I can successfully compile with the f2py2.5 command by commenting out
everything within "function bar .... end function", and the f90
subroutine works fine in Python.
Given this example, any ideas of why I'm getting all the "real(kind=wp)" errors?
Thanks,
Pete
On Nov 7, 2007 11:55 AM, Peter Schmitt
I have 3 source files: a) types_QG.f90, which specifies the "types_QG" module: "integer, parameter :: WP=4, intdim=selected_int_kind(8)" b) fftpack.f which is a f77 program to perform fourier transforms in 1D c) fft_lib.f90 which is a f90 program (a f90 module, actually) that uses fftpack.f to do 1,2 or 3D fourier transforms. I want access to access the functions in fft_lib.f90 via Python... So I use f2py! :)
I just learned about ".f2py_f2cmap" to handle fortran90 <type spec> (kind=KIND(..)) statements and I'm trying to implement it into my code [http://cens.ioc.ee/projects/f2py2e/FAQ.html#qwhatiffortran90codeusest...]. f2py successfully applies the f2py_f2cmap:
make fft gfortran fPIC c types_QG.f90 gfortran fPIC c fftpack.f f2py2.5 fcompiler=gfortran m fft_lib c types_QG.o fftpack.o fft_lib.f90 Reading .f2py_f2cmap ... Mapping "real(kind=wp)" to "float" Mapping "real(kind=WP)" to "float" Mapping "integer(kind=intdim)" to "int" Succesfully applied user defined changes from .f2py_f2cmap ...
However, f2py complains about the "kind=" syntax in every single function I have defined in the module within fft_lib.f90. The errors look something like this:
/tmp/tmpeP_IaX/src.linuxi6862.5/fft_libf2pywrappers2.f90:9.16:
real(kind=wp) a(2,2,2) 1 Error: Parameter 'wp' at (1) has not been declared or is a variable, which does not reduce to a constant expression
If I remove every function from the fft_lib.f90 source code, f2py succesfully compiles the Python module, and I can call all the subroutines in fft_lib.
Any ideas on what's going on with f2py, the "kind" statement, .f2py_f2cmap, and functions within a f90 module?
Thanks, Pete
participants (1)

Peter Schmitt