    PROGRAM e02rafe

!      E02RAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : c02agf, e02raf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: l = 4, m = 4, nout = 6
       INTEGER, PARAMETER              :: ia = l + 1
       INTEGER, PARAMETER              :: ib = m + 1
       INTEGER, PARAMETER              :: ic = ia + ib - 1
       INTEGER, PARAMETER              :: jw = ib*(2*ib+3)
       LOGICAL, PARAMETER              :: scale = .TRUE.
!      .. Local Scalars ..
       INTEGER                         :: i, ifail
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: a(ia), b(ib), c(ic), dd(ia+ib),      &
                                          w(jw), work(2*(l+m+1)), z(2,l+m)
!      .. Intrinsic Functions ..
       INTRINSIC                          real
!      .. Executable Statements ..
       WRITE (nout,*) 'E02RAF Example Program Results'

!      Power series coefficients in C

       c(1) = 1.0E0_nag_wp

       DO i = 1, ic - 1
          c(i+1) = c(i)/real(i,kind=nag_wp)
       END DO

       ifail = 0
       CALL e02raf(ia,ib,c,ic,a,b,w,jw,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'The given series coefficients are'
       WRITE (nout,99999) c(1:ic)
       WRITE (nout,*)
       WRITE (nout,*) 'Numerator coefficients'
       WRITE (nout,99999) a(1:ia)
       WRITE (nout,*)
       WRITE (nout,*) 'Denominator coefficients'
       WRITE (nout,99999) b(1:ib)

!      Calculate zeros of the approximant using C02AGF
!      First need to reverse order of coefficients

       dd(ia:1:-1) = a(1:ia)

       ifail = 0
       CALL c02agf(dd,l,scale,z,work,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Zeros of approximant are at'
       WRITE (nout,*)
       WRITE (nout,*) '    Real part    Imag part'
       WRITE (nout,99998) (z(1,i),z(2,i),i=1,l)

!      Calculate poles of the approximant using C02AGF
!      Reverse order of coefficients

       dd(ib:1:-1) = b(1:ib)

       ifail = 0
       CALL c02agf(dd,m,scale,z,work,ifail)

       WRITE (nout,*)
       WRITE (nout,*) 'Poles of approximant are at'
       WRITE (nout,*)
       WRITE (nout,*) '    Real part    Imag part'
       WRITE (nout,99998) (z(1,i),z(2,i),i=1,m)

99999  FORMAT (1X,5E13.4)
99998  FORMAT (1X,2E13.4)
    END PROGRAM e02rafe
