clearvars -except cmaps
clear global
close all

load('../indiv_proc/amp_struct_sedonly_dist.mat')
load('../indiv_proc/bin_struct_sedonly_dist.mat')

global_var

figure('Position',[0 0 1000 286])
tl=tiledlayout(1,2,'TileSpacing','compact');
%% read files
for its = 1:length(bintype)
   if its==2
      binmean = load('ext_funs/sbm_binmean.txt')*2*1e3;
      nkr=33;
      krdrop=14;
   elseif its==1
      binmean = load('ext_funs/tau_binmean.txt')*2*1e3;
      nkr=34;
      krdrop=15;
   end

   time=amp_struct.(bintype{its}).time;
   dt=time(2)-time(1);
   t1=int32(1/dt);
   t2=int32(60/dt);
   t3=int32(120/dt);
   
   bin_dist_t1=bin_struct.(bintype{its}).mass_dist(t1,1:nkr,104);
   amp_dist_t1=amp_struct.(bintype{its}).mass_dist_init(t1+1,1:nkr,104);
   
   bin_dist_t2=bin_struct.(bintype{its}).mass_dist(t2,1:nkr,104);
   amp_dist_t2=amp_struct.(bintype{its}).mass_dist_init(t2+1,1:nkr,104);
   
   bin_dist_t3=bin_struct.(bintype{its}).mass_dist(t3,1:nkr,104);
   amp_dist_t3=amp_struct.(bintype{its}).mass_dist_init(t3+1,1:nkr,104);
   
   nexttile
   hold on

   %shaded region
   xx=binmean(25:end-1)';
   yy1=amp_dist_t2(25:end-1);
   yy2=bin_dist_t2(25:end-1);
   pt=patch([xx fliplr(xx)], [yy1 fliplr(yy2)], [.8 .8 .8],'edgecolor','none');
   set(get(get(pt,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

   xx=binmean(25:end-1)';
   yy1=amp_dist_t3(25:end-1);
   yy2=bin_dist_t3(25:end-1);
   pt=patch([xx fliplr(xx)], [yy1 fliplr(yy2)], [.8 .8 .8],'edgecolor','none');
   set(get(get(pt,'Annotation'),'LegendInformation'),'IconDisplayStyle','off');

   plot(binmean,bin_dist_t1,'Color',color_order{its},'LineWidth',2)
   plot(binmean,bin_dist_t2,'Color',color_order{its},...
      'LineWidth',2,'LineStyle','--')
   plot(binmean,amp_dist_t2,'Color',color_order{5-its},...
      'LineWidth',2,'LineStyle','--')
   plot(binmean,bin_dist_t3,'Color',color_order{its},...
      'LineWidth',2,'LineStyle',':')
   plot(binmean,amp_dist_t3,'Color',color_order{5-its},...
      'LineWidth',2,'LineStyle',':')
   hold off

   title(['(',char(its+96),') ', upper(bintype{its})])
   lg=legend('t = 0 min','t = 1 min (bin)','t = 1 min (AMP)',...
             't = 2 min (bin)','t = 2 min (AMP)',...
             'Location','northeast','AutoUpdate','off');
   lg.FontWeight='bold';

   ylim([1e-10 1e-3])
   set(gca,'YScale','log')
   set(gca,'fontsize',16)
   grid

   xlabel(tl,'Diameter [mm]','fontsize',18)
   ylabel(tl,'Mass conc. [kg/kg/dlogD]','fontsize',18)
   set(gca,'fontsize',16)
end

exportgraphics(gcf,'plots/13 sedonly_dist.png','Resolution',300)
% exportgraphics(gcf,['plots/13 sedonly_dist.pdf'],'Resolution',300)
