% Plot topography SAR

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_bankup_cell2.mat'));
load(strcat(root_dir,'obs_bankdown_cell2.mat'));
load(strcat(root_dir,'obs_fp060_cell2.mat'));
load(strcat(root_dir,'obs_chdown_cell2.mat'));
load(strcat(root_dir,'obs_chup_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
        
    fp060_attenuation = obs_fp060_cell2{i,7};
    chdown_attenuation = obs_chdown_cell2{i,7};
    chup_attenuation = obs_chup_cell2{i,7};
    bankdown_attenuation = obs_bankdown_cell2{i,7};
    bankup_attenuation = obs_bankup_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),chdown_attenuation(1:max_dist_id,1),'--');
    p3=plot(xs_dist(1:max_dist_id),chup_attenuation(1:max_dist_id,1),'--');
    ax = gca;
    ax.ColorOrderIndex = 1;
    p4=plot(xs_dist,bankdown_attenuation(1:max_dist/250,1));
    p5=plot(xs_dist,bankup_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],'Baseline','CD','CU',...
%             'Location','southwest');
%         legend('boxoff');
    elseif i == 6
        ylim([0.89 1]);
        xlabel('Downstream distance (km)');
%         legend([p4 p5],'BD','BU',...
%             'Location','southwest');
%         legend('boxoff');
    end
    xlim([0 28]);
    set(gca,'Fontsize',14);
    
    BD_end(i,1) = bankdown_attenuation(max_dist/250,1);
    BU_end(i,1) = bankup_attenuation(max_dist/250,1);
    CD_end(i,1) = chdown_attenuation(max_dist/250,1);
    CU_end(i,1) = chup_attenuation(max_dist/250,1);
    Baseline_end(i,1) = fp060_attenuation(max_dist/250,1);

    percent_BD(i,1) = (BD_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_BU(i,1) = (BU_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_CD(i,1) = (CD_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    percent_CU(i,1) = (CU_end(i,1) - Baseline_end(i,1)) / ...
        (1 - Baseline_end(i,1));
    
end

max_topo_bank = max([max(percent_BD) max(percent_BU)]);
max_topo_ch = max([max(percent_CD) max(percent_CU)]);
min_topo_bank = min([min(percent_BD) min(percent_BU)]);
min_topo_ch = min([min(percent_CD) min(percent_CU)]);

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