  function  output=MSFprecondfun(mode,m,tn,dxy,Qy,diagprec)
% function  output=MSFprecondfun(mode,m,tn,dxy,Qy,diagprec)
% oldfunction  output=MSFprecondfun(mode,m,tn,dxy,precond,dataxy)
%  INPUT:
%   dxy = [dx;dy] contains the vector to be multiplied in CG method
%   precond    was indicator for no/type of preconditioning
%   Qy         diag(y)-Q    sparse
%   diagprec = [x;y] contains the data X,y for the current iteration
%                  along with the preconditioner
%   
%global Xu Q q2kron indsu ;
global Xu indsu;

n=size(Xu,2);
n2=n^2;
tnm1=(n*(n-1)/2);
%  update Xu and Qy in solvss 

                   % do diagonal precond 
 if mode==2,
    dXy=reshape(dxy,n,n);
    %output=[zops(Qy,dXy,n)
    %       xops(dXy,n)];
    ZW=(Qy/sqrt(2))*dXy;
    ZWp=ZW';
    output=[ZW(indsu)+ZWp(indsu)
            sum((Xu.*dXy),2) + dXy(1:n+1:end)' ];
    output=output./diagprec;
 else
   dxy=dxy./diagprec;
   output=zop(Qy,dxy(1:tnm1),n)+xop(dxy(tnm1+1:end),n);
 end
