      SUBROUTINE SINV(Z,L,N,IK)
C
C  TO INVERT ARRAY Z OF ORDER N 
C
      REAL*8 Z(N,N),TP
      INTEGER*2 L(N)
      IK=0
      DO 10 I=1,N
   10 L(I)=I
      DO 21 I=1,N
C
C  FIND ELEMENT IN COLUMN WITH LARGEST ABSOLUTE VALUE
C
      TP=0.0
      I1=0
      DO 11 J=I,N
      IF (TP.GE.ABS(Z(J,I))) GOTO 11
      TP=ABS(Z(J,I))
      I1=I
   11 CONTINUE
      IF (I1-I) 12,15,13
   12 IK=I
      RETURN
C
C  EXCHANGE ROWS IF NECESSARY
C
   13 K=L(I1)
      L(I1)=L(I)
      L(I)=K
      DO 14 J=1,N
      TP=Z(I,J)
      Z(I,J)=Z(I1,J)
   14 Z(I1,J)=TP
C
C  NORMALIZE THE PIVOTAL ROW
C
   15 TP=Z(I,I)
      Z(I,I)=1.0
      DO 16 J=1,N
   16 Z(I,J)=Z(I,J)/TP
C
C  NEUTRALIZE THE PIVOTAL COLUMN
C
      DO 20 J=1,N
      IF (J-I) 17,20,17
   17 TP=Z(J,I)
      IF (TP) 18,20,18
   18 Z(J,I)=0.0
      DO 19 K=1,N
   19 Z(J,K)=Z(J,K)-TP*Z(I,K)
   20 CONTINUE
   21 CONTINUE
C
C  RETURN COLUMNS TO ORIGINAL LOCATIONS
C
      DO 26 I=1,N
      IF (L(I)-I) 26,26,22
   22 DO 25 J=I,N
      IF (L(J)-I) 25,23,25
   23 DO 24 K=1,N
      TP=Z(K,I)
      Z(K,I)=Z(K,J)
   24 Z(K,J)=TP
      L(J)=L(I)
      GOTO 26
   25 CONTINUE
   26 CONTINUE
      RETURN
      END
