Re: [f2py] Wraping Fortran code with allocatable arrays.
Jürgen Wieferink <[email protected]>
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Hi,
module mymod
implicit none
real, dimension(:), allocatable :: abc
real, dimension(:,:), allocatable :: deg
contains
subroutine init
implicit none
! do stuff on abc, deg
end subroutine init
subroutine calc
implicit none
! do stuff on abc, deg
end subroutine calc
end module mymod
From this, you can easily generate the wrapper mymod.pyf from
$ f2py -m _mymod -h mymod.pyf mymod.f90
As Pearu mentioned, even the allocatable arrays are then exposed to
python as _mymod.mymod.abc and _mymod.mymod.deg.
Juergen
Benjamin Kutz wrote (Friday 16 July 2010 14:12:05):
>
> Hi,
>
> thanks for your fast answer.
> I still didn`t got the point. I just want to share these allocatable
> data arrays between the first and the second subroutine.
> I also knew the example out of the f2py manual, but I couldn`t realise
> it in my code, due to my limited knowledge in python and wrapping.
> Do you mean, that I have to write a fortran module for each allocatable?
> What does this module look like?
> At the moment I allocate in Fortan at the beginning with:
>
> subroutine init(abc,deg)
> integer max, max2
> max= ...
> max2=...
> real , dimension (:) , allocatable :: abc
> real , dimension (:,:) , allocatable :: deg
> allocate (abc(max))
> allocate (deg(max,max2))
> call initialxyz (abc,deg)
> end
>
> subroutine calc(abc,deg)
> call solve(abc,deg)
> if ( allocated( abc ) ) then
> deallocate (abc)
> ...
> endif
>
> I wrap both routines and want to call them one after another from python.
> Maybe you can help me with a little example? What does the foo.pyf have
> to look like?
> The problem is, that I have to wrap with f2py -c foo.pyf *.o. I can't
> wrap it directly from the foo.f90 routine.
>
> Greetings
> Ben
>
> _______________________________________________
> f2py-users mailing list
> f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
> http://cens.ioc.ee/mailman/listinfo/f2py-users
>