      SUBROUTINE INV(A,AINV,DET)
C
C     ROUTINE INV PERFORMS AN INVERSION OF A REAL 3*3 MATRIX
C
      DIMENSION A(3,3),AINV(3,3)
      COMMON /AUXI/  IANI(20),INTR,INT1,IOUT,KRE,IREFR,LAY,NDER,IPRINT,
     1 MPRINT,NTR,ISQRT,NAUX,ISOUR,MAUX,MREG,MDIM,IPOL,MSCON,LOUT,
     2 IAMP,MTRNS,ICOEF,IAD,IRHO,ISHEAR,IAC,IRT,mori
      COMMON /ZERO/ RNULL
      DET=A(1,1)*(A(2,2)*A(3,3)-A(2,3)*A(3,2))-A(2,1)*(A(1,2)*A(3,3)
     1-A(3,2)*A(1,3))+A(3,1)*(A(1,2)*A(2,3)-A(2,2)*A(1,3))
      INULL=0
      IF(ABS(DET).GT.RNULL) GOTO 100
      DO 10 K=1,3
      DO 10 J=1,3
      IF(ABS(A(J,K)).GT.RNULL) INULL=1
      AINV(J,K)=0.0
   10 CONTINUE
      IF(INULL.EQ.0) THEN
      IF(IPRINT.GT.2)WRITE(LOUT,1000) A
 1000 FORMAT(' ALL ELEMENTS OF MATRIX ARE ZERO',/,3(3F12.6,/))
      ELSE
      IF(IPRINT.GT.2)WRITE(LOUT,1010)
 1010 FORMAT(' DETERMINANT OF MATRIX.EQ.0 !!!!!!!!!!!!!')
      END IF
  100 AINV(1,1)=(A(2,2)*A(3,3)-A(3,2)*A(2,3))
      AINV(2,1)=-(A(2,1)*A(3,3)-A(2,3)*A(3,1))
      AINV(3,1)=(A(2,1)*A(3,2)-A(2,2)*A(3,1))
      AINV(1,2)=-(A(1,2)*A(3,3)-A(1,3)*A(3,2))
      AINV(2,2)=(A(1,1)*A(3,3)-A(1,3)*A(3,1))
      AINV(3,2)=-(A(1,1)*A(3,2)-A(1,2)*A(3,1))
      AINV(1,3)=(A(1,2)*A(2,3)-A(1,3)*A(2,2))
      AINV(2,3)=-(A(1,1)*A(2,3)-A(1,3)*A(2,1))
      AINV(3,3)=(A(1,1)*A(2,2)-A(1,2)*A(2,1))
      IF(IPRINT.LE.2) GOTO 110
      WRITE(LOUT,1030)A,AINV
      WRITE(LOUT,1030) DET
      DO 30  K=1,3
      E1=0.0
      E2=0.0
      E3=0.0
      DO 20 J=1,3
      E1=E1+A(J,K)*AINV(1,J)
      E2=E2+A(J,K)*AINV(2,J)
      E3=E3+A(J,K)*AINV(3,J)
  20  CONTINUE
      WRITE(LOUT,1030)E1,E2,E3
 1030 FORMAT(/3(3F16.8/))
  30  CONTINUE
 110  RETURN
      END
