[Numpy-discussion] f2py with allocatable arrays
Casey W. Stark
Mon Jul 2 20:17:59 CDT 2012
Does anyone know if f2py supports allocatable arrays, allocated inside
fortran subroutines? The old f2py docs seem to indicate that the
allocatable array must be created with numpy, and dropped in the module.
Here's more background to explain...
I have a fortran subroutine that returns allocatable positions and
velocities arrays. I wish I could get rid of the allocatable part, but you
don't know how many particles it will create until the subroutine does some
work (it checks if each particle it perturbs ends up in the domain).
subroutine ics(..., num_particles, particle_mass, positions, velocities)
use data_types, only : dp
... inputs ...
integer, intent(out) :: num_particles
real (kind=dp), intent(out) :: particle_mass
real (kind=dp), intent(out), dimension(:, :), allocatable :: positions,
I tested this with a fortran driver program and it looks good, but when I
try with f2py, it cannot compile. It throws the error "Error: Actual
argument for 'positions' must be ALLOCATABLE at (1)". I figure this has
something to do with the auto-generated "*-f2pywrappers2.f90" file, but the
build deletes the file.
If anyone knows an f2py friendly way to rework this, I would be happy to
try. I'm also fine with using ctypes if it can handle this case.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion