%run data program through all rover plans
global d;
global StbdSlopes;
 %d=dir ('plan-*0.1*');
% d=dir ('plan-*12.01.*');
  d=dir ('plan-*');

for i=1:size(d,1)
cd (d(i).name);
op = dir ('*-optodes');
cd (op.name)
OptodeSlopesv2();
end
%clear all
break
cd MatlabData
l=dir('20*');

%for Station M 11/11 dont use last two
PortSlopes=ones(size(l,1)-2,4);
StbdSlopes=ones(size(l,1)-2,4);
for i=1:size(l,1)-2
    load(l(i).name);
    PortSlopes(i,:)=PortLinFit;
    StbdSlopes(i,:)=StbdLinFit;
   
end
l=dir('20*')

%for Station M 11/11 dont use last two of port last one of stbd
PortSlopes=ones(size(l,1)-2,4);

for i=1:size(l,1)-2
    load(l(i).name);
    PortSlopes(i,:)=PortLinFit;
end
clear l;
cd StbdAb\ 
k=dir('*StbdAb.mat')

StbdSlopes=ones(size(k,1),5);
for i=1:size(k,1)
    load(k(i).name);
    StbdSlopes(i,:)=StbdLinFit;
   
end
%for Station M 5/11 dont use last two
% StbdSlopes=ones(size(l,1)-2,4);
% for i=1:size(l,1)-2
%     load(l(i).name);
%     StbdSlopes(i,:)=StbdLinFit;
%    
% end


p=timeseries(PortSlopes(:,1),datestr(PortSlopes(:,3)))
s=timeseries(StbdSlopes(:,1),datestr(StbdSlopes(:,3)))
q=timeseries(StbdSlopes(:,1),datestr(StbdSlopes(:,3)))

figure; plot(p,'xb');
hold on;plot(s,'xm');
legend('Port','Stbd')
xlabel('Date');ylabel('Slope (um/hr)');
figure;
plot(PortSlopes(:,3),PortSlopes(:,1),'bx');
hold on;
plot(StbdSlopes(:,3),StbdSlopes(:,1),'rx');
xlabel('Date');ylabel('Slope (um/hr)');

figure;
plot(PortSlopes(:,3),PortSlopes(:,4),'bx');
hold on;
plot(StbdSlopes(:,3),StbdSlopes(:,4),'rx');
xlabel('Date');ylabel('R^2 for Lin Reg');
saveas(gcf,strcat('R^2_SCOCLinReg','.tiff'));
datetick('x','mmmyyyy','keepticks','keeplimits')
legend('Port','Stbd');
saveas(gcf,strcat('SCOC_Rover','.tiff'));
datetick('x','ddmmmyyyy','keeplimits')
st=datestr(StbdSlopes(:,3));
fid = fopen('StbdR2.txt','wt');
for i=1:size(StbdSlopes,1),
fprintf(fid,'%s\t %d\n',st(i,:),StbdSlopes(i,4));
end
fclose(fid);

st=datestr(PortSlopes(:,3));
fid = fopen('PortR2.txt','wt');
for i=1:size(PortSlopes,1),
fprintf(fid,'%s\t %d\n',st(i,:),PortSlopes(i,4));
end
fclose(fid);


        
        

