    PROGRAM h02bufe

!      H02BUF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e04mff, e04mhf, h02buf, h02bvf, nag_wp, x04acf, &
                               x04baf
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       REAL (KIND=nag_wp), PARAMETER   :: xbl_default = 0.0E0_nag_wp
       REAL (KIND=nag_wp), PARAMETER   :: xbu_default = 1.0E+20_nag_wp
       INTEGER, PARAMETER              :: maxm = 50, maxn = 50, nindat = 7,    &
                                          nout = 6
       INTEGER, PARAMETER              :: lda = maxm
       INTEGER, PARAMETER              :: liwork = 2*maxn + 3
       INTEGER, PARAMETER              ::                                      &
                                        lwork = 2*(maxm+1)**2 + 7*maxn + 5*maxm
       CHARACTER (*), PARAMETER        :: fname = 'h02bufe.opt'
       CHARACTER (8), PARAMETER        :: kblank = '        '
       CHARACTER (3), PARAMETER        :: optim = 'MIN'
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: objval
       INTEGER                         :: ifail, infile, iter, m, mode, n
       LOGICAL                         :: mpslst
       CHARACTER (8)                   :: nmbnd, nmobj, nmprob, nmrhs, nmrng
       CHARACTER (80)                  :: rec
!      .. Local Arrays ..
       REAL (KIND=nag_wp)              :: a(maxm,maxn), ax(maxm),              &
                                          bl(maxn+maxm), bu(maxn+maxm),        &
                                          clamda(maxn+maxm), cvec(maxn),       &
                                          work(lwork), x(maxn)
       INTEGER                         :: intvar(maxn), istate(maxn+maxm),     &
                                          iwork(liwork)
       CHARACTER (8)                   :: crname(maxn+maxm)
!      .. Executable Statements ..
       WRITE (rec,99999) 'H02BUF Example Program Results'
       CALL x04baf(nout,rec)

!      Open the data file for reading

       mode = 0

       ifail = 0
       CALL x04acf(nindat,fname,mode,ifail)

!      Initialize parameters

       infile = nindat
       nmprob = kblank
       nmobj = kblank
       nmrhs = kblank
       nmrng = kblank
       nmbnd = kblank
       mpslst = .FALSE.

!      Convert the MPSX data file for use by E04MFF

       ifail = 0
       CALL h02buf(infile,maxn,maxm,optim,xbl_default,xbu_default,nmobj,nmrhs, &
          nmrng,nmbnd,mpslst,n,m,a,bl,bu,cvec,x,intvar,crname,nmprob,istate, &
          ifail)

!      Solve the problem

       CALL e04mhf('Print Level = 5')

       ifail = -1
       CALL e04mff(n,m,a,lda,bl,bu,cvec,istate,x,iter,objval,ax,clamda,iwork, &
          liwork,work,lwork,ifail)

       SELECT CASE (ifail)
       CASE (0,1,3)

!         Print solution (using MPSX names)

          ifail = 0
          CALL h02bvf(n,m,a,lda,bl,bu,x,clamda,istate,crname,ifail)

       END SELECT

99999  FORMAT (1X,A)
    END PROGRAM h02bufe
