% Plot Roughness QAR

clear

max_dist = 27000;
min_t = 7200; % plots start at 2 hour
max_t = 96 * 3600; % hours * seconds in an hour - gives seconds
peak_index = [180; 300; 180; 300; 180; 300];
max_xs_num = max_dist/250;

%% Load relevant files
root_dir =...
    '/Users/Colin/Documents/MATLAB/DFlow/influences_chap2/SAR_cells/';
load(strcat(root_dir,'obs_bank040_cell2.mat'));
load(strcat(root_dir,'obs_bank080_cell2.mat'));
load(strcat(root_dir,'obs_bank100_cell2.mat'));
load(strcat(root_dir,'obs_fp040_cell2.mat'));
load(strcat(root_dir,'obs_fp060_cell2.mat'));
load(strcat(root_dir,'obs_fp080_cell2.mat'));
load(strcat(root_dir,'obs_fp100_cell2.mat'));


%% Plot attenuation ratio
h = figure(1);
h.Units = 'inches';
%h.Position = [1 1 11 15];
h.PaperSize = [8.5 11];
set(gcf,'color','white');
xs_dist = (250:250:max_dist)/1000;
for i = 1:6
    
    fp040_attenuation = obs_fp040_cell2{i,7};    
    fp060_attenuation = obs_fp060_cell2{i,7};
    fp080_attenuation = obs_fp080_cell2{i,7};
    fp100_attenuation = obs_fp100_cell2{i,7};
    bank040_attenuation = obs_bank040_cell2{i,7};    
    bank080_attenuation = obs_bank080_cell2{i,7};
    bank100_attenuation = obs_bank100_cell2{i,7};
    
    max_dist_id = max_dist/250;
    
    subplot(3,2,i);
    p1=...
        plot(xs_dist(1:max_dist_id),fp060_attenuation(1:max_dist_id,1),'k-');
    hold on
    p2=...
        plot(xs_dist(1:max_dist_id),fp040_attenuation(1:max_dist_id,1),'--');
    p3=...
        plot(xs_dist(1:max_dist_id),fp080_attenuation(1:max_dist_id,1),'--');
    p4=...
        plot(xs_dist(1:max_dist_id),fp100_attenuation(1:max_dist_id,1),'--');
    ax = gca;
    ax.ColorOrderIndex = 1;
    p5=plot(xs_dist,bank040_attenuation(1:max_dist/250,1));
    p6=plot(xs_dist,bank080_attenuation(1:max_dist/250,1));
    p7=plot(xs_dist,bank100_attenuation(1:max_dist/250,1));
    if i == 1
        ylim([0.89 1]);
    elseif i == 2
        ylim([0.89 1]);
    elseif i == 3
        ylim([0.89 1]);
        ylabel('Stage Attenuation Ratio');
    elseif i == 4
        ylim([0.89 1]);
    elseif i == 5 
        ylim([0.89 1]);
        xlabel('Downstream distance (km)');
%         legend([p1 p2 p3 p4],'Baseline','F04','F08','F10',...
%             'Location','southwest');
%         legend('boxoff');
    elseif i == 6
        ylim([0.89 1]);
        xlabel('Downstream distance (km)');
%         legend([p5 p6 p7], 'B04','B08','B10',...
%             'Location','southwest');
%         legend('boxoff');
    end
    xlim([0 28]);
    set(gca,'Fontsize',14);
    
    B04_end(i,1) = bank040_attenuation(max_dist/250,1);
    B08_end(i,1) = bank080_attenuation(max_dist/250,1);
    B10_end(i,1) = bank100_attenuation(max_dist/250,1);
    F04_end(i,1) = fp040_attenuation(max_dist/250,1);
    F08_end(i,1) = fp080_attenuation(max_dist/250,1);
    F10_end(i,1) = fp100_attenuation(max_dist/250,1);
    Baseline_end(i,1) = fp060_attenuation(max_dist/250,1);

    percent_B04(i,1) = (B04_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_B08(i,1) = (B08_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_B10(i,1) = (B10_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_F04(i,1) = (F04_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_F08(i,1) = (F08_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_F10(i,1) = (F10_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    
end

max_topo_bank = max([max(percent_B04) max(percent_B08) max(percent_B10)]);
max_topo_fp = max([max(percent_F04) max(percent_F08) max(percent_F10)]);
min_topo_bank = min([min(percent_B04) min(percent_B08) min(percent_B10)]);
min_topo_fp = min([min(percent_F04) min(percent_F08) min(percent_F10)]);

% print('-bestfit',['/Users/Colin/Documents/MATLAB/DFlow/'...
%     'influences_chap2/figures/SARroughness8_5x11'],'-dpdf');