c    @(#)trdslv.f	1.2
c
      subroutine trdslv (n,a,b,c,y,x,ks,alpha,gamma)
      dimension       a(n)       ,b(n)       ,c(n)       ,y(n)       ,
     1                x(n)       ,alpha(n)   ,gamma(n)
      nm1 = n-1
      if (ks .eq. 1) go to 102
      alpha(1) = 1./b(1)
      gamma(1) = c(1)*alpha(1)
      do 101 i=2,nm1
         alpha(i) = 1./(b(i)-a(i)*gamma(i-1))
         gamma(i) = c(i)*alpha(i)
  101 continue
  102 continue
      x(1) = y(1)*alpha(1)
      do 103 i=2,nm1
         x(i) = (y(i)-a(i)*x(i-1))*alpha(i)
  103 continue
      x(n) = (y(n)-a(n)*x(nm1))/(b(n)-a(n)*gamma(nm1))
      do 104 j=1,nm1
         jb = n-j
         x(jb) = x(jb)-gamma(jb)*x(jb+1)
  104 continue
      return
	end
