itload('../merger_debug.it');

ndat = 1000; % check if true!

XL = [-1 4];
YL= XL;

figure(1);
for it=0:20
    figure(it+1)
    subplot(2,2,1);
    si = num2str(it);
    eval(['contour_2(Smp' si '(1,:),Smp' si '(2,:),exp(Mpdf' si '))']);
    title('Proposal density ');
    set(gca,'XLim',XL);
    set(gca,'YLim',YL);
        
    subplot(2,2,2);
    eval(['contour_2(Smp' si '(1,:),Smp' si '(2,:),exp(lW' si '(1,:)))']);
    title('First source'); 
    set(gca,'XLim',XL);
    set(gca,'YLim',YL);
    
    subplot(2,2,3);
    eval(['contour_2(Smp' si '(1,:),Smp' si '(2,:),exp(lW' si '(2,:)))']);
    title('Second source');
    set(gca,'XLim',XL);
    set(gca,'YLim',YL);
    
    
    subplot(2,2,4);
    eval(['contour_2(Smp' si '(1,:),Smp' si '(2,:),w' si ')']);
    title('Merged density'); 
    set(gca,'XLim',XL);
    set(gca,'YLim',YL);
    
end

   
itload('../merger_iter_test.it');
XG = reshape(Grid(1,:),Npoints,Npoints);
YG = reshape(Grid(2,:),Npoints,Npoints);

figure(it+2);
M1 = reshape(exp(Res1),Npoints,Npoints);
contour(XG,YG,M1,7);

figure(it+3);
hold off
mm = max(max(Res2));
for i=1:size(Res2,1)
    M2 = reshape(Res2(i,:),Npoints,Npoints);
    contour(XG,YG,M2,[0:mm/7:mm]);
    hold on
end
