File size: 2,495 Bytes
5ab75a9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | function [LS] = LeapSeconds(EpochUTC)
%
% LeapSeconds - This function determines the correct number of leap seconds
% based on a particular epoch (UTC). Leap Seconds is the count
% between UTC and TAI. Leap Seconds count remains constant until
% changed.
%
% Syntax: [LS] = LeapSeconds(EpochUTC)
%
% Inputs:
% EpochUTC - Epoch (UTC). Format: 'yyyy-mm-dd HH:MM:SS.FFF'
% (Other formats also work; basically any format which is
% supported by Matlab's datenum routine)
%
% Outputs:
% LS - Number of leap seconds based on the epoch.
%
% Examples/Validation Cases:
%
% Other m-files required: None
% Subfunctions: None
% MAT-files required: LeapSeconds.mat
% Global variables: None
%
% See also: None
%
% July 2015; Last revision: 18-Oct-2022
%
% ----------------- BEGIN CODE -----------------
% Leap seconds data
persistent LeapSecInfo;
if (isempty(LeapSecInfo))
% Get leap second info from a .mat file (LeapSeconds.mat)
[p,~,~] = fileparts(mfilename('fullpath'));
leapSecFile = fullfile(p, '../../../DataFiles/TimeCons/LeapSeconds.mat');
load(leapSecFile,'LeapSecInfo');
end
% Matlab date number of the UTC epoch
EpochUTC = datenum(EpochUTC);
% The above leap-second dates expressed as Matlab date number
LeapSecDateNum = datenum(LeapSecInfo(:,1:3));
% Concurrent number of leap seconds at the above dates
LeapSecCount = LeapSecInfo(:,4);
% Choose proper leap second count based on UTC epoch
id = LeapSecDateNum <= EpochUTC;
% Check for out-of-range UTC epoch
if (sum(id) == 0)
error('EpochUTC must be >= 1972-01-01 00:00:00.000 UTC. \n');
else
LS = LeapSecCount(sum(id));
end
return
% ----------------- END OF CODE ------------------
%
% Please record any changes to the software in the change history
% shown below:
%
%---------------- CHANGE HISTORY ------------------
% Developer | Date | Description
%--------------------------------------------------
% D. Plakalovic | 07-13-2015 | Re-coded this function from the original
% version (Feb 2013). Inserted additional
% functionality.
% L. Baars | 10-18-2022 | Updated to account for new LeapSecInfo
% file location. |