%% Load data
% Comment this out after loading once
load('/gdata/projects/nsf_alpha/LCS/Chinmay/trunk/WorkDir/Calypso/mar_11_runs/4day_fwd/mat/forward_Start_11_March_12_00_00_End_15_March_12_00_00/ftle.mat')


%% Setting data
zmap = final_flowmap.z;
zmap_target = zmap;
zmap_target(:) = 0;

% Edit this to change what is being plotted. For instance, to plot points in the
% first 10 depths (20m) that end up below 50m:
 zmap_target(:,:,10) = zmap(:,:,10)>50;
%zmap_target(:,:,10) = zmap(:,:,10)>30;
to_plot = double(app.mask);
to_plot2 = double(zmap_target);
% to_plot3 = double(final_tracer);

%% Plotting
timeZone = 'GMT';

saveStringFormat = sprintf('initAdvectField3D_Start_%s_End_%s', app.startDate_str, app.endDate_str);

if strcmp(timeZone, 'EST')
    timeDifference = -5/24; % wrt GMT in hours (for EST)
elseif strcmp(timeZone, 'EDT')
    timeDifference = -4/24; % wrt GMT in hours (for EDT)
elseif strcmp(timeZone, 'GMT')
    timeDifference = 0;
end

to_plot(to_plot ~= 1) = 0;
to_plot2(to_plot2 ~= 1) = 0;
% to_plot3(to_plot3 ~= 1) = 0;

depth = app.depth;
lat = app.lat;
lon = app.lon;

lon3d = repmat(app.lon, [1, 1, length(depth)]);
lat3d = repmat(app.lat, [1, 1, length(depth)]);
depth3d = repmat(reshape(depth,[1, 1, length(depth)]), [app.Ny, app.Nx, 1]);

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

startDate = datenum(app.start_date) + app.t0/86400 + timeDifference;
endDate = datenum(app.start_date) + app.tEnd/86400 + timeDifference;

title_fig = sprintf('Points of interest in flow from \n %s to %s %s', datestr(startDate, 0), datestr(endDate, 0), timeZone);
title(title_fig, 'FontSize', 20, 'Interpreter', 'LaTex');

xlabel('Longitude', 'Interpreter', 'LaTex');
ylabel('Latitude', 'Interpreter', 'LaTex');
zlabel('Depth (m)', 'Interpreter', 'LaTex');
set(gca, 'FontSize', 30);

fv = isosurface(lon3d, lat3d, depth3d, permute(to_plot, [2, 3, 1]), 0.75);
p = patch(fv, 'FaceColor', [0.2 0 0], 'EdgeColor', 'none', 'FaceAlpha', 0.1);

fv2 = isosurface(lon3d, lat3d, depth3d, permute(to_plot2, [2, 1, 3]), 0.75);
p2 = patch(fv2, 'FaceColor', 'b', 'EdgeColor', 'none', 'FaceAlpha', 1);
% 
% fv3 = isosurface(lon3d, lat3d, depth3d, permute(to_plot3, [2, 1, 3]), 0.75);
% p3 = patch(fv3, 'FaceColor', 'r', 'EdgeColor', 'none', 'FaceAlpha', 1);

%% View settings
zticks([0,10,20,30,40,50])
grid on;
camlight;
%camlight(-90, 30);
camlight(-135, -15);
lighting gouraud;
view([30, 60]);
set(gca,'zdir','reverse');
zlim([0,50]);
hold off;
