% Calculates flood wave speed (km/hr) assuming his_extract for chapter 1
% has been run

for i = 1:6

    l2010_time_dist = xs_2010lidar_cell{i,5};
    
    l2010_idtd_km = l2010_time_dist(mod(l2010_time_dist(:,1),4) == 0,:);
    
    [km,~] = size(l2010_idtd_km);
    if i == 1
        l2010_awv = zeros(24,6);
        error_check = zeros(km,6);
    end    
    
    for j = 2:km
        if l2010_idtd_km(j,2) <= l2010_idtd_km(j-1,2)
            error_check(j,i) = 1;
        end
    end
    
    l2010_dist = l2010_idtd_km(2:end,1)/4;

    for k = 2:km
        l2010_awv(k-1,i) = 1 /...
            ((l2010_idtd_km(k,2) - l2010_idtd_km(k-1,2))/3600);
    end
    
end

for i = 1:6
    plot(l2010_dist,l2010_awv(:,i));
    if i == 1
        hold on
    end
    xlabel('Distance downstream (km)')
    ylabel('Absolute wave velocity (km/hr)')
end