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

Xavier Barthelemy <[email protected]> Mon, 1 Nov 2010 09:24:35 +1100
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Hi Jon

I think it's because you are mixing fortran declaration and f2py
variable declaration.

first you have to tell f2py what you really wants to do:

     subroutine hello(n,m)
      implicit none
!f2py integer, intent(in) :: n
!f2py integer, intent(out) :: m
      integer n,m
      print*,'hello world ',n
      m = n + 5
      end

and then, the intend(out) has automatically the hidden attribute: That
means the correct call in python will be

import optim
n=10
m=10
m=optim.hello(n)

you can confirm this with the autodocumentation
import optim
print optim.__doc__

hope it helps
Xavier



2010/11/1 Jon <[email protected]>:
> Hello,
>
> I have the following code, compiled by f2py,
>
>       subroutine hello(n,m)
>       implicit none
> !      integer, intent(in) :: n
> !      integer, intent(out) :: m
>       integer n,m
>       print*,'hello world ',n
>       m = n + 5
>       end
>
> and called by python code as
>
> import optim
> n=10
> m=10
> optim.hello(n,m)
>
> The execution result is: the parameter m is not changed, as if only a formal
> parameter is transferred to hello,
>
> if I comment out
>
> integer n,m
>
> 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?!
>
> Any idea towards these issues? Thanks a lot!
>
> Jon
>
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>
>



-- 
 « Quand le gouvernement viole les droits du peuple, l'insurrection
est, pour le peuple et pour chaque portion du peuple, le plus sacré
des droits et le plus indispensable des devoirs »

Déclaration des droits de l'homme et du citoyen, article 35, 1793