-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrc_check_flag.m
57 lines (49 loc) · 1.61 KB
/
crc_check_flag.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
function [flags,ind_repl] = crc_check_flag(flags_o,flags,opt)
% FORMAT flags = crc_check_flag(flags_o,flags)
%
% Function to automatically check the content of a "flag" structure, using
% a "default flag structure", adding the missing fields and putting in the
% default value if none was provided.
%
% INPUT:
% flags_o default or reference structure
% flags input flag/option structure that need to be filled for missing
% fields with default values
%
% OUPUT:
% flags filled flag/option structure
%__________________________________________________________________________
% Copyright (C) 2015 Cyclotron Research Centre
% Written by Y. Leclercq & C. Phillips, 2008.
% Revised and updated by C. Phillips, 2015
% Cyclotron Research Centre, University of Liege, Belgium
% Option structure:
% opt
% .verbose : print out information [true] or not [false, def.] on the fixed
% structure
if nargin<3
opt.verbose = false;
end
f_names = fieldnames(flags_o);
% 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(flags,f_names{ii}) || ...
( isempty(flags.(f_names{ii})) && ~isempty(flags_o.(f_names{ii})) )
flags.(f_names{ii}) = flags_o.(f_names{ii});
ind_repl(ii) = 1;
if opt.verbose
fprintf('\n\tAdding field ''%s'' to structure ''%s''.', ...
f_names{ii},inputname(2));
jump_line = true;
end
end
end
if opt.verbose && jump_line
fprintf('\n');
end
end