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

      subroutine dkstem( k, fr, to, pr, depth, ftstem, nro, kandis )

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

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

*     Given a superbasic variable K, this routine evaluates the
*     length from the origine node of arc K to the stem node and
*     the length from the end node of arc K to the stem node.
*     It stores the first length and the sum of these lengths in
*     the array FTSTEM. The sum of these two lengths is the length
*     of the flow augmenting path of the superbasic variable K.

*     We define the stem node of a given superbasic arc as the 
*     first common node of the paths to the root node of its
*     two ending nodes.

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

*     k       ( int )

*       input  : the arc for which we evaluate the lengths from
*                its two ending nodes to the stem node.
*       output : unmodified.

*     fr      ( int )

*       input  : vector containing the origine nodes of the arcs.
*       output : unmodified.

*     to      ( int )

*       input  : vector containing the end nodes of the arcs.
*       output : unmodified.

*     pr      ( int )

*       input  : the predecessor vector.
*       output : unmodified.

*     depth   ( int )

*       input  : the depth vector.
*       output : unmodified.

*     ftstem  ( int )

*       input  : vector containing for each superbasic variable
*                the length of its origine node to the stem node
*                and the length of its flow augmenting path.
*       output : the Kth component is updated.

*     nro     ( int )

*       input  : the sum of the lengths of the flow augmenting
*                paths of all the superbasic variables.
*       output : we add to NRO the length of the flow augmenting
*                path of variable K.

*     kandis  ( int )

*       input  : the length of the longest flow augmenting path.
*       output : it is updated if neccessary.

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

*     max, min, abs.
*     setdbl.

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

*     D. Tuyttens

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

*     Routine parameters

      integer  k, fr(*), to(*), pr(*), depth(*), ftstem(*),
     +         nro, kandis

*     Internal variables

      integer  idepth,  i,  fk, tk,  fstem, tstem,  fptstm

*
*     Initialize the two lengths FSTEM and TSTEM.
*      FSTEM : length from FR(K) to the stem node.
*      TSTEM : length from TO(K) to the stem node.
*
      fk     = fr(k)
      tk     = to(k)
      idepth = depth(fk) - depth(tk)
      fstem  =  max( 0 , idepth )
      tstem  = -min( 0 , idepth )
*
*     We start from the node having the largest depth
*     and we loop until finding two nodes having the
*     same depth.
*
      do 10 i = 1 , abs(idepth)
        if( fstem.ne.0 ) then
          fk = pr(fk)
        else
          tk = pr(tk)
        endif
 10   continue
*
*     We climb the two branches of the tree at the
*     same time until reaching the stem node.
*
 11   if( fk.ne.tk ) then
        fstem = fstem + 1
        tstem = tstem + 1
        fk = pr(fk)
        tk = pr(tk)
        go to 11
      endif
*
*     We store the evaluated informations in FTSTEM(K).
*
      fptstm = fstem + tstem
      nro    = nro   + fptstm
      kandis = max( kandis , fptstm )
      call setdbl( fstem,   1, ftstem(k) )
      call setdbl( fptstm , 2, ftstem(k) )
*
      return
      end
