[f2py] Returning allocatable arrays

John Lowe <[email protected]> Tue, 24 Aug 2010 15:01:26 +1000
Newsgroups gmane.comp.python.f2py.user
Message-ID <[email protected]>
Apologies if this is a simple question. I'm new to fortran, so I might be
missing something obvious.

I'm using f2py with some old F77 code, and thought I'd check before
rewriting the routine completely in python. The original code stores
pointers to arrays in common blocks. The arrays are then resized as
necessary using MALLOC. What I would like to do is be able to access those
arrays from python.

So the original code looks something like:

SUBROUTINE EXAMPLE
    COMMON/block/pntarray
    POINTER(pntarray, array(30,3,1))
    pntarray = MALLOC(some_large_number_of_bytes)
    ! Store stuff in the now large array
   STOP
   END

If I change it to look like:

SUBROUTINE EXAMPLE(array)
    DIMENSION array(30,3,1)

which is what I would do if the array wasn't being resized, then I can't use
a pointer to allocate more memory to array because the array is now a dummy
variable. Is there some way that I can have my function return an array
whose dimensions aren't known until runtime? Alternatively, I can easily get
the pointer stored in the common block from python, but I don't believe it's
possible to use this to access the array.

Thanks,
John

_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users