function sst = read_sst_WHOTS_2022(dfl,ddd,hh)
%{
    reads sst from parsed scs file specified by dfl and returns 10-min table with the
    following variables:

    1   jd_ref      1 Hz timestamp
    2   sst1        sea temperature 1
    3   sst2        sea temperature 2
    4   sal         salinity
    
    input parameters: dfl = string path to scs file
                      ddd = julian date
                      hhh = hour
%}

%% open file and read
disp(['Reading sst file for hour ',int2str(hh)]);
flist = fopen(dfl,'r');
N = 9; % columns of data in raw file
tempsst = {};
sstm = [];
%%read file
while feof(flist)==0
    try
        % temp will be 1x 16 cell array, cells will be 3600 x 1 arrays
        %         07/21/2022 21:00 Sette SCS met and nav (SN: 999)
% 0000888 2022-07-24 00:00:01.017Z, 97fbf243-232b-4b62-8f12-e23adca9f73a, t1= 26.1126, c1= 5.46064, s= 35.2689, sv=1536.923, t2= 25.9373
% 0002038 2022-07-24 00:00:02.053Z, 97fbf243-232b-4b62-8f12-e23adca9f73a, t1= 26.1117, c1= 5.46067, s= 35.2698, sv=1536.924, t2= 25.9373
        tempsst = textscan(flist,'%2f%2f%3f %*f-%*f-%*f %*f:%*f:%*f %*3c%f %*3c%f %*3c%f %*3c%f %*3c%f %*3c%f %*[^\n]',...
            'delimiter',',','headerlines',0,'treatasempty',{'?????','-Unknown-','97fbf243-232b-4b62-8f12-e23adca9f73a'});
        sstm = [sstm cell2mat(tempsst)'];
    catch
        %[lnr2,~] = size(temp{1,N});
        for ll=1:N
            if length(tempsst{1,ll})~=length(tempsst{1,N})
                tempsst{1,ll}(length(tempsst{1,N})+1)=[];
            end
        end
        fgetl(flist);  %excess remaining junk line
        if ~isempty(tempsst{1,1})
            sstm = [sstm cell2mat(tempsst)'];
        end
    end
end
fclose(flist);

ii = isinf(sstm); sstm(ii) = NaN;

%% define raw variables
jd_sst =  ddd + (hh + (sstm(1,:)+(sstm(2,:)+sstm(3,:)/1000)/60)/60)/24;
tsg1m =  sstm(5,:);          % 
tssm =   sstm(7,:);
tsg2m=   sstm(9,:);          


%% check for unreasonable values
tssm(tssm>40) = NaN;
tssm(tssm<25) = NaN;
tsg1m(tsg1m>50) = NaN;
tsg1m(tsg1m<-2) = NaN;
tsg2m(tsg2m>50) = NaN;
tsg2m(tsg2m<-2) = NaN;

%% despike and replace NaNs with nearest neighbor
[tssm,~] = despike2(tssm);
[tsg1m,~] = despike2(tsg1m);
[tsg2m,~] = despike2(tsg2m);

%% rebuild raw array in output format
sstm = [jd_sst',tsg1m',tsg2m',tssm'];
[~,c]=size(sstm);

%% average to 10 min
start = (ddd+hh/24);

delta = double(10/1440);
last = start + 6*delta;
tref = start:delta:last;

sst10m = interval_avg(jd_sst',sstm(:,2:c),tref');


%% output table
vars = {'jd','sst1','sst2','sss'};
sst = array2table(sst10m,'VariableNames',vars);

end

