function []= RefOptodes()
DELIMITER = ',';
HEADERLINES = 1;
newData1 = importdata('port_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

port_refO2Conc=newData1.data(:,1);
port_refRoverTime=newData1.textdata(2:end,1);
[date,time]=strtok(port_refRoverTime,'T');
time=strtok(time,'T');
port_refdatetime=strcat(date,',',time);
port_refConcTS=timeseries(port_refO2Conc,port_refdatetime);

timestring=char(time);

port_refTime=zeros(size(port_refdatetime,1),6);
for i= 1:size(port_refdatetime,1),
     [hr,mn,sc]=strread(char(time(i,:)),'%d%d%f','delimiter',':');
     [yr,mth,dy]=strread(char(date(i)),'%d%d%d','delimiter','-');
     [ss,ds]=strread(num2str(sc),'%d%d','delimiter','.');
     port_refTime(i,:)=[yr,mth,dy,hr,mn,ss];
end
%[index,j]=find(abs(diff(port_refTime(:,5)))>5);
[index,j]=find(abs(diff(datenum(port_refTime))>0.008));

port_refAveConc=zeros(size(index));
port_refAveTime=zeros(size(index));
for i= 1:size(index),
    if i==1
        port_refAveConc=mean(port_refO2Conc(1:index(i)));
        port_refAveTime=port_refdatetime(index(i));       
    else
        port_refAveConc=[port_refAveConc;mean(port_refO2Conc(index(i-1)+1:index(i)))];
        port_refAveTime=[port_refAveTime;port_refdatetime(index(i))];        
    end
end
port_refAveConc=[port_refAveConc;mean(port_refO2Conc(index(i)+1:end))];
port_refAveTime=[port_refAveTime;port_refdatetime(end)];
port_refConcAveTS=timeseries(port_refAveConc,port_refAveTime);

port_refAveTimeVect=datenum(port_refAveTime(:,1));
EpochSecs=(port_refAveTimeVect-719529)*86400;
port_refElapsedTime=zeros(size(EpochSecs));
for i=1:size(EpochSecs,1),
        port_refElapsedTime(i,1)=(EpochSecs(i,1)-EpochSecs(1,1))/60/60;
end


s=char(date(1));

RefData=[];
RefData=[mean(port_refAveConc),std(port_refAveConc),port_refAveConc(1),datenum(port_refAveTime(1,1)),datenum(port_refAveTime(end,1)), port_refElapsedTime(end)];
filename=strcat(s,'RefOnly.mat');
cd ..\..\MatlabData
save(filename, 'RefData');
close all;
cd ..