PSET set or add a key/value pairor a param-object into the parameter list. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: PSET set or add a key/value pairor a param-object into the parameter list. Exist the key in the parameter list then becomes the value the new value. CALL: pl = pset(pl, param-object); pl = pset(pl, key, val); pl = pset(pl, key1, val1, key2, val2); M-FILE INFO: Get information about this methods by calling >> plist.getInfo('pset') Get information about a specified set-plist by calling: >> plist.getInfo('pset', 'set') VERSION: $Id: pset.m,v 1.11 2008/09/04 15:29:31 ingo Exp $ HISTORY: 30-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 % PSET set or add a key/value pairor a param-object into the parameter list. 0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0003 % 0004 % DESCRIPTION: PSET set or add a key/value pairor a param-object 0005 % into the parameter list. Exist the key in the parameter list 0006 % then becomes the value the new value. 0007 % 0008 % CALL: pl = pset(pl, param-object); 0009 % pl = pset(pl, key, val); 0010 % pl = pset(pl, key1, val1, key2, val2); 0011 % 0012 % M-FILE INFO: Get information about this methods by calling 0013 % >> plist.getInfo('pset') 0014 % 0015 % Get information about a specified set-plist by calling: 0016 % >> plist.getInfo('pset', 'set') 0017 % 0018 % VERSION: $Id: pset.m,v 1.11 2008/09/04 15:29:31 ingo Exp $ 0019 % 0020 % HISTORY: 30-01-07 M Hewitson 0021 % Creation 0022 % 0023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0024 0025 function varargout = pset(varargin) 0026 0027 %%% Check if this is a call for parameters 0028 if utils.helper.isinfocall(varargin{:}) 0029 varargout{1} = getInfo(varargin{3}); 0030 return 0031 end 0032 0033 [objs, invars, rest] = utils.helper.collect_objects(varargin(:), 'plist'); 0034 [pps, invars, rest] = utils.helper.collect_objects(rest(:), 'param'); 0035 0036 %%% Decide on a deep copy or a modify 0037 pls = copy(objs, nargout); 0038 0039 %%%%%%%%%% Some plausibility checks %%%%%%%%%% 0040 if (isempty(pps) && isempty(rest)) || mod(numel(rest),2) 0041 error('### Please define a ''key'' AND a ''value''%s### to set this pair.', char(10)); 0042 end 0043 0044 for ii = 1:numel(pls) 0045 0046 %%%%%%%%%% First case: Set param-objects %%%%%%%%%% 0047 if ~isempty(pps) 0048 for jj = 1:numel(pps) 0049 add_param(pls(ii), pps(jj)); 0050 end 0051 end 0052 0053 %%%%%%%%%% Second case: Set key/value pair %%%%%%%%%% 0054 rest_help = rest; 0055 while ~isempty(rest_help) 0056 key = rest_help{1}; 0057 val = rest_help{2}; 0058 0059 %%% Remove the first two objects from the 'rest_help' variable 0060 rest_help(1) = []; 0061 rest_help(1) = []; 0062 0063 add_param(pls(ii), param(key,val)); 0064 end 0065 end 0066 0067 % Set output 0068 if nargout > 0 0069 varargout{1} = pls; 0070 end 0071 end 0072 0073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0074 % Local Functions % 0075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0076 0077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0078 % DESCRIPTION: check to see if this is one of the parameters we can set, 0079 % otherwise add it. 0080 function add_param(pl, pp) 0081 found = 0; 0082 for j=1:length(pl.params) 0083 if strcmpi(pl.params(j).key, pp.key) 0084 pl.params(j).setVal(pp.val); 0085 found = 1; 0086 break 0087 end 0088 end 0089 % add this parameter if necessary 0090 if ~found 0091 pl.params = [pl.params pp]; 0092 end 0093 end 0094 0095 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0096 % 0097 % FUNCTION: getInfo 0098 % 0099 % DESCRIPTION: Get Info Object 0100 % 0101 % HISTORY: 11-07-07 M Hewitson 0102 % Creation. 0103 % 0104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0105 0106 function ii = getInfo(varargin) 0107 if nargin == 1 && strcmpi(varargin{1}, 'None') 0108 sets = {}; 0109 pl = []; 0110 else 0111 sets = {'Default'}; 0112 pl = getDefaultPlist; 0113 end 0114 % Build info object 0115 ii = minfo(mfilename, 'plist', '', utils.const.categories.helper, '$Id: pset.m,v 1.11 2008/09/04 15:29:31 ingo Exp $', sets, pl); 0116 end 0117 0118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0119 % 0120 % FUNCTION: getDefaultPlist 0121 % 0122 % DESCRIPTION: Get Default Plist 0123 % 0124 % HISTORY: 11-07-07 M Hewitson 0125 % Creation. 0126 % 0127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0128 0129 function plo = getDefaultPlist() 0130 plo = plist(); 0131 end 0132