function [ ival, jval ] = r8mat_is_triangular ( m, n, a )

%*****************************************************************************80
%
%% r8mat_is_triangular() determines whether an R8MAT is triangular.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 November 2007
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer M, N, the row and column dimensions of 
%    the matrix.  M and N must be positive.
%
%    real A(M,N), the matrix.
%
%  Output:
%
%    integer IVAL:
%    -1, the matrix is not upper triangular
%    1, the matrix is upper triangular.
%    2, the matrix is unit upper triangular.
%
%    integer JVAL:
%    -1, the matrix is not lower triangular.
%    1, the matrix is lower triangular.
%    2, the matrix is unit lower triangular.
%
  ival = 2;
  jval = 2;

  for i = 1 : m
    for j = 1 : n

      if ( i == j )
        if ( a(i,j) ~= 1.0 )
          if ( ival == 2 )
            ival = 1;
          end
          if ( jval == 2 )
            jval = 1;
          end
        end
      elseif ( i < j )
        if ( a(i,j) ~= 0.0 )
          jval = -1;
        end
      elseif ( j < i )
        if ( a(i,j) ~= 0.0 )
          ival = -1;
        end
      end

      if ( ival == -1 & jval == -1 )
        return
      end

    end
  end

  return
end
