*     *************************************************************************

      subroutine bding( bound, ba, nba, su, nsu, x, xst )

*     *************************************************************************

*     Purpose :
*     ---------

*     This routine checks if some basic or superbasic variables
*     hit a bound. If it is the case, the status of these variables
*     are modified and are set to the status of bounded variables.

*     Parameters :
*     ------------

*     bound   ( int )

*       input  : it must be equal to zero.
*       output : 0 iff no basic and superbasic variables hit a bound.
*                1 iff at least one basic variable hits a bound.
*                2 iff no basic variable hit a bound and a least one
*                  superbasic variable hits a bound.

*     ba      ( int )

*       input  : array containing the indices of the basic
*                variables.
*       output : unmodified.

*     nba     ( int )

*       input  : the number of basic variables.
*       output : unmodified.

*     su      ( int )

*       input  : array containing the indices of the superbasic 
*                variables.
*       output : unmodified.

*     nsu     ( int )

*       input  : the number of superbasic variables.
*       output : unmodified.

*     x       ( dble )

*       input  : the current iterate vector.
*       output : unmodified.

*     xst     ( int )

*       input  : vector containing the status of the variables.
*       output : the status of the basic or superbasic variables
*                that hit a bound are modified and are set to 
*                the status of bounded variables.

*     Routines used :
*     ---------------

*     abs.
*     xlower, xupper, sxbdg.

*     Programming :
*     -------------

*     D. Tuyttens

*     ========================================================================

*     Routine parameters

      integer           bound, ba(*), nba, su(*), nsu, xst(*)
      double precision  x(*)

*     Internal variables

      integer           ik, k
      double precision  xlower, xupper, lb, ub

*     Common specifications

      double precision  epsmch, huge, tiny, tol
      common / prbmch / epsmch, huge, tiny, tol

      double precision  zero, one, two, three, half, tenm1, tenm2, tenm4
      common / prbcst / zero, one, two, three, half, tenm1, tenm2, tenm4
*
*     Loop on the basic variables. If one of them
*     hits a bound, modify its status.
*
      do 10 ik = 1 , nba
        k  = ba(ik)
        lb = xlower(k)
        ub = xupper(k)
        if( x(k)-lb.le.tol*(one+abs(lb)) .or.
     +      ub-x(k).le.tol*(one+abs(ub)) ) then
          bound = 1
          call sxbdg(xst(k))
        endif
 10   continue
*
*     Loop on the superbasic variables. If one of them
*     hits a bound, modify its status.
*
      do 20 ik = 1 , nsu
        k  = su(ik)
        lb = xlower(k)
        ub = xupper(k)
        if( x(k)-lb.le.tol*(one+abs(lb)) .or.
     +      ub-x(k).le.tol*(one+abs(ub)) ) then
          if( bound.eq.0 ) bound = 2
          call sxbdg(xst(k))
        endif
 20   continue
*
      return
      end
