global d;
d=dir ('plan-*');

for i=1:size(d,1)
    cd (d(i).name);
    op = dir ('*-optodes');
    cd (op.name)
    RefOptodes();
end


cd MatlabData
l=dir('*RefOnly.mat');

RefDataArray=ones(size(l,1)-1,6);

for i=1:size(l,1)-1
    load(l(i).name);
    RefDataArray(i,:)=RefData;
    
end
%%%% RefData=[mean(port_refAveConc),std(port_refAveConc),port_refAveConc(1),
%%%% datenum(port_refAveTime(1,1)),datenum(port_refAveTime(end,1)), 
%%%% port_refElapsedTime(end)];

figure;
plot(RefDataArray(:,4),RefDataArray(:,1),'rx');
datetick('x','mmmyyyy','keepticks','keeplimits')
legend('Ref')
xlabel('Date');ylabel('Mean O2 Conc. (um/hr)');
saveas(gcf,strcat('RefOptode_Mean','.tiff'));

figure;errorbar(RefDataArray(:,4),RefDataArray(:,1),RefDataArray(:,2),'x')
datetick('x','mmmyyyy','keepticks','keeplimits')
legend('Reference Optode')
xlabel('Date');ylabel('Mean 02 Conc');

figure;bar(RefDataArray(:,4),RefDataArray(:,1));
hold on;
errorbar(RefDataArray(:,4),RefDataArray(:,1),RefDataArray(:,2),'LineStyle','none' );
YLIM([130 145]);
datetick('x','mmmyyyy','keepticks','keeplimits')
legend('Reference Optode')
xlabel('Date');ylabel('Std Dev Ref Optode (umol)');


figure;hist(RefDataArray(:,2));
xlabel('Ref Optode Std Dev')
ylabel('Frequency')


fid = fopen('RefData.txt','wt');fprintf(fid,'Date Mean  STD\n');
for i=1:size(RefDataArray,1),
    
fprintf(fid,'%s\t %d\t %d\n',datestr(RefDataArray(i,4)),RefDataArray(i,1),RefDataArray(i,2));
end
fclose(fid);
