function [cells,requestsc] = LEM_requests_LBSD2cells(requests,...
    airways,min_alt,max_alt,del_x,del_y,hd)
% LEM_gen_requests_LBSD2cells - convert LBSD requests to cells requests
% On input:
%     requests (requests struct): LBSD requests
%     airways (airways struct): airways info
%     min_alt (float): minimum altitude for flight
%     max_alt (float): max altitude for flight
%     del_x (float): step in x for cells
%     del_y (float): step in y for cells
%     hd (float): headway distance
% On output:
%     cells (cells struct): cells info
%     requests (requests struct): request info
%      (k).request_time (float): time request is submitted
%      (k).launch_interval (1x2 vector): [earliest time, latest time]
%      (k).speed (float): desired average speed (uniform from speeds)
%      (k).path (nx6 array): endpts of flight path line segments
%      (k).launch_index (int): index in airways.launch_lane_vertexes
%      (k).land_index (int): index in airways.land_lane_vertexes
% Call:
%     [cells1,reqs1] = LEM_requests_LBSD2cells(requests,467,534,10,10,0.1);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

% create cells struct
x_min = min(airways.vertexes(:,1));
x_max = max(airways.vertexes(:,1));
y_min = min(airways.vertexes(:,2));
y_max = max(airways.vertexes(:,2));
launch_sites = airways.vertexes(airways.launch_vertexes,:);
land_sites = airways.vertexes(airways.land_vertexes,:);
cells = LEM_gen_FAA_cells(x_min,x_max,y_min,y_max,del_x,del_y,...
    launch_sites,land_sites,hd);

alt_spread = max_alt - min_alt;
num_requests = length(requests);
launch_sites = cells.launch_sites;
num_launch_sites = length(launch_sites);
land_sites = cells.land_sites;
num_land_sites = length(land_sites);

for r = 1:num_requests
    requestsc(r).request_time = requests(r).request_time;
    requestsc(r).launch_interval = requests(r).launch_interval;
    requestsc(r).speed = requests(r).speed;
    launch_index = requests(r).launch_index;
    land_index = requests(r).land_index;
    alt = min_alt + rand*alt_spread;
    path = zeros(3,6);
    pt1 = [launch_sites(launch_index,1:2),0];
    pt2 = [pt1(1:2),alt];
    pt4 = [land_sites(land_index,1:2),0];
    pt3 = [pt4(1:2),alt];
    path = [pt1 pt2; pt2 pt3; pt3 pt4];
    requestsc(r).path = path;
    requestsc(r).launch_index = launch_index;
    requestsc(r).land_index = land_index;
end

tch = 0;
