    PROGRAM e02aefe

!      E02AEF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e02aef, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: p, xcap
       INTEGER                         :: i, ifail, m, n, nplus1, r
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'E02AEF Example Program Results'

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

       READ (nin,*) m
       READ (nin,*) n
       nplus1 = n + 1
       ALLOCATE (a(nplus1))

       READ (nin,*) (a(i),i=1,nplus1)

       DO r = 1, m
          xcap = real(2*r-m-1,kind=nag_wp)/real(m-1,kind=nag_wp)

          ifail = 0
          CALL e02aef(nplus1,a,xcap,p,ifail)

          IF (r==1) THEN
             WRITE (nout,*)
             WRITE (nout,*) '  R       Argument       Value of polynomial'
          END IF

          WRITE (nout,99999) r, xcap, p
       END DO

99999  FORMAT (1X,I3,F14.4,4X,F14.4)
    END PROGRAM e02aefe
