
function dataOut = read_M1_CO2_full(buoy,dep)

% You must specify buoy as 'm1-slave1', not 'm1'

% The number of columns in the CO2 output changes several times, so you
%  can't use fscanf() - have to read line-by-line instead. This still works
%  b/c first few, and last few columns don't ever change, so can reference
%  from beg/end of line.

% This script is for 'm1-slave1'. The 'm1' data output is different:
%  'm1' files have a field for 'I', 'C', or '' (blank)
%  'C' = calibration (or zero)
%  'I' = pump ON

if ispc
  pre = '//atlas.shore.mbari.org/';
else
  pre = '/Volumes/';
end

mydir = [pre 'oasis_coredata/deployments/' ...
  buoy '/' dep '/' buoy '/'];

fid = fopen([mydir 'data/pco2']);

%skip header
 hd='#';
 while ~isempty(strfind(hd,'#'))
   ft=ftell(fid);
   hd=fgetl(fid);
 end
 clear hd;

%pre-allocate for speed
 fseek(fid,ft,'bof');
 ct=0;
 while ~feof(fid)
   fgetl(fid);
   ct=ct+1;
 end

%read data
 fseek(fid,ft,'bof');
 data=NaN(ct,6);
 for n=1:ct
   s = sscanf(fgetl(fid), '%f')'; %3-5x faster than str2num
   if length(s)>=6 %else an incomplete line (should actually be 10?)
     data(n,:) = s([end 1:4 end-1]);
   end
 end
 fclose(fid);
 clear fid ft ct n s ans;

%get rid of incomplete lines from pre-allocating
 data(isnan(data(:,1)),:)=[];

%format time
 dataOut = [datenum([data(:,1) zeros(length(data),1) ...
   data(:,2)]) data(:,3:end)];
 clear data;
