function w = spqrZv(Z,v)

%        w = spqrZv(Z,v);
% takes an m-vector v and computes w = Z*v,
% where Z satisfies S'*Z = 0.
% If w = Z*v, we will have z = S'*w = 0.

% 02 Feb 2016: First working version of spqrZv.

[~,n] = size(Z.A);
r     = Z.info.rank_A_estimate;
if ~Z.trans
    b    = [sparse(r,1); v];
    w    = spqr_qmult(Z.Q,b,1);
else
    R1   = Z.R(1:r,1:r);
    R2   = Z.R(1:r,r+1:n);
    t    = R1\(R2*v);
    w    = [-t; v];
    w    = Z.P*w;
end
w    = Z.Rinv*w;