function [result,remainder,fin_no_it] = deconExecute_BbpP(Par, kern_ord, z, f, fker, noise,lev,sc,no_iter,conv_heat,num_blocks,tre)
%Block Pursuit processing
% Par --spline order 
%kern_ord-- order of the spline interpolating the blurring kernel. 
%For heat eq. kern_ord=0, for deconv. typically kern_ord=2
%z-- blurred noised input
%f-- original (used for monitorng the restoration process, not participates
% in processing)
%fker--DFT of the blurring kernel
%noise--modelled noise
%lev -- decomposition depth
%sc-- scaling of the regularization parameter
%no_iter --maximal number of iterations
%conv_heat=1--deconv.;conv_heat=2--heat inversion with difference appr.;
%conv_heat=3--inversion with collocation appr.;
%num_blocks--number of the involved Best Basis blocks 
%tre --threshold for stopping rule
%result -- result of processing
%fin_no_it final number of iterations
%remainder --remainder of  data after stopping the pursuit
[N,hz]=size(z);
%calculation of SHA spectra of wavelet packets
[Depth,w_coef ]=wavs_coefP(Par,N);
w_coef=w_coef(2:end,:);

levels=min(lev,Depth);
result = zeros(N, N);

count = no_iter;
sb=[0 0 0];
SB=[];


 fNoise = fft2(noise);
%auxiliary coefficients
 [W,T,V]=weteviP(Par, kern_ord,N,conv_heat,hz); 
for kk = 1 : count
%Wavelet packet transform of the input
[~, ~, entro,ener]=spl_WP_anaP2D(z,Par,levels);
ListBB=WP_BB_Listree2D_P(entro,ener);


clear wvtran wctran 

s=1:num_blocks;
lis=sort_list_P(ListBB,fker,w_coef);
lis=lis(s,:);
en=lis(:,4);
%Discard of insignificant blocks
fen=find(en>tre);
lfen=length(fen);
if lfen ==0
        break
else
     fZ = fft2(z);
    bb_result = zeros(N, N);
     bb_rem = zeros(N, N);
        for mm=1:lfen
%  
maxPos = lis(mm,1:3);
    
[ sp_f, sp_g, ~, a] = onePacketDecon_PN(maxPos,   fker, w_coef, fZ, fNoise,sc,W,T,V);
 
    
    bb_result = bb_result + sp_f;  
    bb_rem =bb_rem +sp_g;
   
    
    sub_b = maxPos;  
    %SB=[SB;sb];
   SB=[SB;sub_b];
        end
    result = result+bb_result;    
    %SB
    
   [PSNR, mablod]=psnB(f, result); 
    ttl = ['intermediate result, step  ' int2str(kk)  ', PSNR= ' num2str(PSNR) ]
    z = z - bb_rem;    

    end
 end
fin_no_it=kk;
remainder=z;
SB
end
% Copyright (c) 2013. Valery A. Zheludev 