    Program g03zafe

!     G03ZAF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g03zaf, nag_wp, x04caf
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Integer                          :: i, ifail, ldx, ldz, m, n, nvar
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: e(:), s(:), x(:,:), z(:,:)
      Integer, Allocatable             :: isx(:)
!     .. Intrinsic Procedures ..
      Intrinsic                        :: count
!     .. Executable Statements ..
      Write (nout,*) 'G03ZAF Example Program Results'
      Write (nout,*)
      Flush (nout)

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

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

      ldx = n
      Allocate (x(ldx,m),isx(m),e(m),s(m))

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

!     Read in variable inclusion flags
      Read (nin,*) isx(1:m)

!     Read in shift and scaling
      Read (nin,*) e(1:m)
      Read (nin,*) s(1:m)

!     Calculate NVAR
      nvar = count(isx(1:m)/=0)

      ldz = n
      Allocate (z(ldz,nvar))

!     Standardize data
      ifail = 0
      Call g03zaf(n,m,x,ldx,nvar,isx,s,e,z,ldz,ifail)

!     Display results
      ifail = 0
      Call x04caf('General',' ',n,nvar,z,ldz,'Standardized Values',ifail)

    End Program g03zafe
