% Analyzes changes in area inundated for each flood wave

area_cell_root = ['/Users/Colin/Documents/MATLAB/DFlow/'...
    'attenuation_chap1/data/'];

%% Retrieve necessary data for historical contour (HC) model runs

fname_floods = 'historical_area_cell.mat';
fname_180cms = 'historical_180cms_area.mat';
fname_300cms = 'historical_300cms_area.mat';

floods_cell = importdata(strcat(area_cell_root,fname_floods));
area180cms = importdata(strcat(area_cell_root,fname_180cms));
area300cms = importdata(strcat(area_cell_root,fname_300cms));
    
for i = 1:6
    
    i_area = floods_cell{i,1};
    if mod(i,2) == 0
        peak_area = area300cms(1:72,2);
    elseif mod(i,2) == 1
        peak_area = area180cms(1:72,2);
    end
    floods_area = i_area(1:72,2);
    attenuated_area = floods_area(:,1) ./ peak_area(:,1);
    xs_num = size(i_area(1:72,2),1);
    xs_dist = (1:xs_num) * 0.25;
    
    f1 = figure(1);
    set(f1,'Color','White');
    sp(i) = {subplot(3,2,i)};
    plot(xs_dist, attenuated_area(:,1));
    
end

%% Retrieve necessary data for contemporary contour model runs

fname_floods = 'abq10a12bshc_area_cell.mat';
fname_180cms = 'abq10a12bshc_180cms_area.mat';
fname_300cms = 'abq10a12bshc_300cms_area.mat';

floods_cell = importdata(strcat(area_cell_root,fname_floods));
area180cms = importdata(strcat(area_cell_root,fname_180cms));
area300cms = importdata(strcat(area_cell_root,fname_300cms));
    
for i = 1:6
    
    i_area = floods_cell{i,1};
    if mod(i,2) == 0
        peak_area = area300cms(1:72,2);
    elseif mod(i,2) == 1
        peak_area = area180cms(1:72,2);
    end
    floods_area = i_area(1:72,2);
    attenuated_area = floods_area(:,1) ./ peak_area(:,1);
    xs_num = size(i_area(1:72,2),1);
    xs_dist = (1:xs_num) * 0.25;
    
    subplot(sp{i});
    hold on
    plot(xs_dist, attenuated_area(:,1),'--');
    
end

%% Retrieve necessary data for pre-restoration lidar model runs

fname_floods = 'abqpreblhc_area_cell.mat';
fname_180cms = 'abqpreblhc_180cms_area.mat';
fname_300cms = 'abqpreblhc_300cms_area.mat';

floods_cell = importdata(strcat(area_cell_root,fname_floods));
area180cms = importdata(strcat(area_cell_root,fname_180cms));
area300cms = importdata(strcat(area_cell_root,fname_300cms));
    
for i = 1:6
    
    i_area = floods_cell{i,1};
    if mod(i,2) == 0
        peak_area = area300cms(:,2);
    elseif mod(i,2) == 1
        peak_area = area180cms(:,2);
    end
    floods_area = i_area(:,2);
    attenuated_area = floods_area(:,1) ./ peak_area(:,1);
    xs_num = size(i_area(:,2),1);
    xs_dist = (1:xs_num) * 0.25;
    
    subplot(sp{i});
    hold on
    plot(xs_dist, attenuated_area(:,1),'-.');
    
end 

%% Retrieve necessary data for contemporary lidar model runs

fname_floods = 'abq10a12blhc_area_cell.mat';
fname_180cms = 'abq10a12blhc_180cms_area.mat';
fname_300cms = 'abq10a12blhc_300cms_area.mat';

floods_cell = importdata(strcat(area_cell_root,fname_floods));
area180cms = importdata(strcat(area_cell_root,fname_180cms));
area300cms = importdata(strcat(area_cell_root,fname_300cms));
    
for i = 1:6
    
    i_area = floods_cell{i,1};
    if mod(i,2) == 0
        peak_area = area300cms(:,2);
    elseif mod(i,2) == 1
        peak_area = area180cms(:,2);
    end
    floods_area = i_area(:,2);
    attenuated_area = floods_area(:,1) ./ peak_area(:,1);
    xs_num = size(i_area(:,2),1);
    xs_dist = (1:xs_num) * 0.25;
    
    subplot(sp{i});
    hold on
    plot(xs_dist, attenuated_area(:,1),':');
    
end   

%% Adjust plot attributes

for i = 1:6

    subplot(sp{i});
    hold on
    xlim([0 25]);
    if i == 3
        ylabel('Inundation Attenuation Ratio');
    elseif i == 5 
        xlabel('Distance downstream (km)');
    elseif i == 6
        xlabel('Distance downstream (km)');
        columnlegend(2,{'HC','CC','PL','CL'},'Location','SouthEast');
    end
    
    % Set y limits
    if mod(i,2) == 1
        ylim([0.25 1])
    elseif mod(i,2) == 0
        ylim([0.25 1])
    end
    xlim([0 27])
    set(gca,'FontSize',14);
    
end

