function varargout = tok
%  TOK ends the timer, and uses the builtin clock function to get an
%  exact measurement of the current time when the function is run.  It then
%  loads up the value stored by function TIK, and subtracts the two times, to get
%  the elapsed time.
% 
%  Record of Revisions
%   Date             Programmer            Description of Change
%   ====             ==========            =====================
%  4/11/12            X          				Original Code 
%
%  Define Variables
%  p2      --  Current time when tok was run
%  p1      --  Time when tik was run
%  p3      --  Elapsed time ignoring days, between the running of tik and tok
%  days      --  Elapsed days in secs between the running of tik and tok
%  totsec  --  Elapsed time between the running of tik and tok in seconds
%

% Setting p2 as the current time
p2 = clock;

% Loading tik and then taking the time that tok was run- the time that tik
% was run to determine the elapsed time.
load tik;

% Converting the elapsed days into seconds
days = (datenum(p1(:,1:3))- datenum(p1(:,1:3)))* 86400;

p3= p2(:,4:6)-p1(:,4:6);
hours = p3(1)* 3600;
minutes = p3(2)* 60;
seconds = p3(3);

% Adding up the total elapsed time in seconds
totsec = days + hours + minutes + seconds;

% Calculating the elapsed time 
day = fix(totsec/86400);

hour = fix( mod(totsec,86400)/3600);
minute = fix( mod(mod(totsec,86400),3600)/60);
second = mod( mod( mod(totsec,86400),3600),60);

varargout{ 1 } = p2 - p1;
for i = 2 : nargout
    varargout{ i } = [];
end
end