*     F04CFF Example Program Text
*     Mark 21 Release. NAG Copyright 2004.
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        (NIN=5,NOUT=6)
      INTEGER          KDMAX, NMAX, NRHSMX
      PARAMETER        (KDMAX=4,NMAX=8,NRHSMX=2)
      INTEGER          LDAB, LDB
      PARAMETER        (LDAB=KDMAX+1,LDB=NMAX)
      CHARACTER        UPLO
      PARAMETER        (UPLO='U')
*     .. Local Scalars ..
      DOUBLE PRECISION ERRBND, RCOND
      INTEGER          I, IERR, IFAIL, J, KD, N, NRHS
*     .. Local Arrays ..
      COMPLEX *16      AB(LDAB,NMAX), B(LDB,NRHSMX)
      CHARACTER        CLABS(1), RLABS(1)
*     .. External Subroutines ..
      EXTERNAL         F04CFF, X04DBF
*     .. Intrinsic Functions ..
      INTRINSIC        MAX, MIN
*     .. Executable Statements ..
      WRITE (NOUT,*) 'F04CFF 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
            DO 20 I = 1, N
               READ (NIN,*) (AB(KD+1+I-J,J),J=I,MIN(N,I+KD))
   20       CONTINUE
         ELSE IF (UPLO.EQ.'L') THEN
            DO 40 I = 1, N
               READ (NIN,*) (AB(1+I-J,J),J=MAX(1,I-KD),I)
   40       CONTINUE
         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
*
         IFAIL = 1
         CALL F04CFF(UPLO,N,KD,NRHS,AB,LDAB,B,LDB,RCOND,ERRBND,IFAIL)
*
         IF (IFAIL.EQ.0) THEN
*
*           Print solution, estimate of condition number and approximate
*           error bound
*
            IERR = 0
            CALL X04DBF('General',' ',N,NRHS,B,LDB,'Bracketed','F7.4',
     +                  'Solution','Integer',RLABS,'Integer',CLABS,80,0,
     +                  IERR)
*
            WRITE (NOUT,*)
            WRITE (NOUT,*) 'Estimate of condition number'
            WRITE (NOUT,99999) 1.0D0/RCOND
            WRITE (NOUT,*)
            WRITE (NOUT,*)
     +        'Estimate of error bound for computed solutions'
            WRITE (NOUT,99999) ERRBND
         ELSE IF (IFAIL.EQ.N+1) THEN
*
*           Matrix A is numerically singular.  Print estimate of
*           reciprocal of condition number and solution
*
            WRITE (NOUT,*)
            WRITE (NOUT,*) 'Estimate of reciprocal of condition number'
            WRITE (NOUT,99999) RCOND
*
            WRITE (NOUT,*)
            IERR = 0
            CALL X04DBF('General',' ',N,NRHS,B,LDB,'Bracketed','F7.4',
     +                  'Solution','Integer',RLABS,'Integer',CLABS,80,0,
     +                  IERR)
*
         ELSE IF (IFAIL.GT.0 .AND. IFAIL.LE.N) THEN
*
*           The matrix A is not positive definite to working precision
*
            WRITE (NOUT,99998) 'The leading minor of order ', IFAIL,
     +        ' is not positive definite'
         ELSE
            WRITE (NOUT,99997) IFAIL
         END IF
      ELSE
         WRITE (NOUT,*)
     +     'One or more of NMAX, KDMAX and NRHSMX is too small'
      END IF
*
99999 FORMAT (4X,1P,E9.1)
99998 FORMAT (1X,A,I3,A)
99997 FORMAT (1X,' ** F04CFF returned with IFAIL = ',I5)
      END
