Re: [f2py] incompatible parameter transfer between python and fortran?

Juergen Wieferink <[email protected]> Tue, 2 Nov 2010 07:05:24 +0100
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Am Sonntag 31 Oktober 2010 22:32:28 schrieb Jon:
> and called by python code as
> 
> import optim
> n=10
> m=10
> optim.hello(n,m)

Please note that this cannot work because of how Python does things
You are passing an object of type integer to some function.  And as
integers are immutable, the object cannot be changed.  Python passes
by object, not by value.

> and restore the two commented statements,
> 
>       integer, intent(in) :: n
>       integer, intent(out) :: m
> 
> then, python complains
> 
> TypeError: optim.hello() takes exactly 1 argument (2 given)
> 
> It seems that f2py does not recognize the intent(out) parameters in the
> fortran code?!

Yes, f2py is kind of smart how to wrap a given routine.  Python can
infer sizes of arrays and pass them automatically, and output
argument are more conveniently returned as function result.

HTH,
Juergen