%SIM
clear all; 
close all;

set(0,'DefaultFigureWindowStyle','docked');
warning('off','all');
warning;

ff = 'D:\2022\21_paper\near field\Near-field immersion array model\code\results\';

%%%%-----hole-------
fa = 'data_DC_TFM_hd_'; 
fb = 'data_DC_TFM_far_field_hd_';
num = 36;
% num1 = [2 8 25]; %% 
% num1 = [2 17 24]; %% 
num1 = 17;

sc_size = 0.25:0.25:10;
sc_ang = [0:15:90];
vL = 6320;
centre_freq = 5e6; 
lambdaL_solid = vL / centre_freq;

load ([ff 'ref_DC_TFM_far_field_crack_s2']);
rra = rr.rr1;
rram = 4 * lambdaL_solid * min(rra(:));
Fs = (2 * sc_size * lambdaL_solid) .^2 ./ rram;

load mesh_DC_near_field_01;

[mesh.x, mesh.z] = meshgrid(x_image, z_image);
dx = x_image(2) - x_image(1);
dz = z_image(2) - z_image(1);
da = dx * dz / lambdaL_solid / lambdaL_solid; 
scatterer.x = 0e-3; 
scatterer.z = 20e-3; 
threshold1 = -40; %% dB, profile
threshold2 = -6; %% dB, artefact
threshold3 = -40; %% dB, artefact

for ii = num1
% for ii = 1 : num
    tmpr = sc_size(ii) * lambdaL_solid;
    tmpx = x_image(find(abs(x_image) <= tmpr));
    tmpz = scatterer.z - sqrt(tmpr^2 - (tmpx - scatterer.x).^2);
    tmpz = round(tmpz ./ dz) .* dz;
    tmpzm = max(tmpz(:)) + 2e-3;
%     load([ff fa num2str(ii)]);
%     load([ff fb num2str(ii)]);
    
    load([fa num2str(ii)]);
    load([fb num2str(ii)]);
    
    tmpI10 = abs(data_TFM);
    tmpI20 = abs(data_TFM_far_field);
    
    tmpI1 = tmpI10;
    tmpI2 = tmpI20;
    [I1m(ii) ind10] = max(tmpI1(:));
    [I2m(ii) ind20] = max(tmpI2(:));

    tmpI1_db = 20 * log10(tmpI1 ./ I1m(ii));
    tmpI2_db = 20 * log10(tmpI2 ./ I2m(ii));

    
    if ~isempty(find(num1 == ii))
        figure;
        pcolor(mesh.x./lambdaL_solid,mesh.z./lambdaL_solid,tmpI1_db);colorbar;axis ij;shading interp;
        caxis([threshold3 0]);axis equal;colormap(1-gray);
%         text(-14,2,'Near-field model');
%         text(-11,10,'I^N^F');
        text(-8.5,7.7,'I^N^F');
%         hold on;plot(tmpx*1e3,tmpz*1e3,'r');
%         plot(x_image*1e3,z_image(ind1)*1e3,'g')
        
        figure;pcolor(mesh.x./lambdaL_solid,mesh.z./lambdaL_solid,tmpI2_db);colorbar;axis ij;shading interp;
        caxis([threshold3 0]);axis equal;colormap(1-gray);
%         text(-14,2,'Far-field model');
%         text(-9,2,'I^F^F');
%         text(-11,10,'I^F^F');
        text(-8.5,7.7,'I^F^F');       

    end
end

figure_options.powerpoint_figure.size_in_cm = [11,11];
figure_options.powerpoint_figure.fontname = 'Times New Roman';
figure_options.powerpoint_figure.fontsize_pts = 24;
figure_options.powerpoint_figure.linewidth_pts = 2;
figure_options.powerpoint_figure.axis_linewidth_pts = 2;
figure_options.powerpoint_figure.marker_size_pts = 10;

num_fig = [1:2];
refi = 200; %%% 0,
for ii = 1 : length(num_fig)
    figure(num_fig(ii));    
    axis equal;
    xlim([-15 15]);
    ylim([5 35]);
    box on;
    xlabel('x (mm)');
    ylabel('z (mm)');
    caxis([threshold3 0]);
    
%     xlim([-12 12]);
%     ylim([8 32]);
    
    xlim([-12 12]*1e-3./lambdaL_solid);
    ylim([8 32]*1e-3./lambdaL_solid);
    
    box on;
%     xlabel('x (mm)');
%     ylabel('z (mm)');
    
    xlabel('x (\lambda)','FontAngle','Italic');
    ylabel('z (\lambda)','FontAngle','Italic');
    
    fn_make_figure_for_presentation(gcf, figure_options);
%     saveas(gcf,['Itmp' num2str(ii+refi) '.jpg']);
end



