0

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.

Nigu
  • 2,025
  • 2
  • 22
  • 31
  • Not on the right computer right now... I'll try to update the question tomorrow. But I did not include the error messages at first because there were hundreds of them, and it may be easier for the f2py users here to copy paste my code and see for themselves what the error is. – Nigu Aug 28 '10 at 21:35
  • What OS version are you using and compiling to? – kennytm Aug 29 '10 at 09:11
  • First error is `/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:19:20: error: limits.h: No such file or directory` @Kenny i386-apple-darwin8.10.1 –  Aug 29 '10 at 09:43
  • Make sure you have all the xcode stuff installed, including 10.4 SDK - limits.h should come from there. – robince Aug 29 '10 at 15:41
  • Thanks thrope for the suggestion. I reinstalled the whole xcode stuff, and it actually solves some of the problems. However, some still persist. It does not seem to find stdarg.h in the path mentioned in the newly attached log file... however, I checked manually, and the file exists there! Sorry for the inconvenience... please tell me if I should ask this question somewhere else. – Nigu Aug 30 '10 at 09:57
  • Ok... following some advice found on the net (http://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. – Nigu Aug 30 '10 at 11:01
  • Should I put this solution in an answer and accept it? Or wait for someone else's advice? – Nigu Aug 30 '10 at 12:59

1 Answers1

0

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.

SamAct
  • 529
  • 4
  • 23
Nigu
  • 2,025
  • 2
  • 22
  • 31