    PROGRAM g07dbfe

!      G07DBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g07dbf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: c, dchi, h1, h2, h3, sigma, sigsav,  &
                                          thesav, theta, tol
       INTEGER                         :: ifail, ipsi, isigma, maxit, n, nit
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: rs(:), wrk(:), x(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'G07DBF Example Program Results'
       WRITE (nout,*)

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

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

       ALLOCATE (x(n),rs(n),wrk(n))

!      Read in data
       READ (nin,*) x(1:n)

!      Read in details of algorithm to use
       READ (nin,*) ipsi, dchi, maxit
       IF (ipsi==2) THEN
          READ (nin,*) h1, h2, h3
       END IF

!      Display titles
       WRITE (nout,*) '          Input parameters     Output parameters'
       WRITE (nout,*) 'ISIGMA   SIGMA   THETA   TOL    SIGMA  THETA'

D_LP:  DO
          READ (nin,*,IOSTAT=ifail) isigma, sigma, theta, tol
          IF (ifail/=0) THEN
             EXIT D_LP
          END IF

!         Save the input parameters for later display
          sigsav = sigma
          thesav = theta

!         Compute M-estimates
          ifail = 0
          CALL g07dbf(isigma,n,x,ipsi,c,h1,h2,h3,dchi,theta,sigma,maxit,tol, &
             rs,nit,wrk,ifail)

!         Display results
          WRITE (nout,99999) isigma, sigsav, thesav, tol, sigma, theta
       END DO D_LP

99999  FORMAT (1X,I3,3X,2F8.4,F7.4,F9.4,F8.4,I4)
    END PROGRAM g07dbfe
