function [] = plot_spraysat(s, plotpath)



w = 0.4;
l = 0.3;
ygap = 0.08;
xgap = 0.05; 
xindent = 0.1;
yindent = 0.06;
fname = 'times';
fsize = 12;
msize = 4;

if(length(s.lat)<10)
    nplot = length(s.lat)-1;
else
    nplot = 10; % how many dives to plot
end



profs2plot = size(s.pres,2)-nplot:size(s.pres,2);

preslimits = [0 round(nanmax(nanmax(s.pres(:,profs2plot))),1)+10];
% preslimits = [0 1000];
% fit into a printable letter size paper
f1 = figure('unit', 'inch', 'position', [0.1 0.6 8.5 11]);

% first subplot is map. m_mapV1.4 needs to be downloaded
subplot('position', [0.15 0.82 0.35 0.17]);
    hold on; box on;
    m_proj('miller', 'lat', [nanmin(s.lat)-0.5 nanmax(s.lat)+0.5], 'lon', [nanmin(s.lon)-0.5 nanmax(s.lon)+0.5]); % set range for world map
    m_coast('color', [0 0 0]); % draw coast lines
    m_plot(s.lon(end-nplot:end), s.lat(end-nplot:end), 'ro', 'markerfacecolor', 'r', 'markersize', 1); % plot cruise tracks. 
    m_plot(s.lon(end), s.lat(end), 'ko', 'markerfacecolor', 'k', 'markersize', 1); % plot last surface black
    set(gca, 'yticklabel', [], 'xticklabel', []); % erase x and y labels.
    xlabel('Lon', 'fontsize', fsize, 'fontname', fname);
    ylabel('Lat', 'fontsize', fsize, 'fontname', fname);

fsize_tbl = 16;
% top right is for text
subplot('position', [0.55 0.82 0.4 0.17], 'visible', 'off');
    t1 = text(0, 0.9, [s.depID]);
    t2 = text(0, 0.7, ['DATE: ',datestr(s.sdn_(1),'dd/mm/yyyy'),' to ',datestr(s.sdn_(end),'dd/mm/yyyy')]);
    t3 = text(0, 0.5, ['Last profile: ',datestr(s.sdn(end))]);
    t4 = text(0, 0.3, [num2str(length(s.sdn)),' profiles']);
    t5 = text(0, 0.1, sprintf('%3.3f, %3.3f', s.lat(end), s.lon(end)));
    set(t1, 'fontsize', fsize_tbl, 'fontweight', 'bold');
    set(t2, 'fontsize', fsize_tbl, 'fontweight', 'bold');
    set(t3, 'fontsize', fsize_tbl, 'fontweight', 'bold');
    set(t4, 'fontsize', fsize_tbl, 'fontweight', 'bold');
    set(t5, 'fontsize', fsize_tbl, 'fontweight', 'bold');
        
% ============= start plotting profiles, 4 panels ======================

% top left; temperature
ax(1) = subplot('position', [xindent yindent+l+ygap w l]);
    hold on; box on;
    tc2plot = s.tc;
    tc2plot(s.tc_QC~=0) = NaN;
    plot(tc2plot(:,profs2plot), s.pres(:,profs2plot));
    plot(s.tc(:,end), s.pres(:,end), 'k');
    set(gca, 'ydir', 'reverse', 'fontsize', fsize, 'FontName', fname);
    ylabel('Pressure');
    xlabel('Temperature');
    ylim(preslimits);
    
% top right; salinity
ax(2) = subplot('position', [xindent+xgap+w yindent+l+ygap w l]);
    hold on; box on;
    psal2plot = s.psal;
    psal2plot(s.psal_QC~=0) = NaN;
    plot(psal2plot(:,profs2plot), s.pres(:,profs2plot));
    plot(s.psal(:,end), s.pres(:,end), 'k');
    set(gca, 'ydir', 'reverse', 'fontsize', fsize, 'FontName', fname); %, 'YTickLabel', []);
    xlabel('Salinity');
    ylim(preslimits);

% bottom left; Oxy
ax(3) = subplot('position', [xindent yindent w l ]);
    hold on; box on;
    doxy2plot = s.doxy;
    doxy2plot(s.doxy_QC~=0) = NaN;
    plot(doxy2plot(:,profs2plot), s.pres(:,profs2plot));
    plot(s.doxy(:,end), s.pres(:,end), 'k');
    xlabel('O2 [umol/kg]');
    ylabel('Pressure');    
    set(gca, 'ydir', 'reverse', 'fontsize', fsize, 'FontName', fname);
    ylim(preslimits);
    
% bottom right; pH
ax(4) = subplot('position', [xindent+xgap+w yindent w l]);
    hold on; box on;
    pHin2plot = s.pHin;
    pHin2plot(s.pHin_QC~=0) = NaN;
    plot(pHin2plot(:,profs2plot), s.pres(:,profs2plot));
    plot(s.pHin(:,end), s.pres(:,end), 'k');
    xlabel('pH');
    set(gca, 'ydir', 'reverse', 'fontsize', fsize, 'FontName', fname); %, 'YTickLabel', []);
    ylim(preslimits);
%     xlim([7.6 8.3]);

linkaxes(ax, 'y');

f1filename = [s.depID,'_sat_',num2str(size(s.pres,2)),'prof.jpg'];
saveas(f1, f1filename);

fgfilename = [s.depID,'_sat_',num2str(size(s.pres,2)),'prof.fig'];
saveas(f1, fgfilename);

pause(1);

% send file via email

setpref('Internet', 'E_mail', 'yui@mbari.org');
setpref('Internet', 'SMTP_Server', 'mail.mbari.org');

sendmail('yui@mbari.org', s.depID, 'Summary plots', [s.depID,'_sat_',num2str(size(s.pres,2)),'prof.jpg']);

% send data to Anna 
setpref('Internet', 'E_mail', 'ahughes@mbari.org');
setpref('Internet', 'SMTP_Server', 'mail.mbari.org');

sendmail('ahughes@mbari.org', s.depID, 'Summary plots', [s.depID,'_sat_',num2str(size(s.pres,2)),'prof.jpg']);



movefile(f1filename, plotpath, 'f');
movefile(fgfilename, plotpath, 'f');

close(f1);



