Re: [f2py] Wraping Fortran code with allocatable arrays.

Jürgen Wieferink <[email protected]>
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Benjamin Kutz wrote (Friday 16 July 2010 10:18:52):
> When it comes to allocatable arrays I have a problem. As far as I know I
> can`t share an allocatable array with a common block. So I have to share
> it in the parameter list of the subroutine. That means, that in case of
> a wrapped routine I have to pass this array to Python and back to the
> next wrapped Fortran routine. Therefore I have chosen the following
> implementation.

You cannot share allocatable arrays within common blocks, true.  But
then, common blocks are, well, depricated, to put it mildly.  Your
situation cries for using a fortran module with allocatable arrays
as module data.  

> !    -*- f90 -*-
> python module foo ! in
>      interface  ! in :foo
>          subroutine init(abc,deg) ! in :foo:init.f
>              real allocatable,dimension(:), intend(out) :: abc
>              real allocatable,dimension(:,:), intend(out) :: deg
>          end subroutine init
>          subroutine calc(abc,deg) ! in :foo:calc.f
>              real allocatable,dimension(:), intend(in,out) :: abc
>              real allocatable,dimension(:,:), intend(in,out) :: deg
>          end subroutine calc
>      end interface
> end python module foo

Allocatable arrays in subprocedure interfaces, on the other hand,
are a rather new feature, not introduced before Fortran 2003.  It is
by no way supported by f2py.  But you know that you need to state
'allocatable' in the interface only if you really plan to allocate
it from within, which is not that common to do.?

Juergen



-- 
Juergen Wieferink
Fritz-Haber-Institut der Max-Planck-Gesellschaft (Theory)
Faradayweg 4-6, 14195 Berlin-Dahlem (Germany)
Phone: +49 30/8413-4826, Fax:  +49 30/8413-4701
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.