      SUBROUTINE PPVAL (X, A, L, N, XI, YI, NI)
C
C     ABSTRACT
C
C         THIS ROUTINE EVALUATES A PIECEWISE POLYNOMIAL AT THE
C         ABSCISSAS IN XI. IT IS ASSUMED THAT THE COEFFICIENTS
C         OF THE POLYNOMIALS WHICH FORM THE PP ARE GIVEN.
C
C       --INPUT--
C
C         X   - ARRAY OF THE FIRST N ABSCISSAS (IN INCREASING ORDER)
C               THAT DEFINE THE PP.
C         A   - MATRIX THAT CONTAINS THE COEFFICIENTS OF THE POLY-
C               NOMIALS  WHICH FORM THE PP. IF I = 1,...,N THEN THE
C               PP HAS THE VALUE
C                    A(1,I) + A(2,I)*DX + ... + A(L,I)*DX**(L-1)
C               FOR X(I) .LE. XX .LT. X(I+1).  HERE DX = XX-X(I).
C         L   - ORDER OF THE PIECEWISE POLYNOMIAL.
C         N   - THE NUMBER OF POLYNOMIALS THAT DEFINE THE PP.
C               N MUST BE GREATER THAN OR EQUAL TO 1.
C         XI  - THE ABSCISSA OR ARRAY OF ABSCISSAS (IN ARBITRARY ORDER)
C               AT WHICH THE PP IS TO BE EVALUATED.
C         NI  - THE NUMBER OF ABSCISSAS AT WHICH THE PP IS TO BE
C               EVALUATED.  IF NI IS GREATER THAN 1 THEN XI AND YI
C               MUST BE ARRAYS OF DIMENSION NI OR LARGER.
C               IT IS ASSUMED THAT NI IS GREATER THAN OR EQUAL TO 1.
C
C       --OUTPUT--
C
C         YI  - ARRAY OF VALUES OF THE PP AT XI
C
C
      DIMENSION X(N), A(L,N), XI(NI), YI(NI)
C
C     K IS INDEX ON VALUE OF XI BEING WORKED ON.  XX IS THAT VALUE.
C     I IS CURRENT INDEX INTO X ARRAY.
C
      K  = 1
      XX = XI(1)
      LM1 = L - 1
      IF (XX .LT. X(1)) GO TO 90
      IF (XX .GE. X(N)) GO TO 80
      IL = 1
      IR = N
C
C     BISECTION SEARCH
C
   10 I = (IL + IR)/2
      IF (I .EQ. IL) GO TO 100
      IF (XX-X(I)) 20,100,30
   20 IR = I
      GO TO 10
   30 IL = I
      GO TO 10
C
C     LINEAR FORWARD SEARCH
C
   40 IF (XX .LT. X(I+1)) GO TO 100
      I = I + 1
      GO TO 40
C
C     XX IS GREATER THAN X(N) OR LESS THAN X(1)
C
   80 I = N
      GO TO 100
   90 I = 1
C
C     EVALUATION
C
  100 DX = XX - X(I)
      S = A(L,I)
      IF (L .EQ. 1) GO TO 120
      DO 110 J = 1,LM1
      LMJ = L - J
  110 S = A(LMJ,I) + DX*S
  120 YI(K) = S
C
C     NEXT POINT
C
      IF (K .GE. NI) RETURN
      K = K + 1
      XX = XI(K)
      IF (XX .LT. X(1)) GO TO 90
      IF (XX .GE. X(N)) GO TO 80
      IF (XX-XI(K-1)) 130,120,40
  130 IL = 1
      IR = MIN0(I+1,N)
      GO TO 10
      END
