function ival = r8mat_is_toeplitz ( m, n, a )

%*****************************************************************************80
%
%% R8MAT_IS_TOEPLITZ checks if an R8MAT is a Toeplitz matrix.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%    A Toeplitz matrix is constant along each diagonal.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    04 November 2007
%
%  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 Toeplitz.
%    1, the matrix is Toeplitz.
%
  ival = 1;

  for i = 1 : m
    test = a(i,1);
    khi = min ( m - i, n - 1 );
    for k = 1 : khi
      if ( a(i+k,1+k) ~= test )
        ival = -1;
        return
      end
    end
  end

  for j = 2 : n
    test = a(1,j);
    khi = min ( m - 1, n - j );
    for k = 1 : khi
      if ( a(1+k,j+k) ~= test )
        ival = -1;
        return
      end
    end
  end

  return
end

