Skip to content

Commit

Permalink
Merge pull request #1669 from pace-neutrons/1663_gen_sqw_progress
Browse files Browse the repository at this point in the history
gen sqw progress
  • Loading branch information
abuts authored May 10, 2024
2 parents 528a5ad + cf1978d commit 3cc7832
Showing 1 changed file with 66 additions and 24 deletions.
90 changes: 66 additions & 24 deletions herbert_core/classes/data_loaders/@rundata/private/gen_runfiles_.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@
end
end
n_spe_files = numel(spe_files);
ll = config_store.instance().get_value('hor_config','log_level');
if ll>0 && n_spe_files > 5
print_progress_dots = true;
else
print_progress_dots = false;
end
if print_progress_dots
fprintf('*** Constructing %d rundata objects\n',n_spe_files);
end

% Check if second parameter is a par file or list of par files and
% remove par_files variable from the list of input parameters;
Expand All @@ -87,31 +96,31 @@
par_files = params{1};
else
error('HERBERT:gen_runfiles:invalid_argument', ...
'number of par_files is not 1 or the number of spe_files');
'number of par_files is not 1 or the number of spe_files');
end
elseif isempty(params{1}) % empty par file definition provided
par_files = {};
else
par_files = params{1};
if ~iscell(par_files)
if numel(par_files)==1
a = repmat({par_files},n_spe_files,1);
par_files = a;
elseif numel(par_files)==n_spe_files
par_files = num2cell(par_files);
elseif isa(par_files,'double')
par_files = repmat({par_files},n_spe_files,1); % array form of detpar - further checks will be done in the isdetpar call below
else
error('HERBERT:rundata:gen_runfiles', ...
'number of input par_files not 1 or number of spe files');
end
if numel(par_files)==1
a = repmat({par_files},n_spe_files,1);
par_files = a;
elseif numel(par_files)==n_spe_files
par_files = num2cell(par_files);
elseif isa(par_files,'double')
par_files = repmat({par_files},n_spe_files,1); % array form of detpar - further checks will be done in the isdetpar call below
else
error('HERBERT:rundata:gen_runfiles', ...
'number of input par_files not 1 or number of spe files');
end
else
if numel(par_files)==1
par_files = repmat({par_files{1}},n_spe_files,1);
elseif numel(par_files)~=n_spe_files
error('HERBERT:rundata:gen_runfiles', ...
'number of input par_files not 1 or number of spe files');
end
if numel(par_files)==1
par_files = repmat({par_files{1}},n_spe_files,1);
elseif numel(par_files)~=n_spe_files
error('HERBERT:rundata:gen_runfiles', ...
'number of input par_files not 1 or number of spe files');
end
end
for ii=1:numel(par_files)
[is,pfiles] = isdetpar(par_files{ii}); % will throw if array in wrong format
Expand Down Expand Up @@ -244,13 +253,15 @@

file_exist = true(n_files,1);



% define parameters for the progress bar displaying the progress of objects construction.
dot_string_length = 0;
max_dot_string_length = 50;
% Do we build runfiles from one, multiple or no par files?
if isempty(par_files)
for i=1:n_files
[runfiles{i},file_exist(i)] = init_runfile_no_par(runfiles{i},...
spe_files{i},dfnd_params(i),allow_missing);
dot_string_length = print_progress(print_progress_dots,dot_string_length,max_dot_string_length);
end
elseif numel(par_files)==1
[runfiles{1},file_exist(1)]= init_runfile_with_par(runfiles{1},spe_files{1},...
Expand All @@ -261,8 +272,9 @@
error('HERBERT:gen_runfiles:invalid_argument',runfiles{1}.reason_for_invalid)
end
end
dot_string_length = print_progress(print_progress_dots,dot_string_length,max_dot_string_length);
% Save time on multiple load of the same par into memory by reading it just once
%CM:will probably have to get rid of this
%CM:will probably have to get rid of this
if n_files>1
[par,runfiles{1}] = get_par(runfiles{1}); %CM:get_par()
end
Expand All @@ -275,6 +287,7 @@
error('HERBERT:gen_runfiles:invalid_argument',runfiles{i}.reason_for_invalid)
end
end
dot_string_length = print_progress(print_progress_dots,dot_string_length,max_dot_string_length);
end
else % multiple par and spe files;
for i=1:n_files
Expand All @@ -287,7 +300,7 @@
error('HERBERT:gen_runfiles:invalid_argument',runfiles{i}.reason_for_invalid)
end
end

dot_string_length = print_progress(print_progress_dots,dot_string_length,max_dot_string_length);
end
end

Expand All @@ -306,6 +319,35 @@
end
end
end
if print_progress_dots
if dot_string_length ~= 0
fprintf('\n');
end
fprintf('*** Finished constructuion of %d %s objects\n',n_files,name_of_class);
end

function log_length = print_progress(do_print,log_length,max_length)
% print progress log.
% Inputs:
% do_print -- bulean. If true, progress log is printed and if false it
% does not.
% log_length -- The lengh of already printed dot string.
% max_length -- Maximal length of dot string requested. If log_length
% reaches this value, CR is send to stdout.
%
% Returns:
% log_length -- the number of dots printed in current row after routine
% has been called. Either log_length or log_length+1
%
if ~do_print
return;
end
fprintf('.');
log_length= log_length + 1;
if log_length >= max_length
fprintf('\n');
log_length = 0;
end

function [runfile,file_found] = init_runfile_no_par(runfile,spe_file_name,param,allow_missing)
% init runfile in the case of no par file is present
Expand Down Expand Up @@ -366,7 +408,7 @@

function [is,input]=isdetpar(input)
%ISDETPAR for a scalar argument input
% check if it is a struct. If so and the struct is a detpar,
% check if it is a struct. If so and the struct is a detpar,
% return true for output argument is, else false.
% If it is not a struct,do the same for a numeric vector which may
% represent a detpar.
Expand All @@ -375,7 +417,7 @@
% -----
% input - scalar which may or may not
% be a detpar or a numeric detpar vector
%
%
% Output
% ------
% is - logical scalar which is true or false according as its
Expand Down

0 comments on commit 3cc7832

Please sign in to comment.