       subroutine trifac1(a,b,c,n)
C
C  factor tridiagonal system into LDU.  L replaces a, 1/D replaces b, and
C  U replaces c.  Diagonals of L and U are identically 1 and not stored.
C  a(1) and c(n) and lots else are clobbered in this cyclic reduction version.
C
C
      implicit none
      integer n
      real a(n),b(n),c(n)
C
#define L(im) a(im)
#define D(im) b(im)
#define U(im) c(im)
C
      integer im
C
      if(n.le.0) return
C
C First compute ordinary LDU factors
C
	  D(1)=1.0/B(1)
	  U(1)=-C(1)*D(1)
C
      do im=2,n-1,1
	       D(im)=1.0/(B(im)+A(im)*U(im-1))
	       L(im)=-A(im)*D(im-1)
	       U(im)=-C(im)*D(im)
      enddo
C
      if(n.eq.1) return
C
	  D(n)=1.0/(B(n)+A(n)*U(n-1))
	  L(n)=-A(n)*D(n-1)
C
C Now modify for cyclic reduction
C
      call rbi(L(1),1,D(1),1,n,1)
      call rbi(U(n),-1,D(n),-1,n,1)
C
      return
      end
