function [bad,N] = scan_licor_CAPRICORN_2016(dfl,ddd,hhh)
%{
scans licor file for gaps and bad timestamps
%}

% read file
disp(['Reading lic file for hour ',int2str(hhh)]);
flist = fopen(dfl,'r');
temp = {};
z = [];
bad=[];
while feof(flist)==0,
    try    % read file into cell array. temp is 1x8 cell array
        temp = textscan(flist,'%2f%2f%3f %f %f %f %f %f %*[^\n]','delimiter', ', ','headerlines', 1,'emptyvalue',NaN,'treatAsEmpty','Overflow');
        z = [z cell2mat(temp)'];
    catch
        for ii=1:8  % length of last cell reflects missing values from any/all fields
            if length(temp{1,ii})~=length(temp{1,8})
                temp{1,ii}(length(temp{1,8})+1)=[]; %truncate length of all cells to length(temp{1,8})
            end;
        end;
        if ~isempty(temp{1,1})
            z=[z cell2mat(temp)'];
        end;
    end;
end;
fclose(flist);
z(:,any(isnan(z(1,:)),1))=[]; % kill lines beginning with NaN
tlic =  ddd + (hhh + (z(1,:)+(z(2,:)+z(3,:)/1000)/60)/60)/24;
N = length(tlic);
% compute delta T and scan for jumps > 0.25 seconds
dt = diff((tlic-floor(tlic(1)))*86400);
ii = find(dt>0.25);
jj = length(find(dt<0.05)); % # points from rapid buffer dumps
if ~isempty(ii)
    hours = floor((tlic(ii)-floor(tlic(1)))*24);
    bad = [tlic(ii)',hours',dt(ii)',ones(length(ii),1)*length(tlic),ones(length(ii),1)*jj];
end;
