
function dataOut = read_M1_pH_daily(buoy,dep)

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

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

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

fmt = ['%d%*c%f %f'];

%get yearday for current time
 dv = datevec(floor(now)+[-1:1]);
 yrday = datenum(dv) - datenum([dv(:,1) ones(3,1) zeros(3,1)]);
 for n=1:length(yrday)
   ys = num2str(yrday(n));
   while length(ys)<3
     ys = ['0' ys];
   end
   d(n).name = [num2str(dv(n,1)) ys];
 end
 clear dv yrday n ys;

%do it
 data=[];
 for n=1:length(d)

   fid = fopen([mydir d(n).name]);
   
   if fid>=0 %specified file has to exist

    %get year from filename
     yr = str2num(d(n).name(1:4));

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

    %read data
     fseek(fid,ft,'bof');
     while ~feof(fid)
       out = fscanf(fid,fmt,[3,Inf])';
       if size(out,2)==3
         data = [data; yr*ones(size(out,1),1) out];
       else
         fgetl(fid); %get the bad line and move to the next line
       end
     end
     fclose(fid);
     clear fid yr ft out ans;

   end

 end
 clear d fmt n;

%format time
 if ~isempty(data)
   dataOut = [datenum([data(:,1) zeros(size(data,1),1) ...
     data(:,2)+data(:,3)/1e5]) data(:,4)];
 else
   dataOut = [];
 end
 clear data;
