c-----------------------------------------------------------
c Chapter 1: Next subset of an n-set(p19)
c-----------------------------------------------------------
c   Name of subroutine: LEXSUB
c
c   Algorithm:Generating subsets of {1,2,...,n} which
c             succeed input set, in lexicographical order, 
c             with optional jumps over supersets.     
c
c-----------------------------------------------------------

c-----The driver program is in lexsub_2.f-------------------

c-----Subroutine begins here-------------------------------   
      subroutine lexsub(n,k,in,jmp,ndim)
      dimension in(ndim)
      logical jmp
   10 if(k.ne.0)goto 40
   20 if(jmp)return
   30 is=0
  100 if(.not.jmp)k=k+1
  110 in(k)=is+1
      return
   40 if(in(k).eq.n)goto 50
   80 is=in(k)
   90 goto 100
   50 k=k-1
   60 if(k.eq.0)return
      is=in(k)
      goto 110
      end

