    PROGRAM g02fafe

!      G02FAF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. 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
