function ival = r8mat_is_sum_column ( m, n, a )

%*****************************************************************************80
%
%% R8MAT_IS_SUM_COLUMN checks whether an R8MAT has constant column 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 column sum constant.
%    1, the matrix is column sum constant.
%    2, the matrix is column sum constant with constant = 1 (transition).
%
  tol = 0.0001;

  a_norm = sum ( sum ( abs ( a(1:m,1:n) ) ) );

  ival = -1;

  col_sum(1:n) = sum ( a(1:m,1:n), 1 );

  cmax = max ( col_sum(1:n) );
  cmin = min ( col_sum(1:n) );
  cave = 0.5 * ( cmax + cmin );
  ctol = tol * ( 1.0 + a_norm / m );

  if ( abs ( cmax - cmin ) <= ctol )
    ival = 1;
    if ( abs ( cave - 1.0 ) <= ctol )
      ival = 2;
    end
  end

  return
end
