Re: [f2py] Wraping Fortran code with allocatable arrays.
Benjamin Kutz <[email protected]>
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <[email protected]> |
Am 16.07.2010 11:20, schrieb Jürgen Wieferink:
> 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
>
>
>
>
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