function [y, m, d, sec] = Gps_to_sec(gps_week, gps_sec) % Function converts gps time (week, sec) into date year, month, day and sec since midnight % [y, m, d, sec] = Gps_to_sec(gps_week, gps_sec) % input: gps week, gps sec % output: year(4digit), month, day, sec since midnight % David Benson % 7/5/01 %Program modified to solve incorrect output when month > January %Paige Sturtevant %1/31/2002 jd = 7 * gps_week + gps_sec / 86400 + 2444245; l = floor(jd) + 68569; n = floor(( 4 * l ) / 146097); l = l - floor(( 146097 * n + 3 ) / 4); i = floor(( 4000 * ( l + 1 ) ) / 1461001); l = l - floor(( 1461 * i ) / 4) + 31; j = floor(( 80 * l ) / 2447); d = l - floor(( 2447 * j ) / 80); L = j / 11; m = j + 2 - floor(( 12 * L )); y = 100 * ( n - 49 ) + i + L; y = floor(y); %added 1/31/2002 if m > 1 %changed to a 1 instead of a 2 - 1/31/2002 m = m+1; %added 1/31/2002 M = m; Y = y; else M = m + 12; Y = y - 1; end JD = fix(365.25*Y) + fix(30.6001*(M+1)) + d + 1720982; sec = round((jd - JD) * 86400); %This section added 1/31/2001 %The month does not seem to increment correctly after January,... %...this section solves that problem if sec > 86400 exdays = floor(sec/86400); exm = round(exdays/30); m = m+exm; sec = sec-exdays*86400; end