*     F07HBF Example Program Text
*     Mark 21 Release. NAG Copyright 2004.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          KDMAX, NMAX
      PARAMETER        (KDMAX=4,NMAX=8)
      INTEGER          LDAB, LDAFB, LDB, LDX, NRHSMX
      PARAMETER        (LDAB=KDMAX+1,LDAFB=KDMAX+1,LDB=NMAX,LDX=NMAX,
     +                 NRHSMX=NMAX)
      CHARACTER        UPLO
      PARAMETER        (UPLO='U')
*     .. Local Scalars ..
      DOUBLE PRECISION RCOND
      INTEGER          I, IFAIL, INFO, J, KD, N, NRHS
      CHARACTER        EQUED
*     .. Local Arrays ..
      DOUBLE PRECISION AB(LDAB,NMAX), AFB(LDAFB,NMAX), B(LDB,NRHSMX),
     +                 BERR(NRHSMX), FERR(NRHSMX), S(NMAX),
     +                 WORK(3*NMAX), X(LDX,NRHSMX)
      INTEGER          IWORK(NMAX)
*     .. External Subroutines ..
      EXTERNAL         DPBSVX, X04CAF
*     .. Intrinsic Functions ..
      INTRINSIC        MAX, MIN
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F07HBF Example Program Results'
      WRITE (NOUT,*)
*     Skip heading in data file
      READ (NIN,*)
      READ (NIN,*) N, KD, NRHS
      IF (N.LE.NMAX .AND. KD.LE.KDMAX .AND. NRHS.LE.NRHSMX) THEN
*
*        Read the upper or lower triangular part of the band matrix A
*        from data file
*
         IF (UPLO.EQ.'U') THEN
            READ (NIN,*) ((AB(KD+1+I-J,J),J=I,MIN(N,I+KD)),I=1,N)
         ELSE IF (UPLO.EQ.'L') THEN
            READ (NIN,*) ((AB(1+I-J,J),J=MAX(1,I-KD),I),I=1,N)
         END IF
*
*        Read B from data file
*
         READ (NIN,*) ((B(I,J),J=1,NRHS),I=1,N)
*
*        Solve the equations AX = B for X
*
         CALL DPBSVX('Equilibration',UPLO,N,KD,NRHS,AB,LDAB,AFB,LDAFB,
     +               EQUED,S,B,LDB,X,LDX,RCOND,FERR,BERR,WORK,IWORK,
     +               INFO)
*
         IF ((INFO.EQ.0) .OR. (INFO.EQ.N+1)) THEN
*
*           Print solution, error bounds, condition number and the form
*           of equilibration
*
            IFAIL = 0
            CALL X04CAF('General',' ',N,NRHS,X,LDX,'Solution(s)',IFAIL)
*
            WRITE (NOUT,*)
            WRITE (NOUT,*) 'Backward errors (machine-dependent)'
            WRITE (NOUT,99999) (BERR(J),J=1,NRHS)
            WRITE (NOUT,*)
            WRITE (NOUT,*)
     +        'Estimated forward error bounds (machine-dependent)'
            WRITE (NOUT,99999) (FERR(J),J=1,NRHS)
            WRITE (NOUT,*)
            WRITE (NOUT,*) 'Estimate of reciprocal condition number'
            WRITE (NOUT,99999) RCOND
            WRITE (NOUT,*)
            IF (EQUED.EQ.'N') THEN
               WRITE (NOUT,*) 'A has not been equilibrated'
            ELSE IF (EQUED.EQ.'S') THEN
               WRITE (NOUT,*)
     +           'A has been row and column scaled as diag(S)*A*diag(S)'
            END IF
*
            IF (INFO.EQ.N+1) THEN
               WRITE (NOUT,*)
               WRITE (NOUT,*)
     +           'The matrix A is singular to working precision'
            END IF
         ELSE
            WRITE (NOUT,99998) 'The leading minor of order ', INFO,
     +        ' is not positive definite'
         END IF
      ELSE
         WRITE (NOUT,*)
     +     'One or more of NMAX, KDMAX and NRHSMX is too small'
      END IF
      STOP
*
99999 FORMAT ((3X,1P,7E11.1))
99998 FORMAT (1X,A,I3,A)
      END
