function [alpha, info] = rpsa(A, epsln, opts)
% RPSA: Criss-cross type method for computing the real pseudospectral 
%       abscissa of small to medium sized matrices.
%
%   alpha = rpsa(A, epsln) returns the real pseudospectral abscissa alpha 
%       of a real square matrix A with perturbation level epsln.
%
%   [alpha, info] = rpsa(A, epsln) also returns an info structure
%       - info.succ:    false if there was an error during the iteration.
%       - info.its      total number of iterations (horizontal search).
%       - info.z        a vector of complex numbers 
%                               z_i = alpha_i + beta_i (1<=i<=its+1) 
%                       that are the approximate rightmost points in the
%                       criss-cross algorithm.
%                       Here i is the number of the horizontal search.
%       - info.message  contains the stopping message.
%
%   [alpha, info] = rpsa(A, epsln, opts) allows specification of the 
%       parameters opts:
%       - opts.maxit (60)       maximum iterations.
%       - opts.tol (1.0E-8)     stopping (relative) increment tolerance.
%       - opts.ctol (1.0E-2)    global verification tolerance.
%       - opts.dodisp (false)   display computation history, if dodisp==true. 
%       - opts.histp (false)    use history points to divid interval.
%       
%
%   References: 
%       [1] Ding Lu and Bart Vandereycken, Criss-cross type algorithms 
%           for computing the real pseudospectral abscissa,
%           manuscript available at http://www.unige.ch/math/vandereycken.
%
%   Authors:
%       Ding Lu and Bart Vandereycken, University of Geneva.
%
%   Version:
%       0.1, Jun. 13, 2016.

if nargin < 3, opts = []; end

if ~isreal(A) || size(A,1)~=size(A,2) 
    alpha = NaN;
    info.succ = false;
    info.message = ' Input matrix A must be a real square matrix! ';
    return;
end

% RUN CRISS-CROSS SEARCH
B = eye(size(A));
[alpha, ~, ~, info0] = rpsa_pencil(A, B, epsln, opts);
hstr = info0.hstr;

% RETURN INFO STRUCTURE
info.succ = info0.succ;
info.its = info0.its;
info.z = hstr(:,1) + 1i * hstr(:,2);
info.message = info0.message; 

% END
return
