    PROGRAM g02bdfe

!      G02BDF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g02bdf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       INTEGER                         :: i, ifail, ldrz, ldsspz, ldx, m, n
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: rz(:,:), sspz(:,:), std(:), x(:,:),  &
                                          xbar(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G02BDF Example Program Results'
       WRITE (nout,*)

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

!      Read in the problem size
       READ (nin,*) n, m

       ldrz = m
       ldsspz = m
       ldx = n
       ALLOCATE (rz(ldrz,m),sspz(ldsspz,m),std(m),x(ldx,m),xbar(m))

!      Read in data
       READ (nin,*) (x(i,1:m),i=1,n)

!      Display data
       WRITE (nout,99999) 'Number of variables (columns) =', m
       WRITE (nout,99999) 'Number of cases     (rows)    =', n
       WRITE (nout,*)
       WRITE (nout,*) 'Data matrix is:-'
       WRITE (nout,*)
       WRITE (nout,99998) (i,i=1,m)
       WRITE (nout,99997) (i,x(i,1:m),i=1,n)
       WRITE (nout,*)

!      Compute summary statistics
       ifail = 0
       CALL g02bdf(n,m,x,ldx,xbar,std,sspz,ldsspz,rz,ldrz,ifail)

!      Display results
       WRITE (nout,*) 'Variable   Mean    St. dev.'
       WRITE (nout,99996) (i,xbar(i),std(i),i=1,m)
       WRITE (nout,*)
       WRITE (nout,*) 'Sums of squares and cross-products about' // ' zero'
       WRITE (nout,99998) (i,i=1,m)
       WRITE (nout,99997) (i,sspz(i,1:m),i=1,m)
       WRITE (nout,*)
       WRITE (nout,*) 'Correlation-like coefficients'
       WRITE (nout,99998) (i,i=1,m)
       WRITE (nout,99997) (i,rz(i,1:m),i=1,m)

99999  FORMAT (1X,A,I5)
99998  FORMAT (1X,6I12)
99997  FORMAT (1X,I3,3F12.4)
99996  FORMAT (1X,I5,2F11.4)
    END PROGRAM g02bdfe
