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

      subroutine nbstat( x, xst, su, nsu, ba, nba, nb,
     +                   nacti, naibs, iss, ip, kdist )

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

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

*     This routine modifies the status of the superbasic
*     variables that are bounded. These variables become
*     nonbasic. The superbasic set SU is reordered.

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

*     x       ( dble )

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

*     xst     ( int )

*       input  : vector containing the status of the variables.
*       output : the status of the superbasic variables that are
*                bounded are modified and correspond to the status
*                of nonbasic variables.

*     su      ( int )

*       input  : vector containing the indices of the superbasic
*                variables.
*       output : the vector contains only the indices of the
*                superbasic variables that are not bounded.

*     nsu     ( int )

*       input  : the number of superbasic variables.
*       output : the number of superbasic variables that are not
*                bounded.

*     ba      ( int )

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

*     nba     ( int )

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

*     nb      ( int )

*       input  : the number of nonbasic variables.
*       output : this number increases by one each time a
*                superbasic variable is detected as bounded.

*     nacti   ( int )

*       input  : the number of variables that have been activated.
*       output : this number increases by one each time a
*                superbasic variable is detected as bounded.

*     naibs   ( int )

*       input  : vector whose IPth component contains the number
*                of superbasic variables in independent set IP.
*       output : the component decreases by one each time a
*                superbasic variable is detected as bounded.

*     iss     ( int )

*       input  : vector whose kth component contains the indice of
*                independent superbasic set in which the kth variable
*                is included. If the kth component is zero, then
*                variable k is not included in one independent set.
*       output : the components corresponding to the indices of the
*                superbasic variables that are bounded are set to zero.
*                If the superbasic set becomes empty, the components
*                corresponding to the indices of the basic variables are
*                also set to zero.

*     ip      ( int )

*       input  : the indice of the independent superbasic set
*                in which where are working.
*       output : unmodified.

*     kdist   ( int )

*       input  : vector containing for each superbasic variable
*                the length of its flow augmenting path.
*       output : only the components of the superbasic variables
*                that are not bounded are maintained.

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

*     abs.
*     snxdej, sxdej, sxnbl, sxnbu, gxbdg, xlower, isetcd.

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

*     D. Tuyttens

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

*     Routine parameters

      integer           xst(*),  su(*),  nsu, ba(*), nba,  nb,
     +                  nacti, naibs(*), iss(*), ip, kdist(*)
      double precision  x(*)

*     Internal variables

      integer           ik, k, next
      logical           gxbdg
      double precision  lb, xlower

*     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
*
*     Initialize the status of the independent set IP to
*     an independent set that does not need to be de-joined.
*
      call snxdej(xst(ip))
*
*     Loop on the superbasic variables and test if
*     some of them are bounded.
*
      next = 0
      do 10 ik = 1 , nsu
        k = su(ik)
        if( gxbdg(xst(k)) ) then
*
*         The superbasic variable K is bounded.
*         Modify its status such that it corresponds
*         to a nonbasic variable.
*
          lb = xlower(k)
          if( x(k)-lb .le. tol*(one+abs(lb)) ) then
            call sxnbl(xst(k))
          else
            call sxnbu(xst(k))
          endif
*
*         The nonbasic set is increased, but the
*         superbasic set is decreased.
*         The status of the independent set IP,
*         is modified and correspond to the status of
*         an independent set that need to be de-joined.
*
          nb     = nb + 1
          naibs(ip) = naibs(ip) - 1
          iss(k) = 0
          nacti  = nacti + 1
          call sxdej(xst(ip))
        else
*
*         The superbasic variable is not bounded.
*         The vectors SU and KDIST are reordered.
*
          next = next + 1
          su(next)    = su(ik)
          kdist(next) = kdist(ik)
        endif
 10   continue
      nsu = next
*
*     If the superbasic set becomes empty,
*     then the independent set IP disappears.
*
      if( naibs(ip).eq.0 ) then
        call snxdej(xst(ip))
        call isetcd(nba, ba, iss, 0 )
      endif
*
      return
      end