    PROGRAM s17alfe

!      S17ALF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : nag_wp, s17alf, x02ajf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: a, rel
       INTEGER                         :: i, ifail, mode, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: x(:)
!      .. Intrinsic Functions ..
       INTRINSIC                          sqrt
!      .. Executable Statements ..
       WRITE (nout,*) 'S17ALF Example Program Results'

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

       rel = sqrt(x02ajf())
       READ (nin,*) a, n, mode
       ALLOCATE (x(n))

       ifail = 0
       CALL s17alf(a,n,mode,rel,x,ifail)

       WRITE (nout,*)
       WRITE (nout,*) '   A   N   MODE        REL'
       WRITE (nout,*) '                 (machine-dependent)'
       WRITE (nout,*)
       WRITE (nout,99999) a, n, mode, rel
       WRITE (nout,*)

       SELECT CASE (mode)
       CASE (1)
          WRITE (nout,*) 'Leading N positive zeros of J'
       CASE (2)
          WRITE (nout,*) 'Leading N positive zeros of Y'
       CASE (3)

          IF (a==0.0E0_nag_wp) THEN
             WRITE (nout,*) 'Leading N non-negative zeros of J'''
          ELSE
             WRITE (nout,*) 'Leading N positive zeros of J'''
          END IF

       CASE (4)
          WRITE (nout,*) 'Leading N positive zeros of Y'''
       END SELECT

       WRITE (nout,*)
       WRITE (nout,*) 'X ='
       WRITE (nout,99998) (x(i),i=1,n)
       WRITE (nout,*)

99999  FORMAT (1X,F4.1,I4,I7,4X,1P,E9.1)
99998  FORMAT (1P,(E12.4))
    END PROGRAM s17alfe
