mdl_normalize

PURPOSE ^

MDL_NORMALIZE Check or set the normalize_measurements flag on a model.

SYNOPSIS ^

function out = mdl_normalize(mdl, val)

DESCRIPTION ^

MDL_NORMALIZE Check or set the normalize_measurements flag on a model.
  OUT = MDL_NORMALIZE(MDL) returns the value of the 
  'normalize_measurements' or 'normalize' field on MDL. If absent, the 
  default value is returned as set with EIDORS_DEFAULT. 

  MDL = MDL_NORMALIZE(MDL, VAL) sets the 'normalize_measurements' to VAL

 See also: FWD_MODEL_PARAMETERS, EIDORS_DEFAULT, EIDORS_STARTUP

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function out = mdl_normalize(mdl, val)
0002 %MDL_NORMALIZE Check or set the normalize_measurements flag on a model.
0003 %  OUT = MDL_NORMALIZE(MDL) returns the value of the
0004 %  'normalize_measurements' or 'normalize' field on MDL. If absent, the
0005 %  default value is returned as set with EIDORS_DEFAULT.
0006 %
0007 %  MDL = MDL_NORMALIZE(MDL, VAL) sets the 'normalize_measurements' to VAL
0008 %
0009 % See also: FWD_MODEL_PARAMETERS, EIDORS_DEFAULT, EIDORS_STARTUP
0010 
0011 % (C) 2012 Bartlomiej Grychtol. License: GPL v2 or v3
0012 % $Id: mdl_normalize.m 5227 2016-06-13 13:51:34Z aadler $
0013 
0014 if ischar(mdl) && strcmp(mdl, 'UNIT_TEST'); do_unit_test; return; end
0015 
0016 % check that we got a fwd_model
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 % do the real thing
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 % iterate over fields
0040 ff = fieldnames(mdl);
0041 for i = 1:length(ff);
0042     % if both are set, you're in trouble
0043     if any(strcmp(ff{i},{'normalize','normalize_measurements'}))
0044         out = mdl.(ff{i});
0045     else
0046         % won't hit 'normal' or anything that starts with 'normals'.
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; % s, throw a warning, return default
0079 eidors_msg(mdl_normalize(fmdl));
0080 fmdl.normalize_my_gran = 1; % throw a warning, return default
0081 eidors_msg(mdl_normalize(fmdl));
0082 fmdl.normalize = 1; % accept happily
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);

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005