function theEpicTime = EP_Time(y, m, d, h, mi, s) % EP_Time -- Epic-time from Matlab date. % EP_Time(theDate) returns the epic-time [time time2] % that corresponds to theDate, a Matlab date-string, % date-number, or date-vector [y m d] or [y m d h mi s]. % See the Matlab "datestr()", "datenum()", and "datevec()" % functions for syntax and restrictions. % EP_Time(y, m, d) and EP_Time(y, m, d, h, mi, s) provide % alternatives for date-vector input. % EP_Time('demo') demonstrates itself. % EP_Time (no argument) shows "help" and demonstrates itself. % Copyright (C) 1997 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 01-Jul-1997 15:54:18. % Note: May 23, 1968 = Julian Day 2,440,000. if nargin < 1, help(mfilename), y = 'demo'; end if strcmp(y, 'demo') y = '23-May-1968'; if exist('begets') begets('EP_Time', 1, y, ep_time(y)) else disp([' ## EP_Time(''' y ''') ==> ' ep_time(y)]) end return end switch nargin case 1 if isstr(y) | length(y) == 1 theDate = datenum(y); elseif length(y) == 3 d = y(3); m = y(2); y = y(1); theDate = datenum(y, m, d); elseif length(y) == 6 s = y(6); mi = y(5); h = y(4); d = y(3); m = y(2); y = y(1); theDate = datenum(y, m, d, h, mi, s); else theDate = y; end case 3 theDate = datenum(y, m, d); case 6 theDate = datenum(y, m, d, h, mi, s); otherwise error(' ## Incorrect number of arguments.') end t0 = datenum(1968, 5, 23) - 2440000; % May 23, 1968. t = theDate - t0; t = [fix(t) rem(t, 1).*24*60*60*1000]; if nargout > 0 theEpicTime = t; else disp(t) end