% Script to manipulate a structute file in Matlab

% Sample structured file contains flight plan data

% flightPanData = 
% 
% 1x5 struct array with fields:
%     fname 
%     fmodel
%     origin
%     destination
%     n
%     wp
%     twp

% Furthermore: the waypoint (flightPlanData.wp) child contains the following information:
%
% Column 1 = waypoint latitudes (deg)
% Column 2 = waypoint longitudes (deg) - negative West of London
% Column 3 = altitudes (in feet/100) - called cruise flight level

%  flightPlanData(1).wp
% 
%    30.3833  -81.4167         0
%    30.2541  -81.3836   46.8964
%    30.1249  -81.3505   87.5529


% Start by loading the file into the Matlab workspace
% Map has three vectors: latitude, longitude and elevation to make 3D plots

load flightPlanData      % loads the structure data
load usamap               % loads the coordinates of the U.S. boundary

% Make a plot of the US first. Then hold the plot to make a plot of the
% flights

plot3(uslon,uslat,elevation)
xlabel('Longitude (deg)','fontsize',20)
ylabel('Latitude (deg)','fontsize',20)
zlabel('Elevation (feet)','fontsize',20)
grid

hold on

% Now plot each flight.
% This requires a loop because the data is inside a struct file. 
% This is one of one of the weaknesses of the struct files

noFlights = length(flightPlanData);     % finds the number of flights

for i=1:noFlights
    
    % here we plot three vectors contained in the waypoint
    % (flightPlanData.wp) child structure
    
    plot3(flightPlanData(i).wp(:,2),flightPlanData(i).wp(:,1),flightPlanData(i).wp(:,3),'o-r')
    
end





