function met = read_met_day_WHOTS_2022(path_working_ddd,ddd,yyyy,adj)
%{
Reads hourly met files for one day and retunrs 10-min averages
Loops through 24 hours, calling read_met_WHOTS_2021 for each hour

Inputs: path_working_ddd: path to daily folder containing hourly files
        ddd: day-of-year variable
        yyyy: year variable
        adj: temperature adjustments array, 1x7, [tsea,tair1,tair2,td1,tc1,td2,tc2]

Output: metm: 144x27 table of bulk met data with the following variables
        Returns NaN for data gaps

        1   jd_met          10 min timestamp, decimal DOY @ start of interval
        2   Tsea            sea snake surface SST
        3   psp1            psp1 radiation, W/m2
        4   pir1            pir1 radiation, W/m2
        5   psp2            psp2 radiation, W/m2
        6   pir2            pir2 radiation, W/m2
        7   Tc1             pir1 case temperature
        8   Td1             pir1 dome temperature
        9   Tc2             pir2 case temperature
        10  Td2             pir2 dome temperature
        11  Pmb             vaisala pressure from mean2 box (no height adjustment)
        12  rwdir_wxt1      rel wind direction, WXT1, 0-360 deg from bow
        13  rwspd_wxt1      rel wind speed, WXT1, m/s
        14  Tair_wxt1       air temperature, WXT1, C
        15  RH_wxt1         RH, WXT1, %
        16  Pmb_wxt1        air pressure, WXT1, mb or hPa
        17  rain_wxt1       rain rate, WXT1, mm/hr
        18  U_wxt1          U (bow-stern) wind component/0.95, WXT1
        19  V_wxt1          V (port-stbd) wind component/1.15, WXT1
        20  rwdir_wxt2      rel wind direction, WXT2, 0-360 deg from bow
        21  rwspd_wxt2      rel wind speed, WXT2, m/s
        22  Tair_wxt2       air temperature, WXT2, C
        23  RH_wxt2         RH, WXT2, %
        24  Pmb_wxt2        air pressure, WXT2, mb or hPa
        25  rain_wxt2       rain rate, WXT2, mm/hr
        26  U_wxt2          U (bow-stern) wind component/0.95, WXT2
        27  V_wxt2          V (port-stbd) wind component/1.15, WXT2
        28  std_rwdir1      std dev of wxt1 1-min rwdir
        29  std_rwdir2      std dev of wxt2 1-min rwdir
%}

%% initialize
fclose all;

metmm = NaN(144,29);
delta = double(10/1440);
last = ddd + 143*delta;
jd_ref = ddd:delta:last;	% ref 10-min timestamp
metmm(:,1) = jd_ref';
JD = sprintf('%03i',ddd);
YYYY = sprintf('%04i',yyyy);

%% read hourly files and concatenate to output array
for hhh = 0:23              % cycle thru 24 hourly met files
    HR = sprintf('%02i',hhh);
    dfl1 = fullfile(path_working_ddd,['me0' YYYY(3:4),JD,HR,'_raw.txt']);
    dfl2 = fullfile(path_working_ddd,['wxp1' YYYY(3:4),JD,HR,'_raw.txt']);
    dfl3 = fullfile(path_working_ddd,['wxp2' YYYY(3:4),JD,HR,'_raw.txt']);
    % read this hours 10-min avg data from both systems if files exist
    % met10m is 6x27 array
    if exist(dfl1,'file')==2 && exist(dfl2,'file')==2 && exist(dfl3,'file')==2
        [~, met10]= read_met_WHOTS_2022(dfl1,dfl2,dfl3,ddd,hhh,adj);
        met10m = table2array(met10);
    else
        continue % no data this hour
    end
    jdmet = met10m(:,1);
    % copy this hours data into metm array
    for jj = 1:length(jdmet)
        diff = jd_ref - jdmet(jj);
        [val,idx] = min(abs(diff));
        % allow 2 sec tolerance for timestamp match
        if val<double(2.0/86400) && length(idx)==1
            metmm(idx,2:29) = met10m(jj,2:29);
        end
    end
end

% output table
vars = met10.Properties.VariableNames; % get var names from last met10 table
met = array2table(metmm,'VariableNames',vars);

end
