function [gpsWeek, gpsSec] = utc2gps(n)
% utc2gps : Convert UTC time to GPS time expressed in GPS week and GPS
%           second of week.
%
%
% INPUTS
%
% n -------------- The UTC time and date expressed as a Matlab datenum.  Use
%                  the Matlab function datenum() to generate n; use datestr()
%                  to render n in a standard format.
%
%
% OUTPUTS
%
% gpsWeek -------- The unambiguous GPS week number where zero corresponds to
%                  midnight on the evening of 5 January/morning of 6 January,
%                  1980.  By unambiguous is meant the full week count since
%                  the 1980 reference time (no rollover at 1024 weeks).
%
% gpsSec --------- The GPS time of week expressed as GPS seconds from midnight
%                  on Saturday.
%
%+------------------------------------------------------------------------------+
% References:
%
%
% Author:  Todd Humphreys
%+==============================================================================+

leapSeconds = getLeapSecondsUTC(n);
nref = datenum(1980,1,6,0,0,0);
dn = n - nref;
gpsWeek = floor(dn/7);
gpsSec = (dn - gpsWeek*7)*86400 + leapSeconds;
