    PROGRAM g07bbfe

!      G07BBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : g07bbf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: nin = 5, nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: corr, dev, sexmu, sexsig, tol, xmu,  &
                                          xsig
       INTEGER                         :: i, ifail, maxit, n, nit
       CHARACTER (1)                   :: method
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: wk(:), x(:), xc(:)
       INTEGER, ALLOCATABLE            :: ic(:)
       INTEGER                         :: nobs(4)
!      .. Executable Statements ..
       WRITE (nout,*) 'G07BBF Example Program Results'
       WRITE (nout,*)

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

!      Read in problem size and control parameters
       READ (nin,*) n, method, xmu, xsig, tol, maxit

       ALLOCATE (x(n),xc(n),ic(n),wk(2*n))

!      Read in data
       READ (nin,*) (x(i),xc(i),ic(i),i=1,n)

!      Calculate estimates
       ifail = 0
       CALL g07bbf(method,n,x,xc,ic,xmu,xsig,tol,maxit,sexmu,sexsig,corr,dev, &
          nobs,nit,wk,ifail)

!      Display results
       WRITE (nout,99999) ' Mean = ', xmu
       WRITE (nout,99999) ' Standard deviation = ', xsig
       WRITE (nout,99999) ' Standard error of mean = ', sexmu
       WRITE (nout,99999) ' Standard error of sigma = ', sexsig
       WRITE (nout,99999) ' Correlation coefficient = ', corr
       WRITE (nout,99998) ' Number of right censored observations = ', nobs(1)
       WRITE (nout,99998) ' Number of left censored observations = ', nobs(2)
       WRITE (nout,99998) ' Number of interval censored observations = ', &
          nobs(3)
       WRITE (nout,99998) ' Number of exactly specified observations = ', &
          nobs(4)
       WRITE (nout,99998) ' Number of iterations = ', nit
       WRITE (nout,99999) ' Log-likelihood = ', dev

99999  FORMAT (1X,A,F8.4)
99998  FORMAT (1X,A,I2)
    END PROGRAM g07bbfe
