function [flight_plan,flights] = LEM_reserve_fp1(flights,airways,t1,t2,...
    speed,v1,v2,ht)
% LEM_reserve_fp - find flight plan, if possible
% On input:
%     flights (flight struct): flight reservation info
%     airways (airway struct): airway info
%     t1 (float): initial possible launch time
%     t2 (float): final possible launch time
%     speed (float): request vehicle's speed
%     v1 (int): launch vertex index
%     v2 (int): lan vertex index
%     ht (float): headway time
% On output:
%     flight_plan (nx4 array): flight plan
%       (i,:): [ti1, ti2, speed, lane_i]
%     flights (flight struct): flight reservation info
% Call:
%     [fp,flights] = LEM_reserve_fp(flights,airways1,1,30,5,12,15,5);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

flight_plan = [];

lanes = airways.lanes;
launch_vertexes = airways.launch_lane_vertexes;
land_vertexes = airways.land_lane_vertexes;

if isempty(find(launch_vertexes==v1))
    return
end
if isempty(find(land_vertexes==v2))
    return
end

path = LEM_get_path(airways,v1,v2,[]);
if isempty(path)
    return
end

%ht = 25;
len_path = length(path);
lane_lengths = zeros(len_path,1);
for c = 1:len_path
    lane_lengths(c) = norm(lanes(path(c),1:3)...
        -lanes(path(c),4:6));
end
possible0 = [t1,t2];

possible = LEM_LSD(possible0,speed,path,lane_lengths,...
    flights,ht);

if isempty(possible)
    return
end

t_start = possible;

flight_plan = zeros(len_path,4);
t1 = t_start(1);
for c = 1:len_path
    flight_plan(c,1) = t1;
    t2 = t1 + lane_lengths(c)/speed;
    flight_plan(c,2) = t2;
    flight_plan(c,3) = speed;
    flight_plan(c,4) = path(c);
    t1 = t2;
end

for c = 1:len_path
    flights(path(c)).flights = [flights(path(c)).flights;flight_plan(c,:)];
end

tch = 0;
