*     F07BPF Example Program Text
*     Mark 21 Release. NAG Copyright 2004.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          NMAX, KLMAX, KUMAX, NRHSMX
      PARAMETER        (NMAX=8,KLMAX=4,KUMAX=4,NRHSMX=2)
      INTEGER          LDAB, LDAFB, LDB, LDX
      PARAMETER        (LDAB=KLMAX+KUMAX+1,LDAFB=LDAB+KLMAX,LDB=NMAX,
     +                 LDX=NMAX)
*     .. Local Scalars ..
      DOUBLE PRECISION RCOND
      INTEGER          I, IFAIL, INFO, J, K, KL, KU, N, NRHS
      CHARACTER        EQUED
*     .. Local Arrays ..
      COMPLEX *16      AB(LDAB,NMAX), AFB(LDAFB,NMAX), B(LDB,NRHSMX),
     +                 WORK(2*NMAX), X(LDX,NRHSMX)
      DOUBLE PRECISION BERR(NRHSMX), C(NMAX), FERR(NRHSMX), R(NMAX),
     +                 RWORK(NMAX)
      INTEGER          IPIV(NMAX)
      CHARACTER        CLABS(1), RLABS(1)
*     .. External Subroutines ..
      EXTERNAL         X04DBF, ZGBSVX
*     .. Intrinsic Functions ..
      INTRINSIC        MAX, MIN
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F07BPF Example Program Results'
      WRITE (NOUT,*)
*     Skip heading in data file
      READ (NIN,*)
      READ (NIN,*) N, NRHS, KL, KU
      IF (N.LE.NMAX .AND. KL.LE.KLMAX .AND. KU.LE.KUMAX .AND. NRHS.LE.
     +    NRHSMX) THEN
*
*        Read the band matrix A and B from data file
*
         K = KU + 1
         READ (NIN,*) ((AB(K+I-J,J),J=MAX(I-KL,1),MIN(I+KU,N)),I=1,N)
         READ (NIN,*) ((B(I,J),J=1,NRHS),I=1,N)
*
*        Solve the equations AX = B for X
*
         CALL ZGBSVX('Equilibration','No transpose',N,KL,KU,NRHS,AB,
     +               LDAB,AFB,LDAFB,IPIV,EQUED,R,C,B,LDB,X,LDX,RCOND,
     +               FERR,BERR,WORK,RWORK,INFO)
*
         IF ((INFO.EQ.0) .OR. (INFO.EQ.N+1)) THEN
*
*           Print solution, error bounds, condition number, the form
*           of equilibration and the pivot growth factor
*
            IFAIL = 0
            CALL X04DBF('General',' ',N,NRHS,X,LDX,'Bracketed','F7.4',
     +                  'Solution(s)','Integer',RLABS,'Integer',CLABS,
     +                  80,0,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.'R') THEN
               WRITE (NOUT,*) 'A has been row scaled as diag(R)*A'
            ELSE IF (EQUED.EQ.'C') THEN
               WRITE (NOUT,*) 'A has been column scaled as A*diag(C)'
            ELSE IF (EQUED.EQ.'B') THEN
               WRITE (NOUT,*)
     +           'A has been row and column scaled as diag(R)*A*diag(C)'
            END IF
            WRITE (NOUT,*)
            WRITE (NOUT,*) 'Estimate of reciprocal pivot growth factor'
            WRITE (NOUT,99999) RWORK(1)
*
            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 (', INFO, ',', INFO, ')',
     +        ' element of the factor U is zero'
         END IF
      ELSE
         WRITE (NOUT,*)
     +     'One or more of NMAX, KLMAX, KUMAX or NRHSMX is too small'
      END IF
      STOP
*
99999 FORMAT ((3X,1P,7E11.1))
99998 FORMAT (1X,A,I3,A,I3,A,A)
      END
