function []= OptodesSlopes_Abbrev(Ehour)
%clear all;
DELIMITER = ',';
HEADERLINES = 1;


% Import the file
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);
stbdTemp=newData1.data(:,3);
stbdRoverTime=newData1.textdata(2:end,1);
[date,time]=strtok(stbdRoverTime,'T');
time=strtok(time,'T');
stbddatetime=strcat(date,',',time);
stbdConcTS=timeseries(stbdO2Conc,stbddatetime);
stbdTempTS=timeseries(stbdTemp,stbddatetime);
timestring=char(time);


stbdTime=zeros(size(stbddatetime,1),6);
for i= 1:size(stbddatetime,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','.');
     stbdTime(i,:)=[yr,mth,dy,hr,mn,ss];
end
[index,j]=find(abs(diff(stbdTime(:,5)))>5);

stbdAveTemp=zeros(size(index));
stbdAveConc=zeros(size(index));
stbdAveTime=zeros(size(index));
for i= 1:size(index),
    if i==1
        stbdAveConc=mean(stbdO2Conc(1:index(i)));
        stbdAveTemp=mean(stbdTemp(1:index(i)));
        stbdAveTime=stbddatetime(index(i));       
    else
        stbdAveConc=[stbdAveConc;mean(stbdO2Conc(index(i-1)+1:index(i)))];
        stbdAveTemp=[stbdAveTemp;mean(stbdTemp(index(i-1)+1:index(i)))];
        stbdAveTime=[stbdAveTime;stbddatetime(index(i))];        
    end
end
stbdAveConc=[stbdAveConc;mean(stbdO2Conc(index(i)+1:end))];
stbdAveTemp=[stbdAveTemp;mean(stbdTemp(index(i)+1:end))];
stbdAveTime=[stbdAveTime;stbddatetime(end)];
stbdConcAveTS=timeseries(stbdAveConc,stbdAveTime);

stbdAveTimeVect=datenum(stbdAveTime(:,1));
EpochSecs=(stbdAveTimeVect-719529)*86400;
stbdElapsedTime=zeros(size(EpochSecs));
for i=1:size(EpochSecs,1),
        stbdElapsedTime(i,1)=(EpochSecs(i,1)-EpochSecs(1,1))/60/60;
end
I=max(find(stbdElapsedTime<Ehour));
stbdElapsedTime(I)
Ehour
StbdLinFit=[polyfit(stbdElapsedTime(1:I),stbdAveConc(1:I),1)];

p=polyfitn(stbdElapsedTime(1:I),stbdAveConc(1:I),'constant x');
StbdLinFit=[StbdLinFit,datenum(stbdAveTime(1,1)),p.R2,stbdElapsedTime(I)];

y=StbdLinFit(1)*stbdElapsedTime(1:I) + StbdLinFit(2);
figure;
subplot(2,1,1);
plot(stbdConcTS,'rv');hold on;plot(stbdConcAveTS,'bx');
xlabel('Time');ylabel('O2 Conc (uM)');
legend('stbd','stbd Ave','Location','Best');

subplot(2,1,2);
plot(stbdElapsedTime,stbdAveConc,'b');hold on; plot(stbdElapsedTime(1:I),y(1:I),'g');
xlabel('Elapsed Time (hrs)');ylabel('O2 Conc (uM)');
legend('stbd Ave','lin fit','Location','Best');

s=char(date(1));
dataname=strcat('Stbd_Abbrev','_',s);
saveas(gcf,strcat(dataname,'.tiff'));


filename=strcat(s,'StbdAb.mat');
cd ..\..\MatlabData
save(filename, 'StbdLinFit');
close all;
cd ..





