C
      SUBROUTINE ZIF1M (A,N,NA,EPS,RDET,IDET,WK,IWK,IER)
C
      IMPLICIT REAL*8 (A-H,O-Z)
      COMPLEX * 16  A,RDET,T,ZMAX,ZZERO,ZONE
C      GENERIC
      DIMENSION A(NA,N),WK(N),IWK(N)
      DATA ZERO,ONE,SIXTN      / 0.0D0,1.0D0,16.0D0                  /
C      DATA PT0625,UEPS         / 0.0625D0,Z3410000000000000          /
      DATA ZZERO,ZONE          / (0.0D0,0.0D0),(1.0D0,0.0D0)         /
C
C      REAL(T)=DREAL(T)
C      ZABS(T)=ABS(REAL(T))+ABS(IMAG(T))
C
C     PARAMETER CHECK AND INITIALIZATION
C
      PT=0.0625D0

,Z3410000000000000          /
       IF (N.LT.1 .OR. N.GT.NA) GO TO 160
      IER=0
      DO 10 I=1,N
         WK(I)=ZERO
   10 CONTINUE
      DO 30 J=1,N
         DO 20 I=1,N
            IF (CDABS(A(I,J)) .GT. WK(I)) WK(I)=CDABS(A(I,J))
   20    CONTINUE
   30 CONTINUE
      DO 40 I=1,N
         Q=WK(I)
         IF (Q .EQ. ZERO) GO TO 170
         WK(I)=ONE/Q
   40 CONTINUE
      SEPS=EPS
      IF (EPS .LT. ZERO) SEPS=SIXTN*FLOAT(N)*UEPS
      RDET=ZONE
      IDET=0
C
C     ELIMINATION BY GAUSS-JORDAN METHOD
C
      DO 130 K=1,N
         AMAX=ZERO
         KMAX=K
         DO 50 I=K,N
            IF (CDABS(A(I,K))*WK(I) .LE. AMAX) GO TO 50
               AMAX=CDABS(A(I,K))*WK(I)
               KMAX=I
   50    CONTINUE
         IF (AMAX .LE. SEPS) GO TO 170
C
         RDET=RDET*A(KMAX,K)
         IF (K .NE. KMAX) RDET=-RDET
C         ADET=MAX(ABS(REAL(RDET)),ABS(IMAG(RDET)))
         ADET=MAX(DABS(DREAL(RDET)),DABS(DIMAG(RDET)))
   60    IF (ADET .LT. ONE) GO TO 70
            ADET=ADET*PT0625
            RDET=RDET*PT0625
            IDET=IDET+4
            GO TO 60
C
   70    IF (ADET .GE. PT0625) GO TO 80
            ADET=ADET*SIXTN
            RDET=RDET*SIXTN
            IDET=IDET-4
            GO TO 70
C
   80    IWK(K)=KMAX
         ZMAX=-ZONE/A(KMAX,K)
         T=A(KMAX,K)
         A(KMAX,K)=A(K,K)
         A(K,K)=T
         T=WK(KMAX)
         WK(KMAX)=WK(K)
         WK(K)=T
         DO 110 J=1,N
            IF (J .EQ. K) GO TO 110
               T=A(KMAX,J)*ZMAX
               A(KMAX,J)=A(K,J)
               IF (CDABS(T) .LE. ZERO) GO TO 100
                  DO 90 I=1,N
                     A(I,J)=A(I,J)+T*A(I,K)
   90             CONTINUE
  100           A(K,J)=-T
  110    CONTINUE
         DO 120 I=1,N
            A(I,K)=A(I,K)*ZMAX
  120    CONTINUE
         A(K,K)=-ZMAX
  130 CONTINUE
C
      DO 150 L=1,N
         K=N-L+1
         IF (K .EQ. IWK(K)) GO TO 150
            KMAX=IWK(K)
            DO 140 I=1,N
               T=A(I,K)
               A(I,K)=A(I,KMAX)
               A(I,KMAX)=T
  140       CONTINUE
  150 CONTINUE
C
C     NORMAL RETURN
C
      GO TO 9999
C
C     PARAMETER ERROR
C
 160 CONTINUE 
C
      GO TO 9999
C
C     MATRIX IS SINGULAR
C
  170 RDET=ZZERO
      IDET=0
C
 9999 CONTINUE 
      RETURN
      END
