************************************************************************
* File: matdecr.for
************************************************************************
* Scopo: soluzione esercizio 4 del compito di esame del 07/06/1999
************************************************************************

      LOGICAL FUNCTION MatDecr (mat,n)
      IMPLICIT NONE
      INTEGER n, mat(n,n)
      INTEGER somma/0/, somma2, i, j

      MatDecr = .TRUE.
      DO 10 i = 1, n
        somma = somma + mat(i,1)
 10   CONTINUE
      DO 20 j = 2, n
        somma2 = 0
        DO 30 i = 1, n
          somma2 = somma2 + mat(i,j)
 30     CONTINUE
        IF (somma2 .GE. somma) THEN
          MatDecr = .FALSE.
        ELSE
          somma = somma2
        ENDIF
 20   CONTINUE
      RETURN
      END

* TEST (PARTE NON RICHIESTA DAL TESTO)
      PROGRAM Main
      IMPLICIT NONE
      INTEGER DIM
      PARAMETER (DIM = 3)
      INTEGER matrice(DIM,DIM)
      LOGICAL MatDecr

      matrice(1,1) = 1
      matrice(2,1) = 1
      matrice(3,1) = 1

      matrice(1,2) = 0
      matrice(2,2) = 1
      matrice(3,2) = 1

      matrice(1,3) = 1
*     matrice(1,3) = 0
      matrice(2,3) = 0
      matrice(3,3) = 1
      
      IF (MatDecr(matrice,DIM)) THEN
        WRITE(*,*) 'VERIFICA LA PROPRIETA'''
      ELSE
        WRITE(*,*) 'NON VERIFICA LA PROPRIETA'''
      ENDIF

      STOP
      END
