clear;
load('GLIDER_DATA_LEVEL1\Ramses_Deployment1_DO_L1.mat');
figure('Name', 'Ramses Dissolved Oxygen Hysteresis Analysis', 'NumberTitle', 'off');

start = 279409;
middle = 279890; 
stop = 280179;
subplot(3, 4, 1);
[ax, ~, 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');
title({'Ramses Deployment 1'; 'Depth and O2 Saturation'; '\color[rgb]{0 .5 0}Sample Time as Green Bar'});
xlabel('UTC Time');
ylabel(ax(1), 'Depth (m)');
ylabel(ax(2), 'O2 Saturation (%)');
axes(ax(2));
yl = get(gca, 'YLim');
line([ptime_ebd_datenum(middle) ptime_ebd_datenum(middle)], [yl(1) yl(2)], 'LineStyle', '-', 'Color', 'green', 'LineWidth', 2);

subplot(3, 4, 2);
[ax, ~, 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');
title({'Ramses Deployment 1'; 'Depth and O2 Saturation'; ['on ', datestr(ptime_ebd_datenum(start), 1)]});
xlabel('UTC Time');
ylabel(ax(1), 'Depth (m)');
ylabel(ax(2), 'O2 Saturation (%)');

subplot(3, 4, 3);
plot(o2_sat(start:middle), -depthi(start:middle), '.');
hold on;
plot(o2_sat(middle:stop), -depthi(middle:stop), 'r.');
title({'Ramses Deployment 1'; 'Depth and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xlabel('O2 Saturation (%)');
ylabel('Depth (m)');

subplot(3, 4, 4);
plot(o2_sat(start:middle), tempi(start:middle), '.');
hold on;
plot(o2_sat(middle:stop), tempi(middle:stop), 'r.');
title({'Ramses Deployment 1'; 'Temp and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xlabel('O2 Saturation (%)');
ylabel('Temp (Degrees C)');

clear;
load('GLIDER_DATA_LEVEL1\Ramses_Deployment2_DO_L1.mat');

start = 96030;
middle = 96414; 
stop = 96765;
subplot(3, 4, 5);
[ax, ~, 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');
title({'Ramses Deployment 2'; 'Depth and O2 Saturation'; '\color[rgb]{0 .5 0}Sample Time as Green Bar'});
xlabel('UTC Time');
ylabel(ax(1), 'Depth (m)');
ylabel(ax(2), 'O2 Saturation (%)');
axes(ax(2));
yl = get(gca, 'YLim');
line([ptime_ebd_datenum(middle) ptime_ebd_datenum(middle)], [yl(1) yl(2)], 'LineStyle', '-', 'Color', 'green', 'LineWidth', 2);

subplot(3, 4, 6);
[ax, ~, 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');
title({'Ramses Deployment 2'; 'Depth and O2 Saturation'; ['on ', datestr(ptime_ebd_datenum(start), 1)]});
xlabel('UTC Time');
ylabel(ax(1), 'Depth (m)');
ylabel(ax(2), 'O2 Saturation (%)');

subplot(3, 4, 7);
plot(o2_sat(start:middle), -depthi(start:middle), '.');
hold on;
plot(o2_sat(middle:stop), -depthi(middle:stop), 'r.');
title({'Ramses Deployment 2'; 'Depth and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xlabel('O2 Saturation (%)');
ylabel('Depth (m)');

subplot(3, 4, 8);
plot(o2_sat(start:middle), tempi(start:middle), '.');
hold on;
plot(o2_sat(middle:stop), tempi(middle:stop), 'r.');
title({'Ramses Deployment 2'; 'Temp and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xlabel('O2 Saturation (%)');
ylabel('Temp (Degrees C)');

clear;
load('GLIDER_DATA_LEVEL1\Ramses_Deployment3_DO_L1.mat');

start = 66193;
middle = 66521; 
stop = 66842;
subplot(3, 4, 9);
[ax, ~, 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');
title({'Ramses Deployment 3'; 'Depth and O2 Saturation'; '\color[rgb]{0 .5 0}Sample Time as Green Bar'});
xlabel('UTC Time');
ylabel(ax(1), 'Depth (m)');
ylabel(ax(2), 'O2 Saturation (%)');
axes(ax(2));
yl = get(gca, 'YLim');
line([ptime_ebd_datenum(middle) ptime_ebd_datenum(middle)], [yl(1) yl(2)], 'LineStyle', '-', 'Color', 'green', 'LineWidth', 2);

subplot(3, 4, 10);
[ax, ~, 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');
title({'Ramses Deployment 3'; 'Depth and O2 Saturation'; ['on ', datestr(ptime_ebd_datenum(start), 1)]});
xlabel('UTC Time');
ylabel(ax(1), 'Depth (m)');
ylabel(ax(2), 'O2 Saturation (%)');

subplot(3, 4, 11);
plot(o2_sat(start:middle), -depthi(start:middle), '.');
hold on;
plot(o2_sat(middle:stop), -depthi(middle:stop), 'r.');
title({'Ramses Deployment 3'; 'Depth and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xlabel('O2 Saturation (%)');
ylabel('Depth (m)');

subplot(3, 4, 12);
plot(o2_sat(start:middle), tempi(start:middle), '.');
hold on;
plot(o2_sat(middle:stop), tempi(middle:stop), 'r.');
title({'Ramses Deployment 3'; 'Temp and O2 Saturation'; '\color{blue}Downcast = Blue \color{black}/ \color{red}Upcast = Red'});
xlabel('O2 Saturation (%)');
ylabel('Temp (Degrees C)');
