function [] = MakeDiagFig(s, plotpath)
% Creates diagnostic figures for most the 10 most recent profiles with 
% the last one in thick red (crimson). inputs s stuct and plotpath 
% (location to save).
% Ben Werb 5/30/24, based on YT 2020 plot_spraysat.m

% Default plot settings
set(0, 'DefaultAxesFontSize', 20, ...
    'DefaultAxesLineWidth', 2, ...
    'DefaultLineLineWidth', 1, ...
    'DefaultTextFontName', 'Times', ...
    'DefaultAxesFontWeight', 'bold', ...
    'DefaultLineMarkerSize', 10, ...
    'DefaultFigureUnit', 'centimeter', ...
    'DefaultFigurePosition', [6 1 25 20]);
% Select graphing display options
fname = 'avenir';
fsize = 12;
newcol = rgb('crimson'); % New profile color settings
newlw = 3; % New line size

% Define number of profiles to plot
if(size(s.lat_,2)<10) % if tot profiles less than 10
    nplot = size(s.lat_,2)-1; % plot n profs - 1
else
    nplot = 9; % how many dives to plot
end
% profs2plot = size(s.pres,2)-nplot:size(s.pres,2); % prof idxs
profs2plot = 400:410;
preslimits = [0 round(max(max(s.pres(:,profs2plot))),1)+10]; % pres axis lims




vars = {'vrs_std','vrs','vk_std','vk','Ik','Ib'};
vname = {'Vrs std','Vrs','Vk std','Vk','Ik','Ib'};
% xlims = [-0.5,0.5;-1.0,-0.5;-0.5,0.5;-2,-1;0,7;0.4,1];
% xlims = [0.0, 0.001;-1.0,-0.8;0.0,0.001;-1.2,-0.8;-20,20;-2,2]; % Limits from JKW
xlims = [-inf,inf;-inf,inf;-inf,inf;-inf,inf;24,35;-1,1]; 
% Need to validate xlims works for all data

% Create a tiled layout with 10 rows and 4 columns
tl = tiledlayout(3, 2, 'TileSpacing', 'Compact', 'Padding', 'Compact');
% title(tl, 'Last 10 Profiles')
% subtitle(tl,'Most recent in red')
cm = colormap(cmocean('dense',11));
cm = cm(2:11,:);
% Define the size of the figure to be full page (8.5 x 11 inches for a standard letter size)
fig = gcf;
fig.Visible = "on";
fig.PaperUnits = 'inches';
fig.PaperPosition = [0 0 8.5 11];

% First 4 cols: four unique plots that span 3 rows and 1 col
for i = 1:6
    nexttile([1 1])
    var = char(vars(i));
    var2plot = s.(var);
    plot(var2plot(:,profs2plot), s.pres(:,profs2plot));
    hold on
    plot(s.(var)(:,end), s.pres(:,end),'Color', newcol,'Linewidth',newlw);
    set(gca, 'ydir', 'reverse', 'fontsize', fsize, 'FontName', fname);
    xlabel(char(vname(i)));
    xlim(xlims(i,:))
    ylim(preslimits);
    hold off
end

plotname = 'prof';
SaveFigFolderServer(fig,plotpath,plotname);

end