function scs = read_scs_day_WHOTS_2022(path_working_ddd,ddd,yyyy,PosLims)
%{
    Reads hourly scs files for one day and returns table with the
    following columns:

    1   jd_ref      1 Hz timestamp
    2   lat         latitude deg, N positive
    3   lon         longitude deg, E positive
    4   sog         gps speed over ground, m/s
    5   cog         gps course over ground, deg
    6   lrg         heading, deg
    7   imta        Air temp, C
    8   imrh        RH humidity, g/kg
    9   imPress     air pressure, mb
    10  imqa        specific humidity, g/kg
    11  imdm        true wind direction, deg
    12  rmdm        relative wind direction, deg
    13  imum        true wind speed, m/s
    14  rmum        relative wind speed, m/s
    15  tsg1m       sst1, C
    16  tsg2m       sst2, C
    17  tssm        salinity, %


    input parameters: path_working_ddd = path to daily data folder
                      ddd = julian date
                      yyyy = year string
                      PosLims = lat/lon limits for filtering position data
%}

%% initialize
fclose all;

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

for hhh = 0:23              % cycle thru 24 hourly scs files
    HR = sprintf('%02i',hhh);
    dfl = fullfile(path_working_ddd,['scs0' YYYY(3:4),JD,HR,'_raw.txt']);
    if exist(dfl,'file')==2
        scs = read_scs_WHOTS_2022(dfl,ddd,hhh,PosLims);
        scsm = table2array(scs);
    else
        continue % no data this hour
    end
    
    dfl = fullfile(path_working_ddd,['sst0' YYYY(3:4),JD,HR,'_raw.txt']);
    if exist(dfl,'file')==2
        sst = read_sst_WHOTS_2022(dfl,ddd,hhh);
        sstm = table2array(sst);
    else
        continue % no data this hour
    end
    
    %merge
    scsm=[scsm sstm(:,2:end)];
    
    
    jd_scs = scsm(:,1);
    % match jd_scs to closest jd_ref and copy data over
    % this preserves gaps in data as NaNs in scsm
    for ii=1:6
        [~,zz] = min(abs(jd_scs(ii) - jd_ref));
        scsmm(zz,2:17) = scsm(ii,2:17);
    end
end

% output table
vars = {'jd','lat','lon','sog','cog','hed','ta','rh','Pmb','qa','wspd','wdir','rwspd','rwdir','sst1','sst2','sal'};
scs = array2table(scsmm,'VariableNames',vars);

end

