-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfce_progress.m
110 lines (89 loc) · 3.38 KB
/
tfce_progress.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
function tfce_progress(action,varargin)
% Display progress and remaining time
% FORMAT tfce_progress('Init',n_iterations,process_name,iteration_name)
% Initialises progress tool
%
% FORMAT tfce_progress('Set',value)
% Sets iteration.
%
% FORMAT tfce_progress('Clear')
% Clears the progress output and prints processing time.
% ______________________________________________________________________
%
% Christian Gaser
% Structural Brain Mapping Group (https://neuro-jena.github.io)
% Departments of Neurology and Psychiatry
% Jena University Hospital
% ______________________________________________________________________
% $Id$
global sum_time time_old iter_old n_iterations arg2 arg3
if ~nargin, action = 'Init'; end
switch lower(action)
% Initialise
%-------------------------------------------------------------------
case 'init'
n_iterations = varargin{1};
if nargin > 2, arg2 = varargin{2}; else arg2 = 'Computing'; end
if nargin > 3, arg3 = varargin{3}; else arg3 = 'Iterations'; end
fprintf('%s\n',arg2);
sum_time = 0;
time_old = clock;
iter_old = 0;
% Set
%-------------------------------------------------------------------
case 'set'
iter = varargin{1};
% estimate time for remaining iterations
time_diff = etime(clock, time_old);
sum_time = sum_time + time_diff;
avg_time = sum_time/iter;
str = sprintf('%.f%% (%s remaining)',iter/n_iterations*100,...
time2str(avg_time*(n_iterations-iter)));
fprintf('%-35s%-35s',repmat(sprintf('\b'),1,35),str);
try
h = axes('position',[0.5 0 0.1 0.05],'Units','normalized','Parent',...
varargin{2},'Visible','off');
text(0.5,0.5,sprintf('%-5s%-15s%-5s',repmat(sprintf(' '),5),str,repmat(sprintf(' '),5)),...
'FontSize',spm('FontSize',8),...
'HorizontalAlignment','Center',...
'VerticalAlignment','middle',...
'BackgroundColor','white');
end
% save old values
time_old = clock;
iter_old = iter;
% Clear
%-------------------------------------------------------------------
case 'clear'
fprintf('%-35s',repmat(sprintf('\b'),1,35));
fprintf('Processing time: %s\n',time2str(sum_time));
try
h = axes('position',[0.5 0 0.1 0.05],'Units','normalized','Parent',...
varargin{1},'Visible','off');
text(0.5,0.5,sprintf('Processing time: %s\n',time2str(sum_time)),...
'FontSize',spm('FontSize',8),...
'HorizontalAlignment','Center',...
'VerticalAlignment','middle',...
'BackgroundColor','white');
end
% Error
%-------------------------------------------------------------------
otherwise
error('Unknown action string');
end
return
function str = time2str(t)
minutes = t/60;
hours = t/3600;
days = hours/24;
if days > 2
str = sprintf('%d days %02.1f h', floor(days),24*(days-floor(days)));
elseif days > 1
str = sprintf('%d day %02.1f h', floor(days),24*(days-floor(days)));
elseif hours > 1
str = sprintf('%d:%02.0f h', floor(hours),60*(hours-floor(hours)));
elseif minutes > 1
str = sprintf('%d:%02.0f min',floor(minutes),60*(minutes-floor(minutes)));
else
str = sprintf('%d s',round(t));
end