    PROGRAM e02rbfe

!      E02RBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e02raf, e02rbf, 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              :: iw = ib*(2*ib+3)
       LOGICAL, PARAMETER              :: plot = .FALSE.
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: ans, tval, x
       INTEGER                         :: i, ifail, nx
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: a(ia), b(ib), cc(ic), w(iw)
!      .. Intrinsic Functions ..
       INTRINSIC                          abs, exp, real
!      .. Executable Statements ..
       IF ( .NOT. plot) THEN
          WRITE (nout,*) 'E02RBF Example Program Results'
          nx = 10
       ELSE
          nx = 30
       END IF

       cc(1) = 1.0E0_nag_wp

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

       ifail = 0
       CALL e02raf(ia,ib,cc,ic,a,b,w,iw,ifail)

       IF ( .NOT. plot) THEN
          WRITE (nout,*)
          WRITE (nout,*) '    X         Pade          True'
       END IF

       DO i = 1, nx
          x = real(i,kind=nag_wp)/10.0_nag_wp

          ifail = 0
          CALL e02rbf(a,ia,b,ib,x,ans,ifail)

          tval = exp(x)

          IF (plot) THEN
             WRITE (nout,99999) x, ans, tval, abs(tval-ans)/tval
          ELSE
             WRITE (nout,99998) x, ans, tval
          END IF
       END DO

99999  FORMAT (1X,F6.1,4E19.9)
99998  FORMAT (1X,F6.1,3E15.5)
    END PROGRAM e02rbfe
