clear;
load('GLIDER_DATA_LEVEL1\Pelagia_Deployment1_DO_L1.mat');
f1 = figure('Name', 'Pelagia Dissolved Oxygen Hysteresis Analysis', 'NumberTitle', 'off');

sp1 = subplot(3, 4, 1);
[ax, h1, h2] = plotyy(ptime_ebd_datenum, -depthi, ptime_ebd_datenum, o2_sat);
datetick(ax(1), 'x', 6, 'keeplimits', 'keepticks');
datetick(ax(2), 'x', 6, 'keeplimits', 'keepticks');
set(h2, 'Color', 'r');
set(ax(2), 'YColor', 'r');
tt = title({'Pelagia Deployment 1'; 'Depth and O2 Saturation'});
xl = xlabel('Time');
yl1 = ylabel(ax(1), 'Depth (m)');
yl2 = ylabel(ax(2), 'O2 Saturation (%)');

sp2 = subplot(3, 4, 2);
start = 250174;
middle = 250290; 
stop = 250401;
[ax, h1, h2] = plotyy(ptime_ebd_datenum(start:stop), -depthi(start:stop), ptime_ebd_datenum(start:stop), o2_sat(start:stop));
datetick(ax(1), 'x', 15, 'keeplimits', 'keepticks');
datetick(ax(2), 'x', 15, 'keeplimits', 'keepticks');
set(h2, 'Color', 'r');
set(ax(2), 'YColor', 'r');
tt = title({'Pelagia Deployment 1'; 'Depth and O2 Saturation'; ['on ', datestr(ptime_ebd_datenum(start), 1)]});
xl = xlabel('Time');
yl1 = ylabel(ax(1), 'Depth (m)');
yl2 = ylabel(ax(2), 'O2 Saturation (%)');

sp3 = subplot(3, 4, 3);
p1 = plot(o2_sat(start:middle), -depthi(start:middle), '.');
hold on;
p2 = plot(o2_sat(middle:stop), -depthi(middle:stop), 'r.');
tt = title({'Pelagia Deployment 1'; 'Depth and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xl = xlabel('O2 Saturation (%)');
yl = ylabel('Depth (m)');

sp4 = subplot(3, 4, 4);
p1 = plot(o2_sat(start:middle), tempi(start:middle), '.');
hold on;
p2 = plot(o2_sat(middle:stop), tempi(middle:stop), 'r.');
tt = title({'Pelagia Deployment 1'; 'Temp and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xl = xlabel('O2 Saturation (%)');
yl = ylabel('Temp (Degrees C)');

clear;
load('GLIDER_DATA_LEVEL1\Pelagia_Deployment2_DO_L1.mat');

sp1 = subplot(3, 4, 5);
[ax, h1, h2] = plotyy(ptime_ebd_datenum, -depthi, ptime_ebd_datenum, o2_sat);
datetick(ax(1), 'x', 6, 'keeplimits', 'keepticks');
datetick(ax(2), 'x', 6, 'keeplimits', 'keepticks');
set(h2, 'Color', 'r');
set(ax(2), 'YColor', 'r');
tt = title({'Pelagia Deployment 2'; 'Depth and O2 Saturation'});
xl = xlabel('Time');
yl1 = ylabel(ax(1), 'Depth (m)');
yl2 = ylabel(ax(2), 'O2 Saturation (%)');

sp2 = subplot(3, 4, 6);
start = 303249;
middle = 303491; 
stop = 303678;
[ax, h1, h2] = plotyy(ptime_ebd_datenum(start:stop), -depthi(start:stop), ptime_ebd_datenum(start:stop), o2_sat(start:stop));
datetick(ax(1), 'x', 15, 'keeplimits', 'keepticks');
datetick(ax(2), 'x', 15, 'keeplimits', 'keepticks');
set(h2, 'Color', 'r');
set(ax(2), 'YColor', 'r');
tt = title({'Pelagia Deployment 2'; 'Depth and O2 Saturation'; ['on ', datestr(ptime_ebd_datenum(start), 1)]});
xl = xlabel('Time');
yl1 = ylabel(ax(1), 'Depth (m)');
yl2 = ylabel(ax(2), 'O2 Saturation (%)');

sp3 = subplot(3, 4, 7);
p1 = plot(o2_sat(start:middle), -depthi(start:middle), '.');
hold on;
p2 = plot(o2_sat(middle:stop), -depthi(middle:stop), 'r.');
tt = title({'Pelagia Deployment 2'; 'Depth and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xl = xlabel('O2 Saturation (%)');
yl = ylabel('Depth (m)');

sp4 = subplot(3, 4, 8);
p1 = plot(o2_sat(start:middle), tempi(start:middle), '.');
hold on;
p2 = plot(o2_sat(middle:stop), tempi(middle:stop), 'r.');
tt = title({'Pelagia Deployment 2'; 'Temp and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xl = xlabel('O2 Saturation (%)');
yl = ylabel('Temp (Degrees C)');

clear;
load('GLIDER_DATA_LEVEL1\Pelagia_Deployment3_DO_L1.mat');

sp1 = subplot(3, 4, 9);
[ax, h1, h2] = plotyy(ptime_ebd_datenum, -depthi, ptime_ebd_datenum, o2_sat);
datetick(ax(1), 'x', 6, 'keeplimits', 'keepticks');
datetick(ax(2), 'x', 6, 'keeplimits', 'keepticks');
set(h2, 'Color', 'r');
set(ax(2), 'YColor', 'r');
tt = title({'Pelagia Deployment 3'; 'Depth and O2 Saturation'});
xl = xlabel('Time');
yl1 = ylabel(ax(1), 'Depth (m)');
yl2 = ylabel(ax(2), 'O2 Saturation (%)');

sp2 = subplot(3, 4, 10);
start = 134879;
middle = 135082; 
stop = 135263;
[ax, h1, h2] = plotyy(ptime_ebd_datenum(start:stop), -depthi(start:stop), ptime_ebd_datenum(start:stop), o2_sat(start:stop));
datetick(ax(1), 'x', 15, 'keeplimits', 'keepticks');
datetick(ax(2), 'x', 15, 'keeplimits', 'keepticks');
set(h2, 'Color', 'r');
set(ax(2), 'YColor', 'r');
tt = title({'Pelagia Deployment 3'; 'Depth and O2 Saturation'; ['on ', datestr(ptime_ebd_datenum(start), 1)]});
xl = xlabel('Time');
yl1 = ylabel(ax(1), 'Depth (m)');
yl2 = ylabel(ax(2), 'O2 Saturation (%)');

sp3 = subplot(3, 4, 11);
p1 = plot(o2_sat(start:middle), -depthi(start:middle), '.');
hold on;
p2 = plot(o2_sat(middle:stop), -depthi(middle:stop), 'r.');
tt = title({'Pelagia Deployment 3'; 'Depth and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xl = xlabel('O2 Saturation (%)');
yl = ylabel('Depth (m)');

sp4 = subplot(3, 4, 12);
p1 = plot(o2_sat(start:middle), tempi(start:middle), '.');
hold on;
p2 = plot(o2_sat(middle:stop), tempi(middle:stop), 'r.');
tt = title({'Pelagia Deployment 3'; 'Temp and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xl = xlabel('O2 Saturation (%)');
yl = ylabel('Temp (Degrees C)');
