Program g02bpfe

!     G02BPF Example Program Text

!     Mark 26 Release. NAG Copyright 2016.

!     .. Use Statements ..
      Use nag_library, Only: g02bpf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, itype, ldrr, ldx, m, n,    &
                                          ncases
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: rr(:,:), work1(:), work2(:), x(:,:), &
                                          xmiss(:)
      Integer, Allocatable             :: incase(:), kworka(:), kworkb(:),     &
                                          kworkc(:), miss(:)
!     .. Executable Statements ..
      Write (nout,*) 'G02BPF Example Program Results'
      Write (nout,*)

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

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

      ldrr = m
      ldx = n
      Allocate (rr(ldrr,m),work1(m),work2(m),x(ldx,m),xmiss(m),incase(n),      &
        kworka(n),kworkb(n),kworkc(n),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)

!     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,*)

!     Calculate correlation coefficients
      ifail = 0
      Call g02bpf(n,m,x,ldx,miss,xmiss,itype,rr,ldrr,ncases,incase,kworka,     &
        kworkb,kworkc,work1,work2,ifail)

!     Display results
      Write (nout,*) 'Matrix of ranks:-'
      Write (nout,*)
      Write (nout,*)                                                           &
        '(1 in the column headed In/Out indicates the case was included,'
      Write (nout,*)                                                           &
        ' 0 in the column headed In/Out indicates the case was omitted.)'
      Write (nout,*)
      Write (nout,99996) 'Case   In/Out', (i,i=1,m)
      Write (nout,99995)(i,incase(i),x(i,1:m),i=1,n)
      Write (nout,*)
      Write (nout,*) 'Matrix of rank correlation coefficients:'
      Write (nout,*) 'Upper triangle -- Spearman''s'
      Write (nout,*) 'Lower triangle -- Kendall''s tau'
      Write (nout,*)
      Write (nout,99998)(i,i=1,m)
      Write (nout,99997)(i,rr(i,1:m),i=1,m)
      Write (nout,*)
      Write (nout,99999) 'Number of cases actually used:', ncases

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