

%dirs.k0 = '\\atlas\chem\DuraFET\K0 for DSD Stems\';
%:dirs.PTraw = '\\atlas\chem\DuraFET\PTchamber\RawData\';
dirs.final = '\\atlas\chem\DuraFET\PTchamber\ProcessedData\';
dirs.temp  = 'C:\temp\';
% 
% GET LIST OF MBARI PROCESSED pH CALIBRATION FILES
d    = dir([dirs.final,'*xls*']);
tmp  = {d.name}';
tf   = ~cellfun(@isempty, regexp(tmp,'mDF\#\d+','once'));
list = tmp(tf);
clear d tmp tf

hdr = {'file name' 'DF SN' 'MSC SN' 'PTstart' 'PTstop' 'k0start' 'k0stop'};
out = cell(1000, size(hdr,2));

for ct = 1: size(list,1)
    fn    = list{ct};
    disp(fn)
    DF_SN = regexp(fn,'\d+','once','match');
    copyfile([dirs.final,fn], dirs.temp)
    tmp   = readcell([dirs.temp,fn],'Sheet','Summary','Range','A1:H15', ...
        'DatetimeType','text');
    
    %FIND START & STOP TIMES
    % colum indice to find time window in
    Cind    = find(strncmp(tmp(1,:),'Ver',3) == 1); 
    PTrow   = strcmp(tmp(:,Cind),'PT Chamber:');
    K0row   = strcmp(tmp(:,Cind),'SW cal:');
    PTstart = tmp{PTrow, Cind+1};
    PTstop  = tmp{PTrow, Cind+2};
    K0start = tmp{K0row, Cind+1};
    k0stop  = tmp{K0row, Cind+2};  
    
    %FIND LISTED MSC (BUT DON'T BELIEVE UNTIL VERIFIED)
    %Sometimes ID = MCS instead of MSC
    MSCrow = strcmp(tmp(:,Cind+1),'MSC Logger');
    if sum(MSCrow) == 0
        MSCrow = strcmp(tmp(:,Cind+1),'MCS Logger');
    end
        
    MSC    = tmp{MSCrow, Cind+2};  
    
    
    %hdr = {'file name' 'DF SN' 'MSC SN' 'PTstart' 'PTstop' 'k0start' 'k0stop'};
    out(ct,:) ={fn, DF_SN, MSC, PTstart, PTstop, K0start, k0stop};
    
    clear DF_SN MSC PTstart PTstop K0start k0stop tmp
    delete([dirs.temp,fn]);
end
out = out(1:ct,:);