[f2py] fortran module crahes from time to time

volker lorrmann at physik.uni-wuerzburg.de
Mon Nov 12 15:17:42 EET 2007


Hello list again!

I've written an easy python module, that findes the indices in an array, where
the sign of the data changes, in fortran and wrapped it with f2py. From time to
time the python crashes using the function. Here's what i've done:

FORTRAN CODE

        subroutine chsign(ar_in,ar_out,n,i)
        integer n,i,ar_out(0:n-1)
        real*8 ar_in(0:n-1)
Cf2py   intent(in) ar_in
Cf2py   intent(out) ar_out
        do i=0,n-1
            if ((ar_in(i).lt.0).and.(ar_in(i+1).gt.0)) then
                ar_out(i+1)=1
            elseif ((ar_in(i).gt.0).and.(ar_in(i+1).lt.0)) then
                ar_out(i+1)=1
            else
                ar_out(i+1)=0
            endif
        enddo
        return
        end

I've compile this code with: f2py -m _chsign -c chsign.f
And wrote a python wrapper for this function
 
PYTHON WRAPPER

from mystuff.chsign import _chsign
from numpy import where


def get_index(ar):
    a_int = fchsign.chsign(ar)
    a_ind = where(a_int==1)[0]
    return a_ind


Then I load some data n an ipython session and used my module. 

data=load('somdata')
I=data[:,1]

chsign.get_index(I)          #this mostly works well, but not always

chsign. get_index(diff(I))   # this most of the time crashs python

Here's the error:

*** glibc detected *** /usr/bin/python: malloc(): memory corruption: 0x08f262e0 

Any tips?

volker









More information about the f2py-users mailing list