      function istkgs (nitems, itype)
      common /cstak / dstak(500)
      double precision dstak
      integer istak(1000), isize(6)
      equivalence (istak(1), dstak(1))
      equivalence (istak(11), isize(1))
      equivalence (istak(7), need)
c
      ileft = istkqu (iabs (itype))
      if (ileft.lt.nitems) go to 10
c
      istkgs = istkgt (nitems, itype)
      print *, 'istkgs 1  ', istkgs, need
      print *, 'istkgs ', (istak(i), i=1, 14)
      return
c
 10   ity = iabs (itype)
      print *, 'istkgs ', (istak(i), i=1, 14)
      if (ileft.gt.0) itemp = istkgt (ileft, ity)
      if (ileft.gt.0) need = (nitems-ileft)*isize(ity) + 2*isize(2)
      if (ileft.le.0) need = need + nitems*isize(ity) + 2*isize(2)
      istkgs = -need
      print *, 'istkgs 2  ', istkgs, need
c
      return
      end