c    @(#)trid.f	1.3
c
      subroutine trid (kstart,kstop,ising,m,n,mm1,a,b,c,y,twocos,d,w)
      dimension  a(m),b(m),c(m),y(m),
     1                twocos(6*n+5*m),d(m),w(m)
c
c uro is a machine dependent constant.  it is the smallest floating
c point number such that 1 + uro is greater than 1 in the
c arithmetic of this computer.
c
      uro = 1./2.**20
  101     do 106 k=kstart,kstop
          x = -twocos(k)
          d(1) = c(1)/(b(1)+x)
          y(1) = y(1)/(b(1)+x)
              do 103 i=2,m
              z = b(i)+x-a(i)*d(i-1)
              d(i) = c(i)/z
  102         y(i) = (y(i)-a(i)*y(i-1))/z
  103         continue
              do 105 ip=1,mm1
              i = m-ip
  104         y(i) = y(i)-d(i)*y(i+1)
  105         continue
  106     continue
  107 if (ising.eq.1) return
      d(1) = c(1)/(b(1)-2.)
      y(1) = y(1)/(b(1)-2.)
          do 109 i=2,mm1
          z = b(i)-2.-a(i)*d(i-1)
          d(i) = c(i)/z
  108     y(i) = (y(i)-a(i)*y(i-1))/z
  109     continue
      z = b(m)-2.-a(m)*d(m-1)
      x = y(m)-a(m)*y(m-1)
      if (abs(z).gt.(30.*m*abs(a(m)))*uro) go to 111
  110 y(m) = 0.
      go to 112
  111 y(m) = x/z
  112     do 114 ip=1,mm1
          i = m-ip
  113     y(i) = y(i)-d(i)*y(i+1)
  114     continue
      return
      end
