    PROGRAM nag_normal_dist_ex03

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

      ! .. Use Statements ..
      USE nag_normal_dist, ONLY : nag_mv_normal_prob
      USE nag_examples_io, ONLY : nag_std_out, nag_std_in
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC ALLOCATED, KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: n
      REAL (wp) :: prob
      CHARACTER (1) :: tail
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: a(:), b(:), correl(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_normal_dist_ex03'

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

      WRITE (nag_std_out,*)

      READ (nag_std_in,*) n, tail

      IF (tail=='C' .OR. tail=='c') THEN
        ALLOCATE (a(n),correl(n,n),b(n))
      ELSE
        ALLOCATE (a(n),correl(n,n))
      END IF

      READ (nag_std_in,*) correl
      READ (nag_std_in,*) a

      IF (tail=='C' .OR. tail=='c') THEN
        READ (nag_std_in,*) b
        prob = nag_mv_normal_prob(tail,a,correl,b=b)
      ELSE
        prob = nag_mv_normal_prob(tail,a,correl)
      END IF
      WRITE (nag_std_out,'(1X,A,F7.4)') 'multivariate probability = ', prob
      DEALLOCATE (a,correl)
      IF (ALLOCATED(b)) DEALLOCATE (b)

    END PROGRAM nag_normal_dist_ex03
