function hdt = read_hdt(ddd,dfl_hdt)

%{
    reads daily TGT GYRO-01-HDT-RAW files
    
    input:  ddd = day of year variable
            dfl_hdt = full path string to file
%}

%% reference 1 Hz timestamp
disp(['Reading HEHDT file for jd ',int2str(ddd)]);
jd_ref = ddd:1/86400:ddd+1-1/86400; jd_ref = jd_ref(:);

%% read data if file exists, if not return NaNs
if exist(dfl_hdt,'file')==2
    %% read file
    flist = fopen(dfl_hdt);
    temp = {};    % empty arrays for textscan
    stx = [];

    while feof(flist)==0    % read entire file into cell array
        try
            % temp will be 1x11 cell array, cells will be ~36000x1 arrays
            temp = textscan(flist,'%2f/%2f/%4f %2f:%2f:%6.3f %*6c %f %*[^\n]','delimiter',',','headerlines',0,'emptyvalue',NaN);
            stx = [stx cell2mat(temp)'];  % 7x~86400 array
        catch
            for ii=1:7      % length of last cell reflects missing values from any/all fields
                 if length(temp{1,ii})~=length(temp{1,7})
                     temp{1,ii}(length(temp{1,7})+1)=[];  %truncate length of all cells to length(temp{1,11})
                 end
            end
            if ~isempty(temp{1,1})  % save good values from last read, if any
                stx = [stx cell2mat(temp)'];
            end
        end
    end
    fclose(flist);
    stx = stx';
    jd_hdt = md2yd_vn(stx(:,3),stx(:,1),stx(:,2));
    jd_hdt = jd_hdt + stx(:,4)/24 + stx(:,5)/1440 + stx(:,6)/86400;
    
    %% copy to 1 Hz array
    hdt = NaN(86400,2);
    hdt(:,1) = jd_ref;
    for xx=1:length(jd_hdt)
        [~,zz] = min(abs(jd_ref - jd_hdt(xx)));
        hdt(zz,2) = stx(xx,7);
    end
    
    % fill in 1Hz array
    kk = jd_ref>=jd_hdt(1) & jd_ref<=jd_hdt(end);
    hdt(kk,2) = replace_NaN_nearest_neighbor(hdt(kk,2));
    
else
    %% return NaN array if file not found
    hdt = NaN(86400,2);
    hdt(:,1) = jd_ref;
end

end