function SN = GetGliderSN(s, mission, DepLog)
% Returns the serial number for the Glider. First try extracting from the
% mission name and if that fails for some reason then check if it is in the
% s struct. If that fails then make nan array.
% Ben Werb 6/4/24

try
    % First method: parse from name
    SN = num2str(mission); % works on both doubles and strings
    SN = SN(5:6);
    SN = str2double(SN);
catch
    try
        % Second method: check the s struct
        SN = str2double(s.sn);
    catch
        try
            % Third method: read in deployment log
            idx = ismember(DepLog.("Deployment ID"),mission) &...
            DepLog.("Date Deployed").Day == datetime(datevec(s.sdn_start)).Day;
            SN = DepLog.GliderID(idx);
        catch
            % If all methods fail, assign NaNs
            SN = NaN(length(s.lat), 1);
        end
    end
end
SN = repmat(SN,length(s.sdn),1);
end