[Numpy-discussion] [f2py] mailing lists, bug, and .f2py_f2cmap, Oh My!

Peter Schmitt pschmittml at gmail.com
Wed Nov 7 17:10:28 EST 2007


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.linux-i686-2.5/hello-f2pywrappers2.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 <pschmittml at gmail.com> wrote:
> 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#q-what-if-fortran-90-code-uses-type-spec-kind-kind].
>  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.linux-i686-2.5/fft_lib-f2pywrappers2.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
>



More information about the NumPy-Discussion mailing list