0001 function out = mdl_normalize(mdl, val)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if ischar(mdl) && strcmp(mdl, 'UNIT_TEST'); do_unit_test; return; end
0015
0016
0017 try
0018 if ~strcmp(mdl.type,'fwd_model'), error;end;
0019 catch
0020 error('mdl_normalize: not called for a fwd_model object');
0021 end
0022
0023 switch nargin
0024 case 1
0025 out = get_flag(mdl);
0026 if isempty(out)
0027 out = feval('eidors_default');
0028 warning('EIDORS:normalize_flag_not_set', ...
0029 'normalize_measurements flag not set on model. Using default: %d',out);
0030 end
0031 case 2
0032 out = set_flag(mdl,val);
0033 otherwise
0034 error('Wrong number of parameters');
0035 end
0036
0037 function out = get_flag(mdl)
0038 out = [];
0039
0040 ff = fieldnames(mdl);
0041 for i = 1:length(ff);
0042
0043 if any(strcmp(ff{i},{'normalize','normalize_measurements'}))
0044 out = mdl.(ff{i});
0045 else
0046
0047 token = regexp(ff{i},'normal[^s]+.*','match','once');
0048 if ~isempty(token);
0049 warning('Suspect field "%s" found on the model',token);
0050 end
0051
0052 end
0053 end
0054
0055 function mdl = set_flag(mdl, val)
0056 mdl.normalize_measurements = val;
0057
0058 function do_unit_test
0059 s = warning('query', 'backtrace');
0060 warning off backtrace;
0061 eidors_default('set','mdl_normalize',@(x) 0);
0062 mdl = mk_common_model('c2t2',16);
0063 fmdl = mdl.fwd_model;
0064 eidors_msg('Does it come normalized?');
0065 eidors_msg(mdl_normalize(fmdl));
0066 eidors_msg('Normalize it');
0067 fmdl = mdl_normalize(fmdl,1);
0068 eidors_msg('How about now?');
0069 eidors_msg(mdl_normalize(fmdl));
0070 eidors_msg('De-normalize it');
0071 fmdl = mdl_normalize(fmdl,0);
0072 eidors_msg('And now?');
0073 eidors_msg(mdl_normalize(fmdl));
0074 eidors_msg('Remove the flag');
0075 fmdl = rmfield(fmdl,'normalize_measurements');
0076 eidors_msg(mdl_normalize(fmdl));
0077 eidors_msg('And now let''s set it to something stupid');
0078 fmdl.normalise_measurements = 1;
0079 eidors_msg(mdl_normalize(fmdl));
0080 fmdl.normalize_my_gran = 1;
0081 eidors_msg(mdl_normalize(fmdl));
0082 fmdl.normalize = 1;
0083 eidors_msg(mdl_normalize(fmdl));
0084 eidors_msg('But an imdl is not acceptable!');
0085 try
0086 eidors_msg(mdl_normalize(mdl));
0087 catch
0088 eidors_msg('Just so.');
0089 end
0090 warning(s);