function cells = LEM_gen_FAA_cells(x_min,x_max,y_min,y_max,del_x,del_y,...
    launch_sites,land_sites,hd)
% LEM_gen_FAA_cells - generate a geographical cell structure
% On input:
%     x_min (float): minimum x value
%     x_max (float): maximum x value
%     y_min (float): minimum y value
%     y_max (float): maximum y value
%     del_x (float): distance between grid lines in x
%     del_y (float): distance between grid lines in y
%     launch_sites (mx3 array): 3D point locations of launch sites
%     land_sites (nx3 array): 3D point locations of landing sites
%     hd (float): headway distance
% On output:
%     cells (cells struct): grid infor
%       .x_min (float): min x value
%       .x_max (float): max x value
%       .y_min (float): min y value
%       .y_max (float): max y value
%       .del_x (float): step in x
%       .del_y (float): step in y
%       .M (int): number of rows in grid
%       .N (int): number of cols in grid
%       .launch_sites (mx3 array): 3D point locations of launch sites
%       .land_sites (nx3 array): 3D point locations of landing sites
%       .hd (float): headway distance
%       .cells_lists (MxN struct): cell indexes traversed from launch site to 
%           land site
% Call:
%     cells_EB = LEM_gen_FAA_cells(-18500,18500,-11500,11500,2000,2000,...
%         launch_sites,land_sites,200);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

cells.x_min = x_min;
cells.x_max = x_max;
cells.y_min = y_min;
cells.y_max = y_max;
cells.del_x = del_x;
cells.del_y = del_y;
x_vals = [x_min:del_x:x_max];
N = length(x_vals) - 1;
y_vals = [y_min:del_y:y_max];
M = length(y_vals) - 1;
cells.M = M;
cells.N = N;
cells.launch_sites = launch_sites;
cells.land_sites = land_sites;
cells.hd = hd;
for r1 = 1:M
    r1;
    for c1 = 1:N
        ind1 = M*(c1-1) + r1;
        for r2 = 1:M
            for c2 = 1:N
                ind2 = M*(c2-1) + r2;
                [rows,cols] = LEM_line_between([r1,c1],[r2,c2]);
                clist = zeros(length(rows),1);
                for k = 1:length(rows);
                    clist(k) = M*(cols(k)-1) + rows(k);
                end
                cells.cell_lists(ind1,ind2).list = clist;
            end
        end
    end
end
return

% finds all launch-land pair cell sequences
[num_launch_sites,dummy] = size(launch_sites);
[num_land_sites,dummy] = size(land_sites);
for s1 = 1:num_launch_sites
    pt1 = launch_sites(s1,1:2);
    for s2 = 1:num_land_sites
        [s1,s2,num_launch_sites]
        pt2 = land_sites(s2,1:2);
        cell_lists(s1,s2).cell_els = LEM_cell_els(cells,pt1,pt2,hd);
    end
end
cells.cell_lists = cell_lists;
tch = 0;
