    PROGRAM e02gcfe

!      E02GCF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e02gcf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: n = 3, nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: relerr, resmax, t, tol
       INTEGER                         :: i, ifail, irank, iter, lda, m, sda
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), b(:), x(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          exp
!      .. Executable Statements ..
       WRITE (nout,*) 'E02GCF Example Program Results'

!      Skip heading in data file
       READ (nin,*)

       READ (nin,*) m
       lda = n + 3
       sda = m + 1
       ALLOCATE (a(lda,sda),b(m),x(n))

       DO i = 1, m
          READ (nin,*) t, b(i)
          a(1,i) = exp(t)
          a(2,i) = exp(-t)
          a(3,i) = 1.0E0_nag_wp
       END DO

       tol = 0.0E0_nag_wp
       relerr = 0.0E0_nag_wp

       ifail = -1
       CALL e02gcf(m,n,sda,lda,a,b,tol,relerr,x,resmax,irank,iter,ifail)

       SELECT CASE (ifail)
       CASE (0,1)
          WRITE (nout,*)
          WRITE (nout,99999) 'RESMAX = ', resmax, '  Rank = ', irank, &
             '  Iterations = ', iter, '  IFAIL =', ifail
          WRITE (nout,*)
          WRITE (nout,*) 'Solution'
          WRITE (nout,99998) x(1:n)
       END SELECT

99999  FORMAT (1X,A,E10.2,3(A,I5))
99998  FORMAT (1X,6F10.4)
    END PROGRAM e02gcfe
