      SUBROUTINE BSPEV(T,K,X,I,M,N,B,IERR)
C     ******************************************************************
C     EVALUATION OF B-SPLINES
C     ******************************************************************
      REAL T(K),B(N)
      IF (M.LT.0 .OR. M.GE.N) GO TO 20
      IF (T(I) .GE. T(I+1)) GO TO 21
      NM1 = N - 1
      IF (I .LT. NM1) GO TO 22
      IF (K .LT. I + NM1) GO TO 23
C
      IERR = 0
      J = M
      IF (M .GE. 1) GO TO 10
      B(1) = 1.0
      IF (N .EQ. 1) RETURN
      J = 1
C
   10 S = 0.0
      DO 11 L = 1,J
      IL = I + L
      ILJ = IL - J
      TERM = B(L)/(T(IL)-T(ILJ))
      B(L) = S + (T(IL)-X)*TERM
   11 S = (X-T(ILJ))*TERM
      B(J+1) = S
      J = J + 1
      IF (J .LT. N) GO TO 10
      RETURN
C
C          ERROR RETURN
C
   20 IERR = 1
      RETURN
   21 IERR = 2
      RETURN
   22 IERR = 3
      RETURN
   23 IERR = 4
      RETURN
      END
