function ival = r8mat_is_m ( m, n, a )

%*****************************************************************************80
%
%% r8mat_is_m() checks whether an R8MAT is an M matrix.
%
%  Discussion:
%
%    An R8MAT is a matrix of real values.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 April 2017
%
%  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: the matrix is:
%    -1, not an M matrix because it is not square.
%    -2, not an M matrix because its offdiagonal is not nonpositive.
%    -3, not an M matrix because it is not invertible;
%    -4, not an M matrix because its inverse is not nonnegative.
%    1, an M matrix.
%
  ival = 1;

  if ( ~ r8mat_is_square ( m, n ) )
    ival = -1;
    return
  end

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

      if ( i == j )

      elseif ( 0.0 < a(i,j) )
        ival = -2;
        return
      end

    end
  end

  if ( rcond ( a ) == 0.0 )
    ival = -3;
    return
  end

  a2 = inv ( a );

  for i = 1 : n
    for j = 1 : n
      if ( a2(i,j) < 0.0 )
        ival = -4;
        return
      end
    end
  end

  return
end
