    PROGRAM nag_beta_dist_ex01

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_out, nag_std_in
      USE nag_beta_dist, ONLY : nag_beta_prob, nag_beta_deviate
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      REAL (wp) :: a, b, beta, beta_deviate, prob, probl
      CHARACTER (1) :: tail
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_beta_dist_ex01'

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

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) &
       ' tail    beta      a       b        prob    deviate'
      WRITE (nag_std_out,*)

      DO
        READ (nag_std_in,*,end=20) tail, beta, a, b

        prob = nag_beta_prob(tail,beta,a,b)

        probl = prob
        IF (tail=='u' .OR. tail=='U') probl = 1.0_wp - prob

        beta_deviate = nag_beta_deviate(probl,a,b)

        WRITE (nag_std_out,'(3X,A,4x,5(F7.4,2X))') tail, beta, a, b, prob, &
         beta_deviate
      END DO
20    CONTINUE

    END PROGRAM nag_beta_dist_ex01
