Question

I have some routines written in fortran that I'd like to use in my python code. A quick websearch informed me about f2py, and I gave it a try. Using

 f2py -c numericalMethods.f -m numericalMethods

it seems to work for a while until a lot of errors are spawn during the conversion. Any idea of why the following bit of code fails to work with f2py?

  SUBROUTINE n_bezier(t, nx2, BezX, BezY)
  PARAMETER (N_SEG=130)
  PARAMETER (nmax=130)
  DOUBLE PRECISION t(nmax)
  DOUBLE PRECISION nx2(nmax)
  DOUBLE PRECISION BezX(N_SEG), BezY(N_SEG)
  DOUBLE PRECISION coeff(nmax)
  INTEGER i, j
  DOUBLE PRECISION r,fact


  do i = 1, N_SEG
    r = real(i) / real(N_SEG)
    BezX(i) = 0 
    BezY(i) = 0
    do j=1,nmax 
        coeff(j) = BICO(nmax,j) *
 .                 (1-r)**(nmax-j) * r**j
        print*, 'coeff for j= ', j, ' --> ', coeff(j) 
    if(coeff(j).ne.0) then
            BezX(i) = BezX(i) + coeff(j)*t(j)
            BezY(i) = BezY(i) + coeff(j)*nx2(j)
        endif
    enddo
  enddo  
  END

  function fact(n)
  INTEGER n, p
  DOUBLE PRECISION fact
     p = 1
     do i = 1, n
        p = p * i
     end do
     fact = p
  end

  FUNCTION BICO(N,K)
  BICO=ANINT(EXP(FACTLN(N)-FACTLN(K)-FACTLN(N-K)))
  RETURN
  END

  FUNCTION FACTLN(N)
  DIMENSION A(100)
  DATA A/100*-1./
  IF (N.LT.0) PAUSE 'negative factorial'
  IF (N.LE.99) THEN
    IF (A(N+1).LT.0.)  A(N+1)=GAMMLN(N+1.)
    FACTLN=A(N+1)
  ELSE
    FACTLN=GAMMLN(N+1.)
  ENDIF
  RETURN
  END


  FUNCTION GAMMLN(XX)
  REAL*8 COF(6),STP,HALF,ONE,FPF,X,TMP,SER
  DATA COF,STP/76.18009173D0,-86.50532033D0,24.01409822D0,
 .     -1.231739516D0,.120858003D-2,-.536382D-5,2.50662827465D0/
  DATA HALF,ONE,FPF/0.5D0,1.0D0,5.5D0/
  X=XX-ONE
  TMP=X+FPF
  TMP=(X+HALF)*LOG(TMP)-TMP
  SER=ONE
  DO 11 J=1,6
      X=X+ONE
      SER=SER+COF(J)/X
  11    CONTINUE
  GAMMLN=TMP+LOG(STP*SER)
  RETURN
  END

EDIT : Here is the log file containing the errors.

Was it helpful?

Solution

Putting my comment that finally solved the problem into an answer :

Following some advice found on the net https://cd34.com/blog/programming/python/mysql-python-and-snow-leopard --> comment 37, I replaced the 10.4 folder by the 10.5 SDK one. And the stdarg.h error is no more. Not very clean and orthodox, but it seems to work. The .so file is created now! Thanks for everyone's help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top