      SUBROUTINE TRIDAGC(A,B,C,R,U,N)
c solve a tridiagonal matrix with complex coefficients

      implicit none
      integer nmax
      PARAMETER (NMAX=512)

c arguments:
      integer n
      complex A(N),B(N),C(N),R(N),U(N)

c local variables:
      complex GAM(NMAX)
      complex bet
      integer j

      IF(abs(B(1)).EQ.0.) call aborter(6,'error in tridagc.f')
      BET=B(1)
      U(1)=R(1)/BET
      DO 11 J=2,N
        GAM(J)=C(J-1)/BET
        BET=B(J)-A(J)*GAM(J)
        IF(abs(BET).EQ.0.) call aborter(6,'BET error in tridagc.f')
        U(J)=(R(J)-A(J)*U(J-1))/BET
11    CONTINUE
      DO 12 J=N-1,1,-1
        U(J)=U(J)-GAM(J+1)*U(J+1)
12    CONTINUE
      RETURN
      END
