-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathhmri_check_opt.m
56 lines (48 loc) · 1.59 KB
/
hmri_check_opt.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
function [opts,ind_repl] = hmri_check_opt(opts_def,opts,loc_opt)
% FORMAT opts = crc_check_flag(opts_def,opts)
%
% Function to automatically check the content of a "opts" structure, using
% a "default opts structure", adding the missing fields and putting in the
% default value if none was provided.
%
% INPUT:
% opts_def : default or reference structure
% opts : input option structure that need to be filled for missing
% fields with default values
%
% OUPUT:
% opts : filled up option structure
%_______________________________________________________________________
% Copyright (C) 2019 Cyclotron Research Centre
% Written by C. Phillips.
% Cyclotron Research Centre, University of Liege, Belgium
% Local option structure:
% loc_opt
% .verbose : print out information [true] or not [false, def.] on the
% fixed/updated structure.
if nargin<3
loc_opt.verbose = false;
end
f_names = fieldnames(opts_def);
% list fields in default structure
Nfields = length(f_names);
ind_repl = zeros(1,Nfields);
for ii=1:Nfields
% Update the output if
% - a field is missing
% - the field is empty when it shouldn't
if ~isfield(opts,f_names{ii}) || ...
( isempty(opts.(f_names{ii})) && ~isempty(opts_def.(f_names{ii})) )
opts.(f_names{ii}) = opts_def.(f_names{ii});
ind_repl(ii) = 1;
if loc_opt.verbose
fprintf('\n\tAdding field ''%s'' to structure ''%s''.', ...
f_names{ii},inputname(2));
jump_line = true;
end
end
end
if loc_opt.verbose && jump_line
fprintf('\n');
end
end