[Numpy-discussion] Enabling NaN-usage in F77 code on Windows

Wes McKinney wesmckinn at gmail.com
Wed Oct 29 18:23:29 EDT 2008


I'm having some trouble getting NaN's to return from f77 code running under
latest f2py in both g77 and gfortran. I would prefer to use gfortran but
whenever I set a result value = NAN, it comes back to Python as 0. Has
anyone tackled this issue? I am new to using f2py, have been moving along
fine with everything else but ran into this.

Here is a sample function for the rolling mean of a series having this
behavior:

      SUBROUTINE ROLLMEAN(DATA,WINDOW,N,AVE,T)
      INTEGER*8 N, WINDOW
      REAL*8 AVE,DATA(N),T(N)
      INTEGER*8 J
      REAL*8 P,S,S1
C
CF2PY REAL*8 INTENT(IN, COPY) DATA
CF2PY INTEGER*8 INTENT(IN) WINDOW
CF2PY INTEGER*8 INTENT(HIDE), DEPEND(DATA), CHECK(N>=2) :: N = SHAPE(DATA,
0)
CF2PY REAL*8 INTENT(OUT, COPY), DEPEND(N), DIMENSION(N) :: T
CF2PY REAL*8 INTENT(HIDE) :: AVE
C
      S=0.
      S1=0.
      DO J=1,WINDOW
          P=DATA(J)
          S1=S1+P
          T(J)=NAN
      ENDDO
      AVE=S1/WINDOW
      T(WINDOW)=AVE
      DO J=WINDOW+1,N
          P=DATA(J)
          S=DATA(J-WINDOW)
          S1=S1+P-S
          AVE=S1/WINDOW
          T(J)=AVE
      ENDDO
      RETURN
      END


Thanks,
Wes
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20081029/2b46d462/attachment.html>


More information about the NumPy-Discussion mailing list