      FUNCTION CSPF(X,C,N)
*     Calculate function value for given argument X, for spline
*     function in array C, dimensioned C(5,N), obtained by previous
*     call of CSPLN.
      REAL C(5,N)
      DATA  I/1/
      IF(I.GE.N) I=(N+1)/2
      IF(X.GE.C(5,I)) THEN   ! make use of previous index 
         IH=MIN(I+2,N-1)
         IF(X.GE.C(5,IH)) IH=N-1         
         IL=I
      ELSE 
         IL=MAX(I-2,1)
         IF(X.LT.C(5,IL)) IL=1
         IH=I
      END IF 
   10 I=(IL+IH)/2     ! binary search 
      IF(I.NE.IL) THEN
         IF(X.GE.C(5,I)) THEN
            IL=I
         ELSE
            IH=I
         END IF
         GOTO 10
      END IF
      H=X-C(5,I)
      CSPF=C(1,I)+H*(C(2,I)+H*(C(3,I)+H*C(4,I)))
      END
