      DOUBLE PRECISION FUNCTION DPDET(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     -------------------
      DOUBLE PRECISION A(KA,N),X
      DOUBLE PRECISION PIVOT,S,C
      IF (N .GE. 2) GO TO 10
      DPDET = A(1,1) - X
      RETURN
C
C              REPLACE A WITH A-XI
C
   10 IF (X .EQ. 0.D0) GO TO 20
      DO 11 K=1,N
   11 A(K,K) = A(K,K) - X
C
C                INITIALIZATION
C
   20 DPDET = 1.D0
      NM1 = N - 1
      DO 52 K=1,NM1
      KP1 = K + 1
C
C       SEARCH FOR THE K-TH PIVOT ELEMENT
C
      S = DABS(A(K,K))
      L = K
      DO 30 I=KP1,N
      C = DABS(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 DET
C
      DPDET = DPDET*PIVOT
      IF (DPDET .EQ. 0.D0) RETURN
      IF (K .EQ. L) GO TO 50
      DPDET = -DPDET
C
C          INTERCHANGING ROWS K AND L
C
      DO 40 J=K,N
      C = A(K,J)
      A(K,J) = A(L,J)
   40 A(L,J) = C
C
C        REDUCTION OF THE NON-PIVOT ROWS
C
   50 DO 51 I=KP1,N
      C = A(I,K)/PIVOT
      DO 51 J=KP1,N
   51 A(I,J) = A(I,J) - C*A(K,J)
   52 CONTINUE
C
C         FINAL DETERMINANT CALCULATION
C
      DPDET = DPDET*A(N,N)
      RETURN
      END
