function ival = r8mat_is_spd ( m, n, a )

%*****************************************************************************80
%
%% r8mat_is_spd() checks for if an R8MAT is symmetric positive definite.
%
%  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 square.
%    -2, the matrix is not symmetric.
%    -3, the matrix is symmetric, but not positive definite.
%    0, the matrix is symmetric positive semi-definite.
%    1, the matrix is symmetric positive definite.
%
  if ( ~ r8mat_is_square ( m, n, a ) )
    ival = -1;
    return
  end

  for i = 1 : n
    for j = 1 : i - 1
      if ( a(i,j) ~= a(j,i) )
        ival = -2;
        return
      end
    end
  end

  [ c, ierror ] = r8mat_cholesky_factor ( n, a );

  if ( ierror == 2 )
    ival = -3;
  elseif ( ierror == 1 )
    ival = 0;
  else
    ival = 1;
  end

  return
end
