close all;
clear all;

DELIMITER = ',';
HEADERLINES = 1;

% Import the file
newData1 = importdata('port_optode.csv', DELIMITER, HEADERLINES);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end

PortO2Conc=newData1.data(:,1);
PortO2Sat=newData1.data(:,2);
PortTemperature=newData1.data(:,3);
PortRoverTime=newData1.textdata(2:end,1);
[date,time]=strtok(PortRoverTime,'T');
time=strtok(time,'T');
Portdatetime=strcat(date,',',time);


newData1 = importdata('starboard_optode.csv', DELIMITER, HEADERLINES);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end

StbdO2Conc=newData1.data(:,1);
StbdO2Sat=newData1.data(:,2);
StbdTemperature=newData1.data(:,3);
StbdRoverTime=newData1.textdata(2:end,1);
[date,time]=strtok(StbdRoverTime,'T');
time=strtok(time,'T');
Stbddatetime=strcat(date,',',time);

newData1 = importdata('stbd_ref_optode.csv', DELIMITER, HEADERLINES);

% Create new variables in the base workspace from those fields.
vars = fieldnames(newData1);
for i = 1:length(vars)
    assignin('base', vars{i}, newData1.(vars{i}));
end

RefO2Conc=newData1.data(:,1);
RefO2Sat=newData1.data(:,2);
RefTemperature=newData1.data(:,3);
RefRoverTime=newData1.textdata(2:end,1);
[date,time]=strtok(RefRoverTime,'T');
time=strtok(time,'T');
Refdatetime=strcat(date,',',time);


figure;
plot(datenum(Portdatetime),PortO2Conc,'rx');hold on;plot(datenum(Stbddatetime),StbdO2Conc,'gx');plot(datenum(Refdatetime),RefO2Conc,'bx')
legend('Port','Stbd','Ref');
xlabel('Time');ylabel('O2 Conc (uM)');
datetick('x','dd HH:MM','keepticks');

figure;
plot(datenum(Portdatetime),PortTemperature,'rx');hold on;plot(datenum(Stbddatetime),StbdTemperature,'gx');plot(datenum(Refdatetime),RefTemperature,'bx')
legend('Port','Stbd','Ref');
xlabel('Time');ylabel('Temp (deg C)');
axis tight;
datetick('x', 'dd HH:MM','keepticks');

break;
s=input('enter the experiment date:','s');
filename=strcat(s,'.mat');
save(filename,'Portdatetime','PortO2Conc','Stbddatetime','StbdO2Conc','Refdatetime','RefO2Conc');
dataname=strcat('Optode Results','_',s);
title(dataname);
saveas(gcf,strcat(dataname,'Conc.fig'),'fig');
saveas(gcf,strcat(dataname,'Conc.tiff'));
