annotate util/ksvd utils/timerinit.m @ 177:714fa7b8c1ad danieleb

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