      SUBROUTINE BSPP(T,BCOEF,N,K,BREAK,COEF,L,WK)
C     ******************************************************************
C     CONVERSION FROM B-SPLINE REPRESENTATION TO PP REPRESENTATION
C     ******************************************************************
C     INPUT
C       T     KNOT SEQUENCE OF LENGTH N+K
C       BCOEF B-SPLINE COEFFICIENT SEQUENCE OF LENGTH N
C       N     LENGTH OF BCOEF
C       K     ORDER OF THE B-SPLINES
C
C     OUTPUT
C       BREAK BREAKPOINT SEQUENCE, OF LENGTH L+1, CONTAINING
C             (IN INCREASING ORDER) THE DISTINCT POINTS OF THE
C             SEQUENCE T(K),...,T(N+1).
C       COEF  KXL MATRIX WHERE COEF(I,J) = (I-1)ST RIGHT DERIVATIVE
C             OF THE PP AT BREAK(J) DIVIDED BY FACTORIAL(I-1).
C       L     NUMBER OF POLYNOMIALS WHICH FORM THE PP
C
C     WORK AREA
C       WK    2-DIMENSIONAL ARRAY OF DIMENSION (K,K+1)
C     ------------------
      REAL T(1),BCOEF(N),BREAK(1),COEF(K,1),WK(K,1)
C     ------------------
      L = 0
      BREAK(1) = T(K)
      IF (K .EQ. 1) GO TO 100
      KM1 = K - 1
      KP1 = K + 1
C
C          GENERAL K-TH ORDER CASE
C
      DO 40 LEFT = K,N
      IF (T(LEFT) .EQ. T(LEFT+1)) GO TO 40
      L = L + 1
      BREAK(L+1) = T(LEFT+1)
      DO 10 J = 1,K
         JJ = LEFT - K + J
   10 WK(J,1) = BCOEF(JJ)
C
      DO 21 J = 1,KM1
      JP1 = J + 1
      KMJ = K - J
      DO 20 I = 1,KMJ
         IL = I + LEFT
         ILKJ = IL - KMJ
         DIFF = T(IL) - T(ILKJ)
   20 WK(I,JP1) = (WK(I+1,J) - WK(I,J))/DIFF
   21 CONTINUE
C
      WK(1,KP1) = 1.0
      X = T(LEFT)
      COEF(K,L) = WK(1,K)
      A = 1.0
      DO 32 J = 1,KM1
      JP1 = J + 1
      S = 0.0
      DO 30 I = 1,J
         IL = I + LEFT
         ILJ = IL - J
         TERM = WK(I,KP1)/(T(IL)-T(ILJ))
         WK(I,KP1) = S + (T(IL)-X)*TERM
   30 S = (X-T(ILJ))*TERM
      WK(JP1,KP1) = S
      S = 0.0
      KMJ = K - J
      DO 31 I = 1,JP1
   31 S = S + WK(I,KMJ)*WK(I,KP1)
      A = (A*FLOAT(KMJ))/FLOAT(J)
   32 COEF(KMJ,L) = A*S
C
   40 CONTINUE
      RETURN
C
C          PIECEWISE CONSTANT CASE
C
  100 DO 110 LEFT = K,N
      IF (T(LEFT) .EQ. T(LEFT+1)) GO TO 110
      L = L + 1
      BREAK(L+1) = T(LEFT+1)
      COEF(1,L) = BCOEF(LEFT)
  110 CONTINUE
      RETURN
      END
