    PROGRAM g05qbfe

!      G05QBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g05kbf, g05qbf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nmax = 10, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: eps
       INTEGER                         :: i, ifail, igen, j, ldc, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: c(nmax,nmax), d(nmax), wk(2*nmax)
       INTEGER                         :: iseed(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'G05QBF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       IF (n<=nmax) THEN
          READ (nin,*) (d(i),i=1,n)

          WRITE (nout,*)

          ldc = nmax
          eps = 0.0001E0_nag_wp

!         IGEN identifies the stream.
          igen = 1
!         Initialize the seed to a repeatable sequence
          iseed(1) = 1762543
          iseed(2) = 9324783
          iseed(3) = 423446
          iseed(4) = 742355
          CALL g05kbf(igen,iseed)

          ifail = 1

          CALL g05qbf(n,d,c,ldc,eps,igen,iseed,wk,ifail)

          IF (ifail==0) THEN
             DO i = 1, n
                WRITE (nout,99999) (c(i,j),j=1,n)
             END DO
          ELSE
             WRITE (nout,99998) ifail
          END IF
       END IF

99999  FORMAT (1X,3F9.3)
99998  FORMAT (1X,' ** G05QBF returned with IFAIL = ',I5)
    END PROGRAM g05qbfe
