%overlaySciData.m

clear;
raw = '2016Sep13';
path =    sprintf('../%s/raw',raw);
outfile = sprintf('../%s/parsed/CPF%s.mat',raw,raw);


MAXi=50000;
fileList = dir(path);
fileList = fileList(~[fileList.isdir]); %remove directories
[junk, sortorder] = sort([fileList.datenum]);
fileList = fileList(sortorder); %list is now in ascending date order
numfiles = numel(fileList);
%In = cell(numfiles,1);
i=1;

P = NaN(numfiles,MAXi);
T = NaN(numfiles,MAXi);
S = NaN(numfiles,MAXi);
FL = NaN(numfiles,MAXi);
BBnm700 = NaN(numfiles,MAXi);
BBnm470 = NaN(numfiles,MAXi);
FLd = NaN(numfiles,MAXi);
O2 = NaN(numfiles,MAXi);
O2d = NaN(numfiles,MAXi);
CPtime = NaN(numfiles,1);

for ii = 1:numfiles
   fp = sprintf('%s/%s',path,fileList(ii).name);
   fprintf('Processing %s\n',fp);
   [cpP,cpT,cpS,flbbFL,flbbBB700,flbbBB470,flbbDepth,optodeO2Conc,optodeDepth,cpDateTimeNum]=parseSciData(fp);
   P(i,:)=cpP;
   T(i,:)=cpT;
   S(i,:)=cpS;
   if(exist('flbbFL'))FL(i,:)=flbbFL;end
   BBnm700(i,:)=flbbBB700;
   BBnm470(i,:)=flbbBB470;
   FLd(i,:)=flbbDepth;
   O2(i,:)=optodeO2Conc;
   O2d(i,:)=optodeDepth;
   CPtime(i)=cpDateTimeNum;
   i=i+1;
end


% figure(1);title('CPF');
% 
% subplot(2,2,1);
% plot(cpT(:),-cpP(:)); hold on
% xlabel('degC'),ylabel('dBar');
% grid on;
% 
% 
% subplot(2,2,2);
% plot(cpS(:),-cpP(:)); hold on
% xlabel('PSU'),ylabel('dBar');
% grid on;
% 
% subplot(2,2,3);
% plot(flbbFL(:),flbbDepth(:)); hold on
% 
% xlabel('flbb'),ylabel('dBar');
% grid on;
% 
% subplot(2,2,4);
% plot(optodeO2Conc(:),optodeDepth(:)); hold on
% 
% xlabel('O2'),ylabel('dBar');
% grid on;


save (outfile);
