function LEM_show_STLD(reservations,lane_number)
% LEM_show_STLD - display Space-Time Lane Diagram
% On input:
%     reservations (reservations struct): reservation infor
%     lane_number (int): index into reservations
% On output:
%     Displays flights through lane as STLD
% Call:
%     LEM_show_STLD(res1,912);
% Author:
%     T Henderson
%     UU
%     Fall 2020
%

flights = reservations(lane_number).flights;
clf
if isempty(flights)
    plot([0,1,1,0,0],[0,0,1,1,0],'k');
    return
end
hold on
num_flights = length(flights(:,1));
list = flights;
[vals,indexes] = sort(list(:,2));
num_vals = length(vals);
min_t = vals(1) - 1;
max_t = max(list(:,3)) + 1;
plot([min_t,max_t,max_t,min_t,min_t],[0,0,10,10,0],'k');
plot(min_t,-5,'w.');
plot(max_t,15,'w.');
title(['Lane: ',num2str(lane_number)]);
for k = 1:num_vals
    plot([list(k,2),list(k,3)],[0,10],'b');
%    if mod(k,3)==1
%        text(list(k,2)-0.5,-1,num2str(list(k,1)));
%    elseif mod(k,3)==2
%        text(list(k,2)-0.5,-2,num2str(list(k,1)));
%    else
%        text(list(k,2)-0.5,-3,num2str(list(k,1)));
%    end
end
return

num_flights = length(flights);
list = [];
for f = 1:num_flights
    lanes = flights(f).plan(:,4);
    index = find(lanes==lane_number);
    if ~isempty(index)%&flights(f).status==0
        list = [list; f,flights(f).plan(index,1),flights(f).plan(index,2)];
    end
end
clf
if isempty(list)
    plot([0,1,1,0,0],[0,0,1,1,0],'k');
    return
end

hold on
[vals,indexes] = sort(list(:,2));
num_vals = length(vals);
min_t = vals(1) - 1;
max_t = max(list(:,3)) + 1;
plot([min_t,max_t,max_t,min_t,min_t],[0,0,10,10,0],'k');
plot(min_t,-5,'w.');
plot(max_t,15,'w.');
for k = 1:num_vals
    plot([list(k,2),list(k,3)],[0,10],'b');
    if mod(k,3)==1
        text(list(k,2)-0.5,-1,num2str(list(k,1)));
    elseif mod(k,3)==2
        text(list(k,2)-0.5,-2,num2str(list(k,1)));
    else
        text(list(k,2)-0.5,-3,num2str(list(k,1)));
    end
end
