function [hmt0, hmt0_1min] = read_hmt337_2023(dfl)
%{
    input parameter: dfl = string path to hmt0 file

    reads HMT337 files (hmt0YYDDDHH_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
        5   tdf             frost point temperature, °C
        6   td              dew point, °C
        7   ah              absolute humidity, g/m3
        8   qa              specific humidity, g/kg
        9   tw              wet bulb temperature, °C
        10  h2o             water vapor mole fraction, umole/mole
        11  pw              water vapor pressure, hPa
        12  pws             water vapor saturation pressure, hPa
        13  h               enthalpy, kJ/kg
        14  dta_td          ta - td temperature difference, °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 %*3c%f %*7c%f %*8c%f %*7c%f %*6c%f ',...
    '%*10c%f %*10c%f %*8c%f %*8c%f %*9c%f %*7c%f %*11c%f %*[^\n]'];
% variable names for output table
vars = {'dnum','rh','ta','tdf','td','ah','qa','tw','h2o','pw','pws',...
        'h','dta_td'};

%% read hmt0 file
disp(['Reading ',fname]);
flist = fopen(dfl,'r');
try
    temp = textscan(flist,fmt_str,'MultipleDelimsAsOne',1,'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:15)];
hmt0 = array2table(raw,'VariableNames',vars);
hmt0 = addvars(hmt0,dt,'Before','rh');

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

end
