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

    1-3   jd_ref      timestamp
    4   lat         latitude deg, N positive
    5   lon         longitude deg, E positive
    6   sogm        gps speed over ground, m/s
    7   imrh        RH humidity, g/kg
    8   imta        Air temp, C
    9   lrg        heading, deg
    10  imum        true wind speed, m/s
    11   imdm        true wind direction, deg
    12   imPress     air pressure, mb
    13   imqa    specific humidity, g/kg


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

fclose all;
%yyyy = '2019';
scsm = zeros(144,12)*NaN;
delta = double(1/144);
last = ddd + 144*delta;
jd_ref = ddd:delta:last;	% ref 1 Hz timestamp
jd_ref = jd_ref';
scsm(:,1) = jd_ref(1:end-1);
jd = sprintf('%03i',ddd);

for hhh = 0:23              % cycle thru 24 hourly gprm files
    hr = sprintf('%02i',hhh);
    df1 = fullfile(path_working_ddd,['scs0' yyyy(3:4),jd,hr,'_raw.txt']);
    if exist(df1,'file')==2
    scs = auto_read_scs_WHOTS_2019(df1,ddd,hhh,PosLims);
    else
        continue % no data this hour
    end
     [df1_n, df1_e] = pol2cart(df1(:,2)*pi/180,1);  % N/E heading components
    df1 = [df1,df1_n,df1_e]; % add N/E components as cols 4,5
    
    jd_scs = scs(:,1);
    ii = find(abs(jd_ref-jd_scs(1))<double(0.5/3600));
    scsm(ii:ii+3599,2:10) = scs(:,2:10);
    jdmet = scs(:,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
            scsm(idx,2:10) = scs(jj,2:10);
        end;
    end;
end;
