% The mat file for each simulation contains the following datastructures:
% 
% app: this contains all the information about the simulation such as
% domain description, numerical mentod descriptions, grids, masks, 
% velocities, simulation dates etc.
%
% final_flowmap: This contains the computed x and y flow maps
%
% ftle: This is the computed FTLE field
%
% pd: This is the computed polar distance (coherence) field

% load the mat file
load ftle.mat;

% either ftle or the flow maps (x or y) may be plotted
% to_plot = ftle;
% to_plot = final_flowmap.x;
to_plot = final_flowmap.y;

% Mask the ftle using NaNs for appropriate plotting 
to_plot_masked = to_plot.*app.NaNmask;

% Create correctly sized empty figure
figure(1);
clf;
f = gcf;
set(f, 'Position', [0, 0, 1920, 1080]);
figpos = getpixelposition(f);
resolution = get(0, 'ScreenPixelsPerInch');
set(f, 'paperunits', 'inches', 'papersize', figpos(3:4)/resolution, 'paperposition', [0 0 figpos(3:4)/resolution]);

% Plot field
pcolor(app.lon, app.lat, to_plot_masked');
shading interp;
colormap jet;
h = colorbar;
set(h, 'FontSize', 20);
xlabel(h, '$s^{-1}$', 'FontSize', 40, 'Interpreter', 'LaTex');
caxis([0, max(to_plot_masked(:))]);
title('Sample field', 'FontSize', 20, 'Interpreter', 'LaTex');

% % Plotting with m_map toolbox (optional)
% m_proj('miller', 'lat', [min(app.lat(:)) max(app.lat(:))], 'lon', [min(app.lon(:)) max(app.lon(:))]);
% m_grid('box', 'fancy', 'FontSize', 20, 'tickstyle', 'dd');
% m_gshhs_f('patch', [.7 .7 .7]);
% m_pcolor(app.lon, app.lat, to_plot_masked');
% shading interp;
% colormap jet;
% h = colorbar;
% set(h, 'FontSize', 20);
% xlabel(h, '$s^{-1}$', 'FontSize', 40, 'Interpreter', 'LaTex');
% caxis([0, max(to_plot_masked(:))]);
% title('Sample field', 'FontSize', 20, 'Interpreter', 'LaTex');