      COMPLEX FUNCTION CDET(A,KA,N,X)
C     -------------------
C     EVALUATION OF THE DETERMINANT OF A-XI WHERE A IS AN NXN MATRIX,
C     X IS A SCALAR, AND I IS THE NXN IDENTITY MATRIX.
C     -------------------
C     KA IS THE ROW DIMENSION OF A IN THE CALLING PROGRAM. IT IS
C     ASSUMED THAT KA IS GREATER THAN OR EQUAL TO N.
C     -------------------
      COMPLEX A(KA,N),X
      COMPLEX PIVOT,T,ZERO
      REAL S,C
      DATA ZERO/(0.0,0.0)/
C
      IF (N .GE. 2) GO TO 10
      CDET = A(1,1)-X
      RETURN
C
C              REPLACE A WITH A-XI
C
   10 IF (X .EQ. ZERO) GO TO 20
      DO 11 K=1,N
   11 A(K,K) = A(K,K)-X
C
C                INITIALIZATION
C
   20 CDET = (1.0,0.0)
      NM1 = N-1
      DO 52 K=1,NM1
      KP1 = K+1
C
C       SEARCH FOR THE K-TH PIVOT ELEMENT
C
      S = ABS(REAL(A(K,K))) + ABS(AIMAG(A(K,K)))
      L = K
      DO 30 I=KP1,N
      C = ABS(REAL(A(I,K))) + ABS(AIMAG(A(I,K)))
      IF (S .GE. C) GO TO 30
      S = C
      L = I
   30 CONTINUE
      PIVOT = A(L,K)
C
C         UPDATE THE CALCULATION OF CDET
C
      CDET = CDET*PIVOT
      IF (CDET .EQ. ZERO) RETURN
      IF (K .EQ. L) GO TO 50
      CDET = -CDET
C
C          INTERCHANGING ROWS K AND L
C
      DO 40 J=K,N
      T = A(K,J)
      A(K,J) = A(L,J)
   40 A(L,J) = T
C
C        REDUCTION OF THE NON-PIVOT ROWS
C
   50 DO 51 I=KP1,N
      T = A(I,K)/PIVOT
      DO 51 J=KP1,N
   51 A(I,J) = A(I,J)-T*A(K,J)
   52 CONTINUE
C
C         FINAL DETERMINANT CALCULATION
C
      CDET = CDET*A(N,N)
      RETURN
      END
