function b = UR_error(flights)
% UR_error - checks if any flights through a corridor are too close
% On input:
%     flights (vector struct): flight info for each lane
%       (k).flights (nx2 array): n start and end times for flights
% On output:
%     b (Boolean): true if flights too close; else 0
% Call:
%     b = UR_error(g_flights);
% Author:
%     T. Henderson
%     UU
%     Summer 2019
%

global g_ht

b = 0;

num_cors = length(flights);

for c = 1:num_cors
    c_flights = flights(c).flights;
    if ~isempty(c_flights)
        num_flights = length(c_flights(:,1));
        for f1 = 1:num_flights-1
            d1 = c_flights(f1,1:2);
            for f2 = f1+1:num_flights
                d2 = c_flights(f2,1:2);
                if abs(d1(1)-d2(1))<(g_ht)|abs(d1(2)-d2(2))<(g_ht)...
                        |(d1(1)<d2(1)&d1(2)>d2(2))
                    b = 1;
                    return
                end
            end
        end
    end
end
