    PROGRAM f04fffe

!      F04FFF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : f04fff, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: ifail, n
       LOGICAL                         :: wantp
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: b(:), p(:), t(:), work(:), x(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'F04FFF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) n
       WRITE (nout,*)
       ALLOCATE (b(n),p(n-1),t(0:n-1),work(2*(n-1)),x(n))
       READ (nin,*) t(0:n-1)
       READ (nin,*) b(1:n)
       wantp = .TRUE.

!      ifail: behaviour on error exit
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 1
       CALL f04fff(n,t,b,x,wantp,p,work,ifail)

       IF (ifail==0) THEN
          WRITE (nout,*)
          WRITE (nout,*) 'Solution vector'
          WRITE (nout,99998) x(1:n)
          IF (wantp) THEN
             WRITE (nout,*)
             WRITE (nout,*) 'Reflection coefficients'
             WRITE (nout,99998) p(1:n-1)
          END IF
       ELSE IF (ifail>0) THEN
          WRITE (nout,*)
          WRITE (nout,99999) 'Solution for system of order', ifail - 1
          WRITE (nout,99998) x(1:ifail-1)
          IF (wantp) THEN
             WRITE (nout,*)
             WRITE (nout,*) 'Reflection coefficients'
             WRITE (nout,99998) p(1:ifail-1)
          END IF
       ELSE
          WRITE (nout,99997) ifail
       END IF

99999  FORMAT (1X,A,I5)
99998  FORMAT (1X,5F9.4)
99997  FORMAT (1X,' ** F04FFF returned with IFAIL = ',I5)
    END PROGRAM f04fffe
