annotate DL/RLS-DLA/private/timerinit.m @ 63:e08af264ef93

(none)
author idamnjanovic
date Tue, 15 Mar 2011 12:23:35 +0000
parents ad36f80e2ccf
children
rev   line source
idamnjanovic@60 1 function tid = timerinit(par1,par2)
idamnjanovic@60 2 %TIMERINIT Initialize a new timer.
idamnjanovic@60 3 % TID = TIMERINIT() initializes a new timer for counting elapsed time,
idamnjanovic@60 4 % and returns its id.
idamnjanovic@60 5 %
idamnjanovic@60 6 % TID = TIMERINIT('TIMERNAME') sets the timer name to the specified
idamnjanovic@60 7 % string for display purposes.
idamnjanovic@60 8 %
idamnjanovic@60 9 % TID = TIMERINIT(ITERNUM) initializes a new ETA timer for a process with
idamnjanovic@60 10 % ITERNUM iterations. An ETA timer can be used for both counting elapsed
idamnjanovic@60 11 % time and estimating remaining time.
idamnjanovic@60 12 %
idamnjanovic@60 13 % TID = TIMERINIT('TIMERNAME',ITERNUM) sets the ETA timer name to the
idamnjanovic@60 14 % specified string for display purposes.
idamnjanovic@60 15 %
idamnjanovic@60 16 % Example:
idamnjanovic@60 17 %
idamnjanovic@60 18 % tid = timerinit(100);
idamnjanovic@60 19 % for i = 1:100
idamnjanovic@60 20 % pause(0.07);
idamnjanovic@60 21 % timereta(tid,i,1);
idamnjanovic@60 22 % end
idamnjanovic@60 23 % timereta(tid,i);
idamnjanovic@60 24 %
idamnjanovic@60 25 % See also TIMERETA, TIMERCLEAR.
idamnjanovic@60 26
idamnjanovic@60 27
idamnjanovic@60 28 % Ron Rubinstein
idamnjanovic@60 29 % Computer Science Department
idamnjanovic@60 30 % Technion, Haifa 32000 Israel
idamnjanovic@60 31 % ronrubin@cs
idamnjanovic@60 32 %
idamnjanovic@60 33 % June 2008
idamnjanovic@60 34
idamnjanovic@60 35
idamnjanovic@60 36 global utiltbx_timer_start_times % start times
idamnjanovic@60 37 global utiltbx_time_lastdisp % last display times
idamnjanovic@60 38 global utiltbx_timer_iternums % iteration numbers
idamnjanovic@60 39 global utiltbx_timer_lastiter % last queried iteration numbers
idamnjanovic@60 40 global utiltbx_timer_name % timer names
idamnjanovic@60 41 global utiltbx_timer_callfun % timer calling functions
idamnjanovic@60 42
idamnjanovic@60 43
idamnjanovic@60 44 % parse function arguments %
idamnjanovic@60 45
idamnjanovic@60 46 if (nargin==0)
idamnjanovic@60 47
idamnjanovic@60 48 iternum = -1;
idamnjanovic@60 49 timername = '';
idamnjanovic@60 50
idamnjanovic@60 51 elseif (nargin==1)
idamnjanovic@60 52
idamnjanovic@60 53 if (ischar(par1))
idamnjanovic@60 54 iternum = -1;
idamnjanovic@60 55 timername = par1;
idamnjanovic@60 56
idamnjanovic@60 57 elseif (isnumeric(par1) && numel(par1)==1 && par1>0)
idamnjanovic@60 58 iternum = par1;
idamnjanovic@60 59 timername = '';
idamnjanovic@60 60
idamnjanovic@60 61 else
idamnjanovic@60 62 error('Invalid number of iterations');
idamnjanovic@60 63 end
idamnjanovic@60 64
idamnjanovic@60 65 elseif (nargin==2)
idamnjanovic@60 66
idamnjanovic@60 67 if (ischar(par1) && isnumeric(par2))
idamnjanovic@60 68 if (numel(par2)==1 && par2>0)
idamnjanovic@60 69 timername = par1;
idamnjanovic@60 70 iternum = par2;
idamnjanovic@60 71 else
idamnjanovic@60 72 error('Invalid number of iterations');
idamnjanovic@60 73 end
idamnjanovic@60 74 else
idamnjanovic@60 75 error('Invalid function syntax');
idamnjanovic@60 76 end
idamnjanovic@60 77
idamnjanovic@60 78 else
idamnjanovic@60 79 error('Too many function parameters');
idamnjanovic@60 80 end
idamnjanovic@60 81
idamnjanovic@60 82
idamnjanovic@60 83 % register the timer %
idamnjanovic@60 84
idamnjanovic@60 85 if (isempty(utiltbx_timer_start_times))
idamnjanovic@60 86 utiltbx_timer_start_times = clock;
idamnjanovic@60 87 utiltbx_time_lastdisp = utiltbx_timer_start_times;
idamnjanovic@60 88 utiltbx_timer_iternums = double(iternum);
idamnjanovic@60 89 utiltbx_timer_lastiter = 0;
idamnjanovic@60 90 utiltbx_timer_name = { timername };
idamnjanovic@60 91 utiltbx_timer_callfun = {};
idamnjanovic@60 92 tid = 1;
idamnjanovic@60 93 else
idamnjanovic@60 94 utiltbx_timer_start_times(end+1,:) = clock;
idamnjanovic@60 95 utiltbx_time_lastdisp(end+1,:) = utiltbx_timer_start_times(end,:);
idamnjanovic@60 96 utiltbx_timer_iternums(end+1) = double(iternum);
idamnjanovic@60 97 utiltbx_timer_lastiter(end+1) = 0;
idamnjanovic@60 98 utiltbx_timer_name{end+1} = timername;
idamnjanovic@60 99 tid = size(utiltbx_timer_start_times,1);
idamnjanovic@60 100 end
idamnjanovic@60 101
idamnjanovic@60 102
idamnjanovic@60 103 % detect timer calling function %
idamnjanovic@60 104
idamnjanovic@60 105 st = dbstack;
idamnjanovic@60 106 if (length(dbstack) >= 2)
idamnjanovic@60 107 utiltbx_timer_callfun{end+1} = st(2).name;
idamnjanovic@60 108 else
idamnjanovic@60 109 utiltbx_timer_callfun{end+1} = '';
idamnjanovic@60 110 end