    PROGRAM nag_gamma_fun_ex04

      ! Example Program Text for nag_gamma_fun
      ! NAG fl90, Release 4. NAG Copyright 2000.

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_out
      USE nag_gamma_fun, ONLY : nag_incompl_gamma
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: n = 5
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i
      REAL (wp) :: p, q
      ! .. Local Arrays ..
      REAL (wp) :: a(n), x(n)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_gamma_fun_ex04'

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) '         a           x           p           q'
      a = (/ 2.0_wp, 7.0_wp, 0.5_wp, 20.0_wp, 21.0_wp/)
      x = (/ 3.0_wp, 1.0_wp, 99.0_wp, 21.0_wp, 20.0_wp/)

      DO i = 1, n

        p = nag_incompl_gamma(a(i),x(i))
        q = 1.0_wp - p

        WRITE (nag_std_out,fmt='(1X,4F12.4)') a(i), x(i), p, q
      END DO

    END PROGRAM nag_gamma_fun_ex04
