%% plot the simulation data in a figure similar to figure 3 of the manuscript

figure(3);
close(3)
fig3=figure(3);
set(fig3,'Units','centimeters');
set(fig3,'Position',[10,5,14.3,13.8])
c_map=morgenstemning(256);

Yindex = 383;
Zindex1 = 555; 
Zindex2 = 655;
zlims = [0.25,0.65]; %flipped
xlims_bscan = [0,0.225]; 
xlims_enface1 = [0.1,0.20]; 
ylims_enface1 = [0.1,0.20]; 
xlims_enface2 = [0.1,0.20]; 
ylims_enface2 = [0.1,0.20]; 


scalebar_length = 50e-3;
methods = {'DFT','RFIAA','DFT + ISAM','MIAA + ISAM'};
for i=1:4
    image = images{i};
    subplot(3,4,i)
    imagesc(Xroi,Zroi,squeeze(image(:,:,Yindex)))
    caxis([-80,0])
    colormap(c_map)
    axis equal tight
    ylim(zlims)
    xlim(xlims_bscan)
    hold on
    plot(xlims_enface1,[1,1]*z_isam(Zindex1),'-b','LineWidth',1.5)
    plot(xlims_enface2,[1,1]*z_isam(Zindex2),'-r','LineWidth',1.5)
    plot(xlims_bscan(1)+(xlims_bscan(2)-xlims_bscan(1))/20+[0,scalebar_length],(zlims(2)-(zlims(2)-zlims(1))/40)*[1,1],'-w','LineWidth',3)
    if i==1
        text(xlims_bscan(1)+(xlims_bscan(2)-xlims_bscan(1))/20+scalebar_length/2,(zlims(2)-3*(zlims(2)-zlims(1))/40),string(round(scalebar_length*1e3))+' '+char(181)+'m','Color','w','HorizontalAlignment','Center')
    end
    title(methods{i})
    
    subplot(3,4,4+i)
    imagesc(Xroi,Xroi,squeeze(image(Zindex1,:,:)))
    caxis([-80,0])
    axis equal tight
    xlim(xlims_enface1)
    ylim(ylims_enface1)
    hold on
    plot(xlims_enface1(1)+(xlims_enface1(2)-xlims_enface1(1))/20+[0,scalebar_length],(ylims_enface1(2)-(ylims_enface1(2)-ylims_enface1(1))/20)*[1,1],'-w','LineWidth',3)
    
    subplot(3,4,8+i)
    imagesc(Xroi,Xroi,squeeze(image(Zindex2,:,:)))
    caxis([-90,0])
    axis equal tight
    xlim(xlims_enface2)
    ylim(ylims_enface2)
    hold on
    plot(xlims_enface2(1)+(xlims_enface2(2)-xlims_enface2(1))/20+[0,scalebar_length],(ylims_enface2(2)-(ylims_enface2(2)-ylims_enface2(1))/20)*[1,1],'-w','LineWidth',3)
    
end
%
figratio = fig3.Position(3)/fig3.Position(4);
ratio_Bscan = (xlims_bscan(2)-xlims_bscan(1))/(zlims(2)-zlims(1))*figratio;
ratio_enface1 = (xlims_enface1(2)-xlims_enface1(1))/(ylims_enface1(2)-ylims_enface1(1))*figratio;
ratio_enface2 = (xlims_enface2(2)-xlims_enface2(1))/(ylims_enface2(2)-ylims_enface2(1))*figratio;

fig.xpos = (0:3)*0.25+0.005;
fig.ypos = [0.52,0.265,0.01];
fig.width = 0.235;

fig.ratio = [0,0,0];
fig.ratio(1) = (xlims_bscan(2)-xlims_bscan(1))/(zlims(2)-zlims(1))/figratio;
fig.ratio(2) = (xlims_enface1(2)-xlims_enface1(1))/(ylims_enface1(2)-ylims_enface1(1))/figratio;
fig.ratio(3) = (xlims_enface2(2)-xlims_enface2(1))/(ylims_enface2(2)-ylims_enface2(1))/figratio;

pos = zeros(4,1);
%
for i=1:4
    for j=1:3
        pos(1) = fig.xpos(i);
        pos(2) = fig.ypos(j);
        pos(3) = fig.width;
        pos(4) = fig.width/fig.ratio(j);
        fig3.Children(13-(3*(i-1)+j)).Position=pos;
    end
    fig3.Children(13-3*i).YAxis.LineWidth = 1.5;
    fig3.Children(13-3*i).XAxis.LineWidth = 1.5;
    fig3.Children(13-3*i).YColor = 'r';
    fig3.Children(13-3*i).XColor = 'r';
    fig3.Children(13-(3*(i-1)+2)).YAxis.LineWidth = 1.5;
    fig3.Children(13-(3*(i-1)+2)).XAxis.LineWidth = 1.5;
    fig3.Children(13-(3*(i-1)+2)).YColor = 'b';
    fig3.Children(13-(3*(i-1)+2)).XColor = 'b';
%   
%     fig3.Children(13-(3*(i-1)+1)).Title.Position(1) = xlims_bscan(2);
end

for i=1:12
    fig3.Children(i).XTick = [];
    fig3.Children(i).YTick = [];
end
%%
labels = 'abcdefghijklmnop';
fig.a = [];
for i=1:4
    for j=1:3
        pos(1) = fig.xpos(i)-0.008;
        pos(2) = fig.ypos(j)+fig.width/fig.ratio(j)+0.008;
        pos(3) = 0;%fig.width;
        pos(4) = 0;%fig.width/fig.ratio(j);
        fig.a(3*(i-1)+j) = annotation('textbox','string', ['(',labels(4*(j-1)+i),')'],'FontWeight','bold','color','w','Position',pos','EdgeColor','none');
    end
end



%%
return
fig.name = 'fig_simulation_pointscatterers.pdf';
fig.pos = get(fig3,'Position');
set(fig3,'PaperPositionMode','Auto','PaperUnits','centimeters','PaperSize',[fig.pos(3), fig.pos(4)])
print(fig3, '-dpdf', fig.name);
print(fig3, '-dpng','-r500', [fig.name(1:end-4),'.png']);