function [min_dist,min_f] = UTM_last_in_lane(flights,lane_number)
% UTM_last_in_lane - get info on immediately preceding flight in lane
% On input:
%     flights (flight struct): flight info
%     lane_number (int): lane index
% On output:
%     min_dist (float): distance along lane
%     min_f (int): flight index
% Call:
%     [md,mf] = UTM_last_in_lane(flights,3);
% Author:
%     T. Henderson
%     UU
%     Summer 2020
%

WAITING = 1;
IN_FLIGHT = 0;
DONE = -1;

min_dist = Inf;
min_f = 0;
num_flights = length(flights);

for f = 1:num_flights
    if flights(f).status==IN_FLIGHT
        traj = flights(f).traj;
        f_lane_index = flights(f).lane_index;
        f_lane_number = traj(f_lane_index);
        if lane_number==f_lane_number
            dist = flights(f).lane_dists(f_lane_index);
            if dist<min_dist
                 min_dist = dist;
                 min_f = f;
            end
        end
    end
end
