%
%   version 29.07.03
%
function z=cal_DPiDm(p,t,daefile,xfunction,t0,s_A,s_D,s_B,threshold,fid,level,rank_vec,argx,varargin);
global rank_ok;
%
%   calculation of xt := x(t) := x + (t-t0)*xp
%
xt=feval(xfunction,t,varargin{1:argx});
y=cal_dxtprime(daefile,xfunction,t,argx,varargin{:});
[Ui_tilde,diagSi,Sim,Faci,B0,A,D,Gi,Gim,Am,Dm,dim,m_i]=...
    chain_start(daefile,y,xt,t,s_A,s_D,s_B,threshold,fid,varargin{argx+1:end});
%
%   check of the rank 
%
if ~rank_vec(1)==dim
    rank_ok=0;
    z=sparse(size(y,1)*size(y,1),1);
    fprintf(fid,'\n%s\n',['cal_DPiDm: rank of G0 changed from ',...
               num2str(rank_vec(1)),' to ',num2str(dim)]);
    disp('Check the log-file !!!');
    return;
end;
%
%disp(' in cal DPiDm');
index=-1;
n=size(B0,1);
Pi=zeros(n,n,level);
Qi=zeros(n,n,level);
Wi=zeros(n,n,level);
[Pi(:,:,1),Qi(:,:,1)]=P_and_Q(Gi,Gim);
B0q=Ui_tilde'*B0*Faci;
dimp1=dim+1;
[Ui,Sigma,Vi] = svd(B0q(dimp1:n,dimp1:n));
[ri,next_sing_value]=rank_of_Sigma(Sigma,threshold,fid);
Si=Sigma(1:ri,1:ri);
bb=Faci(:,dimp1:n);
Zni=[];
DPi=D;
for k=1:(level-1)
   %
   %   check of the rank 
   %
       if ~rank_vec(k+1)==ri
           rank_ok=0;
           z=sparse(size(y,1)*size(y,1),1);
           fprintf(fid,'\n%s\n',['cal_DPiDm: rank changed on level ',num2str(k),' from ',...
               num2str(rank_vec(k+1)),' to ',num2str(ri)]);
           disp('Check the log-file !!!');
           return;
       end;
   %
   if k==1
       Bi=B0;
       prodPi=speye(n,n);
   else
       DPiDm=DPi*Dm;
       [Bi,ok_Bi]=Bi_calc(k,Bi,Gi,D,Dm,prodPi,Pi(:,:,k-1),DPiDm,daefile,xfunction,t,s_A,s_D,s_B,...
           threshold,fid,rank_vec,argx,varargin{:});
       prodPi=prodPi*Pi(:,:,k-1);
   end;
   BQi=Bi*Qi(:,:,k);
   Gi=Gi+BQi;
   Biq=Ui_tilde'*Bi*Faci;
   Fm=speye(n)-Gim*BQi;
   mS=m_i(:,1:dim)*diagSi;
   Faci=Fm*Faci;
   Faci=trans_mat_mult(Faci,mS);
   Faci=block_mult(Faci,Vi);
   % berechnung von mi
   Biq(dim+1:n,dim+1:n)=Ui'*Biq(dim+1:n,dim+1:n);
   Zni=[Zni,[Biq(:,dim+1:n)]];
   if ~ri==0
      diagSi=[diagSi,sparse(dim,ri);sparse(ri,dim),Si]; 
      Sim=[Sim,sparse(dim,ri);sparse(ri,dim),diag(1./diag(Si))];
   end;
   dim=dim+ri;
   %disp(['in cal_DPiDm: ',num2str(dim)]);
   wwi=Faci\bb;
   wwi22q=wwi(dim+1:n,:);
   [m_i,sing]=WZm(wwi22q,Zni,threshold);
   if sing
       fprintf(fid,'%s \n','pencil singular');
       disp('Check the log-file !!!');
       z=sparse(size(y,1)*size(y,1),1);
       rank_ok=0;
       return;
   end;
   bb=[bb,Faci(:,dim+1:n)];
   Ui_tilde=block_mult(Ui_tilde,Ui);
   Gim=Faci*[Sim,sparse(dim,n-dim);m_i]*Ui_tilde';
   [Pi(:,:,k+1),Qi(:,:,k+1)]=P_and_Q(Gi,Gim);
   DPi=DPi*Pi(:,:,k+1);
   if k==level-1
      DPiDm=DPi*Dm;
      z=DPiDm(:);
      break;
   else  
      B0q=Ui_tilde'*B0*Faci;
      [Ui,Sigma,Vi] = svd(B0q(dim+1:n,dim+1:n));
      % indextest
      [ri,next_sing_value]=rank_of_Sigma(Sigma,threshold,fid);
      Si=Sigma(1:ri,1:ri);
   end;
end;
%disp(' out cal DPiDm');