% determine whether there is a file called [file, '.log] 
%   - older log files only have integer seconds (hence two columns)
%   - newer log files have three columns, [unix_secs unix_msec offset];
logfile = [file, '.log'];
%get unix_seconds and offsets
if exist(logfile , 'file')   
   log_info = load(logfile);
   if (length(log_info(1,:)) == 3)
      unixsecs = log_info(:,1) + log_info(:,2)/100;
      offsets = log_info(:,3);
   elseif (length(log_info(1,:)) == 2)
      unixsecs = log_info(:,1);
      offsets = log_info(:,2);
   else
      error(sprintf('logfile %s does not have correct number of columns\n',...
                    logfile))
   end
   %NOTE - some timestamps may be missing from the log file due to limitations
   % in baud rage and serial logging.  Fill in unix seconds from offsets in log
   % file using the assumption that pings have the same size in a file.  Fit
   % the time correction to unix seconds using the same indices extracted
   % by ilist; then smooth the result.
   unixdday = (unixsecs + to_sec(1970, 1, 1, 0, 0, 0) - ...
               to_sec(cfg.yearbase, 1, 1, 0, 0, 0))/86400;
   bytecount = min(diff(offsets)); %offsets should increment by this each time
   hypothetical_offsets = ([1:last_index]-1)*bytecount; %if all were recorded
   hypothetical_unixdday = table1([unixdday offsets],hypothetical_offsets);
   coef = polyfit(d.dday, hypothetical_unixdday(ilist), 1);
   d.dday = polyval(coef, d.dday);
end
% run a 5-pt boxfilt on the time differences
dt = boxfilt(diff(d.dday),5);
oldddaymean = mean(d.dday);   %want mean of times to match
newdday = d.dday(1) + cumsum([0; dt]);
d.dday = newdday - mean(newdday) + oldddaymean;

