      program driver
      use lbfgs_bound_mod
      integer          nmax, mmax
      parameter        (nmax=5, mmax=7)
 
      character*60     task, csave
      logical          lsave(4)
      integer          n, m, iprint, &
                       nbd(nmax), iwa(3*nmax), isave(44)
      double precision f, factr, pgtol,  &
                       x(nmax), l(nmax), u(nmax), g(nmax), dsave(29), &
                       wa(2*mmax*nmax+4*nmax+12*mmax*mmax+12*mmax)


      double precision t1, t2
      integer          i
 

      iprint = 1


      factr=1.0d+7
      pgtol=1.0d-5
 
      n=nmax
      m=mmax
 

      nbd = 0

      l = 1.5
      u = 0.

      write (6,16)
  16  format(/,5x, 'Solving sample problem.', &
             /,5x, ' (f = 0.0 at the optimal solution.)',/)     

      task = 'START'

 
 111  continue
      
      call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa,task,iprint, &
                 csave,lsave,isave,dsave)
 
      if (task(1:2) .eq. 'FG') then

         f = sum((x-1.)**2)/nmax

         g = 2*(x-1)

         goto 111
 
      endif

      if (task(1:5) .eq. 'NEW_X')  goto 111

      write(0,*)"x=", x, sum((x-1)**2)
      stop
 
      end program
