% visulation of Fig 5
clear
clc

% data list
num_list = [760 840 940];
% profile list
prof_list = [115 143]; % mamgatic section, amagmatic section

% loop
for i = 1:length(num_list)
    for j = 1:length(prof_list)
        
        number = num_list(i);
        prof_num = prof_list(j);
        dataname = ['nwn00' num2str(number) '_z' num2str(prof_num) 'km.mat'];
        
        % load data
        load(dataname);
        
        % strain rate
        figure(1);clf;colormap(GyRd);
        pcolor(gx/1000,gy/1000,log10(profile_eii));caxis([-17 -12]);
        shading interp; axis ij image; colorbar;
        title(['Strain rate: ','refer - ', num2str(num_file),' - z = ', num2str(slicez),' km','  ',num2str(evoTime/1e6,'%5.2f\n') ' Myr']);
        hold on
        plot(gx_r/1000,surface_comp/1000,'Color','k','LineStyle','-.','LineWidth',1.5) % seafloor
        plot(gx_r/1000,depth_plastic/1000,'Color','c','LineStyle','-.','LineWidth',1.5) % brittle-ductile transition
        plot(gx_r/1000,depth_melt/1000,'Color','m','LineStyle','-.','LineWidth',1.5) % melt_dpeth
        hold off
        xlabel('ridge (km)')
        ylabel('deepth (km)')
        xlim([40 160])
        ylim([0 50])

        % grain size
        figure(2);clf;
        newmap = cmapnorm(bwr,log10(1e-5), log10(6e-3), log10(3e-3));
        newmap(1,:) = [0.6 0.6 0.6];
        pcolor(gx/1000,gy/1000,log10(profile_rg));caxis([log10(1e-5), log10(6e-3)]);
        shading interp; axis ij image; colorbar;colormap(newmap);
        title(['Grain size: ','refer - ', num2str(num_file),' - z = ', num2str(slicez),' km','  ',num2str(evoTime/1e6,'%5.2f\n') ' Myr']);
        hold on
        plot(gx_r/1000,surface_comp/1000,'Color','k','LineStyle','-.','LineWidth',1.5) % seafloor
        plot(gx_r/1000,depth_plastic/1000,'Color','c','LineStyle','-.','LineWidth',1.5) % brittle-ductile transition
        plot(gx_r/1000,depth_melt/1000,'Color','m','LineStyle','-.','LineWidth',1.5) % melt_dpeth
        hold off
        xlabel('ridge (km)')
        ylabel('deepth (km)')
        xlim([40 160])
        ylim([0 50])

        
        pause(1.0);
    end
end