function ival = r8mat_is_sum_row ( m, n, a )

%*****************************************************************************80
%
%% R8MAT_IS_SUM_ROW checks whether an R8MAT has constant row sums.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    09 April 2017
%
%  Author:
%
%    John Burkardt
%
%  Parameters:
%
%    Input, integer M, N, the row and column dimensions of 
%    the matrix.  M and N must be positive.
%
%    Input, real A(M,N), the matrix.
%
%    Output, integer IVAL:
%    -1, the matrix is not row sum constant.
%    1, the matrix is row sum constant.
%    2, the matrix is row sum constant with constant = 1 (Markov/stochastic).
%
  tol = 0.0001;

  a_norm = sum ( sum ( abs ( a(1:m,1:n) ) ) );
%
%  Look at row sums.
%
  ival = -1;

  row_sum(1:m) = sum ( a(1:m,1:n), 2 );

  rmax = max ( row_sum(1:m) );
  rmin = min ( row_sum(1:m) );
  rave = 0.5 * ( rmax + rmin );
  rtol = tol * ( 1.0 + a_norm / n );

  if ( abs ( rmax - rmin ) <= rtol )
    ival = 1;
    if ( abs ( rave - 1.0 ) <= rtol )
      ival = 2;
    end
  end

  return
end
