    PROGRAM nag_rand_contin_ex02

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_in, nag_std_out
      USE nag_write_mat, ONLY : nag_write_tri_mat
      USE nag_rand_contin, ONLY : nag_rand_mv_normal, nag_rand_seed_set, &
       nag_seed_wp => nag_seed_dp
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      CHARACTER (*), PARAMETER :: fmt = '(/1x,a/(1X, 2F5.1))'
      ! .. Local Scalars ..
      INTEGER :: i, k, n, nw, r
      TYPE (nag_seed_wp) :: seed
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: a(:), c(:,:), chol(:), x(:,:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_rand_contin_ex02'

      READ (nag_std_in,*)          ! skip heading in data file
      READ (nag_std_in,*) n        ! number of variables
      READ (nag_std_in,*) r        ! number of random number sequences

      nw = (n*(n+1))/2

      ALLOCATE (a(n),c(n,n),chol(nw),x(r,n)) ! Allocate storage

      READ (nag_std_in,*) a        ! mean vector
      READ (nag_std_in,*) (c(i,i:),i=1,n) ! covariance matrix

      k = 0

      CALL nag_rand_seed_set(seed,k)

      x(1,:) = nag_rand_mv_normal(seed,a,c=c,rel_tol=0.01_wp,chol=chol)

      DO i = 2, r
        x(i,:) = nag_rand_mv_normal(seed,a,chol=chol)
      END DO

      WRITE (nag_std_out,fmt) 'Mean Vector', a

      CALL nag_write_tri_mat('u',c,title='Covariance Matrix')

      WRITE (nag_std_out,'(/1x,a/(1X, 2F8.4))') 'Random Number Sequence', &
       (x(i,:),i=1,r)

      DEALLOCATE (a,c,chol,x)      ! Deallocate storage

    END PROGRAM nag_rand_contin_ex02
