function [PHI1,Pi11,Pi21]=qz2phipi(s,t,q,z,F1,F2,C,rot);

if nargin==8
    if ~isempty(rot)
    [s,t,q,z]=ordqz(s,t,q,z,rot);
    end
end
prede=size(s,1)/2;

s11=s(1:prede,1:prede);
s12=s(1:prede,prede+1:end);
s22=s(prede+1:end,prede+1:end);

t11=t(1:prede,1:prede);
t12=t(1:prede,prede+1:end);
t22=t(prede+1:end,prede+1:end);

zt=z';


zt11=zt(1:prede,1:prede);
zt12=zt(1:prede,prede+1:end);
zt21=zt(prede+1:end,1:prede);
zt22=zt(prede+1:end,prede+1:end);

z11=z(1:prede,1:prede);
% z12=z(1:prede,prede+1:end);
% z21=z(prede+1:end,1:prede);
% z22=z(prede+1:end,prede+1:end);

% Chat=q'*C;

%%%%%%%%%%%%%%%%
% CHECK OUT THE SIGN
Pi21=real(-zt22\zt21);
Pi11=real(z11*(s11\t11)/z11);

% %%%%%%%%%%%%%%%%%%%%%%%%%

A1_12=F1(:,end:-1:1);
A2_12=F2(:,end:-1:1);

G1=kron_d_f(N',A1_12)+kron_d_f(eye(nsh),A1_12*Pi21)+kron_d_f(eye(nsh),A2_12);
G2=vec(C(1:prede,:));
PHI1=-reshape(G1\G2,neq,nsh);
 PHI2=PHI1;
