    PROGRAM g07gbfe

!      G07GBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g07gbf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: e, lx, ux, var1, var2, x
       INTEGER                         :: ifail, n
       LOGICAL                         :: outlier
!      .. Executable Statements ..
       WRITE (nout,*) 'G07GBF Example Program Results'
       WRITE (nout,*)

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

D_LP:  DO
!         Read in the sample size, variances and value to test
          READ (nin,*,IOSTAT=ifail) n, e, var1, var2
          IF (ifail/=0) EXIT D_LP

!         Check whether E is a potential outlier
          ifail = 0
          outlier = g07gbf(n,e,var1,var2,x,lx,ux,ifail)

!         Display results
          WRITE (nout,99999) 'Sample size                              :', n
          WRITE (nout,99998) 'Largest absolute residual (E)            :', e
          WRITE (nout,99998) 'Variance for whole sample                :', &
             var1
          WRITE (nout,99998) 'Variance excluding E                     :', &
             var2
          WRITE (nout,99998) 'Estimate for cutoff (X)                  :', x
          WRITE (nout,99998) 'Lower limit for cutoff (LX)              :', lx
          WRITE (nout,99998) 'Upper limit for cutoff (UX)              :', ux
          IF (outlier) THEN
             WRITE (nout,*) 'E is a potential outlier'
          ELSE
             WRITE (nout,*) 'E does not appear to be an outlier'
          END IF
          WRITE (nout,*)
       END DO D_LP

99999  FORMAT (1X,A,1X,I10)
99998  FORMAT (1X,A,1X,F10.3)
    END PROGRAM g07gbfe
