    Program g02fafe

!     G02FAF Example Program Text

!     Mark 24 Release. NAG Copyright 2012.

!     .. Use Statements ..
      Use nag_library, Only: g02faf, nag_wp
!     .. Implicit None Statement ..
      Implicit None
!     .. Parameters ..
      Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
      Real (Kind=nag_wp)               :: rms
      Integer                          :: i, ifail, ip, ldsres, n, nres
!     .. Local Arrays ..
      Real (Kind=nag_wp), Allocatable  :: h(:), res(:), sres(:,:)
!     .. Executable Statements ..
      Write (nout,*) 'G02FAF Example Program Results'
      Write (nout,*)

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

!     Read in the problem size
      Read (nin,*) n, ip, nres, rms

      ldsres = nres
      Allocate (res(nres),h(nres),sres(ldsres,4))

!     Read in the data
      Read (nin,*)(res(i),h(i),i=1,nres)

!     Calculate standardised residuals
      ifail = 0
      Call g02faf(n,ip,nres,res,h,rms,sres,ldsres,ifail)

!     Display results
      Write (nout,*) '        Internally    Internally'
      Write (nout,*) &
        'Obs.   standardized  standardized   Cook''s D   Atkinson''s T'
      Write (nout,*) '         residuals     residuals'
      Write (nout,*)
      Write (nout,99999)(i,sres(i,1:4),i=1,nres)

99999 Format (1X,I2,4F13.3)
    End Program g02fafe
