!   C06LBF Example Program Text
!   Mark 23 Release. NAG Copyright 2011.

    MODULE c06lbfe_mod

!      C06LBF Example Program Module:
!             Parameters and User-defined Routines

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER                  :: nin = 5, nout = 6
    CONTAINS
!dec$ attributes offload : mic :: f
       FUNCTION f(s)

!         .. Implicit None Statement ..
          IMPLICIT NONE
!         .. Function Return Value ..
          COMPLEX (KIND=nag_wp)               :: f
!         .. Scalar Arguments ..
          COMPLEX (KIND=nag_wp), INTENT (IN)  :: s
!         .. Intrinsic Functions ..
          INTRINSIC                              cmplx
!         .. Executable Statements ..
          f = cmplx(3.0E0_nag_wp,kind=nag_wp)/(s**2-cmplx(9.0E0_nag_wp,kind= &
             nag_wp))
          RETURN
!dec$ attributes offload : mic :: f
       END FUNCTION f
    END MODULE c06lbfe_mod

    PROGRAM c06lbfe

!      C06LBF Example Main Program

!      .. Use Statements ..
       USE nag_library, ONLY : c06lbf, c06lcf, nag_wp
       USE c06lbfe_mod, ONLY : f, nin, nout
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Local Scalars ..
       REAL (KIND=nag_wp)                  :: b, epstol, exact, finv, pserr,   &
                                              sigma, sigma0, t
       INTEGER                             :: ifail, j, m, mmax
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE     :: acoef(:)
       REAL (KIND=nag_wp)                  :: errvec(8)
!      .. Intrinsic Functions ..
       INTRINSIC                              abs, exp, real, sinh
!      .. Executable Statements ..
       WRITE (nout,*) 'C06LBF Example Program Results'
!      Skip heading in data file
       READ (nin,*)
       READ (nin,*) mmax
       ALLOCATE (acoef(mmax))
       READ (nin,*) sigma0, epstol, sigma, b

!      ifail: behaviour on error exit   
!             =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
       ifail = 0
!      Compute inverse transform
       CALL c06lbf(f,sigma0,sigma,b,epstol,mmax,m,acoef,errvec,ifail)

       WRITE (nout,*)
       WRITE (nout,99999) 'No. of coefficients returned by C06LBF =', m
       WRITE (nout,*)
       WRITE (nout,99998) ' ', 'Computed', 'Exact', 'Pseudo'
       WRITE (nout,99998) 'T', '    f(T)', ' f(T)', ' error'
       WRITE (nout,*)

!      Evaluate inverse transform for different values of t
       DO j = 0, 5
          t = real(j,kind=nag_wp)

          CALL c06lcf(t,sigma,b,m,acoef,errvec,finv,ifail)

          exact = sinh(3.0E0_nag_wp*t)
          pserr = abs(finv-exact)/exp(sigma*t)
          WRITE (nout,99997) t, finv, exact, pserr
       END DO

99999  FORMAT (1X,A,I6)
99998  FORMAT (1X,A10,A15,A15,A12)
99997  FORMAT (1X,1P,E10.2,2E15.4,E12.1)
    END PROGRAM c06lbfe
