[f2py] Basic question? (without typo)
Robert Kern
robert.kern at gmail.com
Wed Oct 3 22:22:37 EEST 2007
Andreas Kring wrote:
> (sorry, this version should be correct).
>
> Hello,
>
> I'm new to f2py and have a very basic question. Consider the follow
> fortran90 file (called test.f90) and the following few lines of python.
>
> ---
> subroutine add(x,y,z)
>
> implicit none
> integer::x,y,z
>
> z=x+y
>
> end subroutine add
> ---
>
> $ f2py -c test.f90 -m test
>
>>>> from test import add
>>>> a,b,c=1,2,7
>>>> add(a,b,c)
>>>> c
> 7
>
> Why is c not equal to 3?
Python integers are immutable. They cannot be changed (technically not true in C
modules, but a well-behaved C module like those f2py generates won't). Even if
the argument were mutable, like a numpy array, the default intent of arguments
is considered to be intent(in), not intent(inout). However, in this case, `c` is
really an intent(out) argument, and you should declare it so, otherwise f2py
won't know. Then call the function from Python like so:
c = add(a, b)
> Shouldn't this be the case when comparing to
> the example in the Users Guide
> (http://cens.ioc.ee/projects/f2py2e/usersguide/index.html#introduction)?
Which example?
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the f2py-users
mailing list