From 62459ed06de21cbbb34a46d43f576e0e60c300dd Mon Sep 17 00:00:00 2001 From: Robert <52195853+robdahn@users.noreply.github.com> Date: Wed, 25 Sep 2024 15:39:41 +0200 Subject: [PATCH] Debugged cat_progress_bar. Corrected older call of cat_progress_bar but also added code to avoid errors with this older input. --- cat_progress_bar.m | 25 +++++++++++++++++++++++-- cat_run.m | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/cat_progress_bar.m b/cat_progress_bar.m index 33acfd1a..1919c4f6 100644 --- a/cat_progress_bar.m +++ b/cat_progress_bar.m @@ -42,7 +42,18 @@ function cat_progress_bar(action,varargin) if ~nargin, help cat_progress_bar; return; end if strcmpi(action,'init') - if nargin > 2, bartype = varargin{3}; else, bartype = 'bar'; end + if nargin > 2 + % catch possible errors of older calls with additional field, eg. + % cat_progress_bar('Init', 10 ,'CAT-Preprocessing','Volumes Complete'); + switch varargin{3} + case {'bar','cmd','cmd%'} + bartype = varargin{3}; + otherwise + bartype = 'bar'; + end + else + bartype = 'bar'; + end elseif strcmpi(action,'off') || strcmpi(action,'silent') || strcmpi(action,'quite') || strcmpi(action,'') return else @@ -63,6 +74,16 @@ function cat_progress_bar(action,varargin) %------------------------------------------------------------------- case 'init' n_iterations = varargin{1}; + + % from older versions that were not printed + %{ + if nargin > 2 + arg3 = varargin{2}; + else + arg3 = ''; + end + %} + if nargin > 1 arg2 = varargin{2}; if ~strcmp(bartype,'bar') && arg2(end)~=':' @@ -155,7 +176,7 @@ function cat_progress_bar(action,varargin) error('Unknown action string'); end otherwise - error('error:cat_progress_bar:bartype',fprintf('Unknown bartype %s',bartype)); + error('error:cat_progress_bar:bartype',sprintf('Unknown bartype "%s"',bartype)); end return diff --git a/cat_run.m b/cat_run.m index c96583c8..4f2ce61b 100644 --- a/cat_run.m +++ b/cat_run.m @@ -405,7 +405,7 @@ else %% conclusion without filelist spm_clf('Interactive'); - cat_progress_bar('Init', sum( numel(job_data) ) ,'CAT-Preprocessing','Volumes Complete'); + cat_progress_bar('Init', sum( numel(job_data) ) ,'CAT-Preprocessing'); fprintf('\nStarted %d jobs with the following PIDs:\n',job.nproc); for i=1:job.nproc