function ival = r8mat_is_diagonally_dominant ( n, a )

%*****************************************************************************80
%
%% r8mat_is_diagonally_dominant() checks whether A is a diagonally dominant matrix.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    08 April 2017
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N, the row and column dimensions of 
%    the matrix.  N must be positive.
%
%    real A(N,N), the matrix.
%
%  Output:
%
%    integer IVAL:
%    -1, the matrix is not diagonally dominant.
%    1, the matrix is diagonally dominant.
%    2, the matrix is strictly diagonally dominant.
%
  ival = 2;

  for k = 1 : n

    s = abs ( a(k,k) );
    sumj = 0.0;
    for j = 1 : n
      if ( j ~= k )
        sumj = sumj + abs ( a(k,j) );
      end
    end

    sumi = 0.0;
    for i = 1 : n
      if ( i ~= k )
        sumi = sumi + abs ( a(i,k) );
      end
    end

    if ( s < sumi || s < sumj )
      ival = -1;
      return
    elseif ( s == sumi || s == sumj )
      ival = 1;
    end

  end

  return
end
