NAG Library Manual, Mark 30.1
Interfaces:  FL   CL   CPP   AD 

NAG FL Interface Introduction
Example description
    Program g02bjfe

!     G02BJF Example Program Text

!     Mark 30.1 Release. NAG Copyright 2024.

!     .. Use Statements ..
      Use nag_library, Only: g02bjf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, ldcnt, ldr, ldssp, ldx, m, &
                                          n, ncases, nvars
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: cnt(:,:), r(:,:), ssp(:,:), std(:),  &
                                          x(:,:), xbar(:), xmiss(:)
      Integer, Allocatable             :: kvar(:), miss(:)
!     .. Executable Statements ..
      Write (nout,*) 'G02BJF Example Program Results'
      Write (nout,*)

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

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

      ldcnt = nvars
      ldr = nvars
      ldssp = nvars
      ldx = n
      Allocate (cnt(ldcnt,nvars),r(ldr,nvars),ssp(ldssp,nvars),std(nvars),     &
        x(ldx,m),xbar(nvars),xmiss(m),kvar(nvars),miss(m))

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

!     Read in missing value flags
      Read (nin,*) miss(1:m)
      Read (nin,*) xmiss(1:m)

!     Read in column IDs
      Read (nin,*) kvar(1:nvars)

!     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,99998)(i,i=1,m)
      Write (nout,99997)(i,x(i,1:m),i=1,n)
      Write (nout,*)

!     Calculate summary statistics
      ifail = 0
      Call g02bjf(n,m,x,ldx,miss,xmiss,nvars,kvar,xbar,std,ssp,ldssp,r,ldr,    &
        ncases,cnt,ldcnt,ifail)

!     Display results
      Write (nout,*) 'Variable   Mean    St. dev.'
      Write (nout,99995)(kvar(i),xbar(i),std(i),i=1,nvars)
      Write (nout,*)
      Write (nout,*) 'Sums of squares and cross-products of deviations'
      Write (nout,99998) kvar(1:nvars)
      Write (nout,99996)(kvar(i),ssp(i,1:nvars),i=1,nvars)
      Write (nout,*)
      Write (nout,*) 'Correlation coefficients'
      Write (nout,99998) kvar(1:nvars)
      Write (nout,99996)(kvar(i),r(i,1:nvars),i=1,nvars)
      Write (nout,*)
      Write (nout,99999)                                                       &
        'Minimum number of cases used for any pair of variables:', ncases
      Write (nout,*)
      Write (nout,*) 'Numbers used for each pair are:'
      Write (nout,99998) kvar(1:nvars)
      Write (nout,99996)(kvar(i),cnt(i,1:nvars),i=1,nvars)

99999 Format (1X,A,I5)
99998 Format (1X,4I12)
99997 Format (1X,I3,4F12.4)
99996 Format (1X,I3,3F12.4)
99995 Format (1X,I5,2F11.4)
    End Program g02bjfe