    PROGRAM h02cbfe

!      H02CBF Example Program Text

!      Mark 23 Release. NAG Copyright 2011.

!      .. Use Statements ..
       USE nag_library, ONLY : e04nfu, h02cbf, h02cbu, h02cdf, nag_wp
!      .. Implicit None Statement ..
       IMPLICIT NONE
!      .. Parameters ..
       INTEGER, PARAMETER              :: lintvr = 1, mdepth = 30, nin = 5,    &
                                          nout = 6
!      .. Local Scalars ..
       REAL (KIND=nag_wp)              :: obj
       INTEGER                         :: i, ifail, j, lda, ldh, liwrk, lwrk,  &
                                          n, nclin, strtgy
!      .. Local Arrays ..
       REAL (KIND=nag_wp), ALLOCATABLE :: a(:,:), ax(:), bl(:), bu(:),         &
                                          clamda(:), cvec(:), h(:,:), wrk(:),  &
                                          xs(:)
       INTEGER, ALLOCATABLE            :: intvar(:), istate(:), iwrk(:)
!      .. Executable Statements ..
       WRITE (nout,*) 'H02CBF Example Program Results'

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

       READ (nin,*) n, nclin
       lda = nclin
       ldh = n
       liwrk = 2*n + 3 + 2*mdepth

!      LWRK for default problem-type QP2

       IF (nclin==0) THEN
          lwrk = n**2 + 9*n + 4*mdepth
       ELSE
          lwrk = 2*n**2 + 9*n + 5*nclin + 4*mdepth
       END IF

       ALLOCATE (a(lda,n),ax(nclin),bl(n+nclin),bu(n+nclin),clamda(n+nclin), &
          cvec(n),h(ldh,n),xs(n+nclin),intvar(lintvr),istate(n+nclin), &
          iwrk(liwrk),wrk(lwrk))

       READ (nin,*) (cvec(i),i=1,n)
       READ (nin,*) ((a(i,j),j=1,n),i=1,nclin)
       READ (nin,*) (bl(i),i=1,n+nclin)
       READ (nin,*) (bu(i),i=1,n+nclin)
       READ (nin,*) (xs(i),i=1,n)
       READ (nin,*) ((h(i,j),j=1,n),i=1,n)

       strtgy = 2
       intvar(1) = 4

       CALL h02cdf('Nolist')

       CALL h02cdf('Print Level = 0')

!      Solve the problem

       ifail = 0
       CALL h02cbf(n,nclin,a,lda,bl,bu,cvec,h,ldh,e04nfu,intvar,lintvr,mdepth, &
          istate,xs,obj,ax,clamda,strtgy,iwrk,liwrk,wrk,lwrk,h02cbu,ifail)

!      Print out the best integer solution found

       WRITE (nout,99999) obj, (i,xs(i),i=1,n)

99999  FORMAT (' Optimal Integer Value is = ',E20.8/' Components are ', &
          7(/' X(',I3,') = ',F15.8))
    END PROGRAM h02cbfe
