function [hmt1, hmt1_1min] = read_hmt335_2023(dfl)
%{
    input parameter: dfl = string path to hmt1 file

    reads HMT335 files (hmt1YYDDDHH_raw.txt), returns raw and 
    1 min avg tables with the following variables:

        1   dnum            timestamp, matlab datenum
        2   dt              matlab datetime timestamp
        3   rh              relative humidity, %
        4   ta              air temperature, °C
%}

%% initialize
temp = {};

[~,fname,~] = fileparts(dfl);
yyyy = 2000 + str2double(fname(5:6));
ddd = str2double(fname(7:9));
hh = str2double(fname(10:11));

start = datenum(yyyy-1,12,31)+(ddd+hh/24);
stop = start + 1/24;
delta1 = double(1.0/1440);
bins1 = start:delta1:stop; bins1 = bins1(:);
% format string to read hmt0 data
fmt_str = '%2f%2f%3f %f %f %*[^\n]';
% variable names for output table
vars = {'dnum','rh','ta'};

%% read hmt0 file
disp(['Reading ',fname]);
flist = fopen(dfl,'r');
try
    temp = textscan(flist,fmt_str,'MultipleDelimsAsOne',1,'Delimiter',' ,',...
                    'headerlines',1);
    raw = cell2mat(temp);
catch % on scan error, stop and show line number for bad data
    [r,~] = size(temp{1,1});
    error(['read error ',fname,' line ',sprintf('%i',r+2)]);
end
fclose(flist);

%% build raw table
% compute raw timestamp
dnum = datenum(yyyy-1,12,31);
dnum = dnum + (ddd+(hh+(raw(:,1)+(raw(:,2)+raw(:,3)/1000)/60)/60)/24);
dt = datetime(dnum,'ConvertFrom','datenum');

raw = [dnum,raw(:,4:5)];
hmt1 = array2table(raw,'VariableNames',vars);
hmt1 = addvars(hmt1,dt,'Before','rh');

%% prepare 1m average output
temp = interval_avg(raw(:,1),raw(:,2:3),bins1);
dt = datetime(temp(:,1),'ConvertFrom','datenum');
hmt1_1min = array2table(temp,'VariableNames',vars);
hmt1_1min = addvars(hmt1_1min,dt,'Before','rh');

end
