      SUBROUTINE MATOUT (MOD,IA,A,N,DIM)
C                                                     CREATION 02.02.87
C  OUTPUT MATRIX. CALCULATE SPUR, MINIMAL ELEMENT.NE.0,
C  ALSO PRINTOUT MATRIX (1 ELEMENT = 1 CHARACTER) WHEN MOD>0
C  UPDATE: LSPUR(06.03.87)
      IMPLICIT LOGICAL (A-Z)
      INTEGER MOD,IA,N,DIM
      REAL*8  A (DIM,DIM)
      INTEGER I,J,K,L,L1,L2,NN
      REAL*8  MIN, LSPUR, AA
      CHARACTER LINE*120

      MIN  = 9.99D66
      LSPUR= 0.0D0

      DO 1 I=1,N
        LSPUR = LSPUR + LOG ( A (I,I) )
        DO 1 J=1,N
          AA = ABS (A(I,J))
1         IF (AA.GT.0.0D0.AND.AA.LT.MIN)  MIN = AA
      WRITE (6,'(1X,A,I4,2D12.3,2X,8D9.2)')
     +  'IA, LOG(SPUR), MIN, A(J,J) = ',IA,LSPUR,MIN,
     +  (A(K,K),K=1,8)

      IF (MOD.LE.0) RETURN

      DO 2 NN=0, N/120
        L1 = 1 + NN*120
        L2 = L1 + 119
        IF (L2.GT.N) L2= N
        PRINT*,'            COLUMNS = ',L1,L2,'                 ',
     +         ' 3:= >1.0D0,  2:= >1.0D-15,  1:= >1.0D-30,  .:= ELSE'

        DO 3 I=1,DIM
          LINE = ' '
          DO 4 L=L1,L2
            J = L - NN*120
            AA = ABS (A(I,L))
            IF (AA.GT.1.0D0) THEN
              LINE (J:J) = '3'
            ELSEIF (AA.GT.1.0D-15) THEN
              LINE (J:J) = '2'
            ELSEIF (AA.GT.1.0D-30) THEN
              LINE (J:J) = '1'
            ELSE
              LINE (J:J) = '.'
            ENDIF
4         CONTINUE
          WRITE (6,'(1X,I5,2X,A)') I,LINE
3       CONTINUE

2     CONTINUE
      RETURN
      END
