    PROGRAM nag_correl_ex02

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

      ! .. Use Statements ..
      USE nag_examples_io, ONLY : nag_std_out, nag_std_in
      USE nag_correl, ONLY : nag_prod_mom_correl
      USE nag_write_mat, ONLY : nag_write_tri_mat
      ! .. Implicit None Statement ..
      IMPLICIT NONE
      ! .. Intrinsic Functions ..
      INTRINSIC KIND
      ! .. Parameters ..
      INTEGER, PARAMETER :: wp = KIND(1.0D0)
      ! .. Local Scalars ..
      INTEGER :: i, m, n
      ! .. Local Arrays ..
      REAL (wp), ALLOCATABLE :: correl(:,:), cov(:,:), data(:,:), mean(:), &
       std(:)
      LOGICAL, ALLOCATABLE :: var_in_correl(:)
      ! .. Executable Statements ..
      WRITE (nag_std_out,*) 'Example Program Results for nag_correl_ex02'

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

      ALLOCATE (data(n,m),var_in_correl(m),mean(m),std(m),cov(m,m), &
       correl(m,m))                ! Allocate storage

      READ (nag_std_in,*) (data(i,:),i=1,n)

      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Calculations on all the variables'
      WRITE (nag_std_out,*)

      CALL nag_prod_mom_correl(data,mean=mean,cov=cov,correl=correl,std=std)

      WRITE (nag_std_out,*) 'Means'
      WRITE (nag_std_out,'(3x,5f10.4)') mean
      WRITE (nag_std_out,*)
      WRITE (nag_std_out,*) 'Standard deviations'
      WRITE (nag_std_out,'(3x,5f10.4)') std
      WRITE (nag_std_out,*)

      CALL nag_write_tri_mat('u',cov,format='f10.4',int_row_labels=.TRUE., &
       int_col_labels=.TRUE.,title='The covariance matrix')

      WRITE (nag_std_out,*)

      CALL nag_write_tri_mat('u',correl,format='f10.4',int_row_labels=.TRUE., &
       int_col_labels=.TRUE.,title='The correlation matrix')

      DEALLOCATE (data,var_in_correl,mean,std,cov,correl) ! Deallocate storage

    END PROGRAM nag_correl_ex02
