APPEND append a parameter to the parameter list. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: APPEND append a parameter to the parameter list. CALL: pl = append(pl,p); pl = append(pl,pl); pl = append(pl, 'key1', 'value1') REMARK: It is not possible to append an key/value pair if the key exist in the parameter list. Tn this case an error is thrown. VERSION: $Id: append.m,v 1.8 2008/02/14 08:29:09 mauro Exp $ HISTORY: 30-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function pl = append(pl, varargin) 0002 % APPEND append a parameter to the parameter list. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: APPEND append a parameter to the parameter list. 0007 % 0008 % CALL: pl = append(pl,p); 0009 % pl = append(pl,pl); 0010 % pl = append(pl, 'key1', 'value1') 0011 % 0012 % REMARK: It is not possible to append an key/value pair if the key exist 0013 % in the parameter list. Tn this case an error is thrown. 0014 % 0015 % VERSION: $Id: append.m,v 1.8 2008/02/14 08:29:09 mauro Exp $ 0016 % 0017 % HISTORY: 30-01-07 M Hewitson 0018 % Creation 0019 % 0020 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0021 0022 VERSION = '$Id: append.m,v 1.8 2008/02/14 08:29:09 mauro Exp $'; 0023 CATEGORY = 'Helper'; 0024 0025 % Check if this is a call for parameters 0026 if nargin == 2 0027 if isa(pl, 'plist') && ischar(varargin{1}) 0028 in = char(varargin{1}); 0029 if strcmp(in, 'Params') 0030 pl = plist(); 0031 return 0032 elseif strcmp(in, 'Version') 0033 pl = VERSION; 0034 return 0035 elseif strcmp(in, 'Category') 0036 pl = CATEGORY; 0037 return 0038 end 0039 end 0040 end 0041 0042 argin = varargin; 0043 0044 while ~isempty(argin) 0045 0046 if isa(argin{1}, 'param') 0047 pp = argin{1}; 0048 pl = add_param(pl, pp); 0049 argin = argin(2:end); 0050 0051 elseif isa(argin{1}, 'plist') 0052 pl_in = argin{1}; 0053 0054 for ii = 1:nparams(pl_in) 0055 pl = add_param(pl, pl_in.params(ii)); 0056 end 0057 argin = argin(2:end); 0058 0059 else 0060 if length(argin) >= 2 0061 key = argin{1}; 0062 val = argin{2}; 0063 pl = add_param(pl, param(key, val)); 0064 argin = argin(3:end); 0065 else 0066 error('### There is a key [%s] without a value left.', key); 0067 argin = argin(2:end); 0068 end 0069 end 0070 end 0071 0072 0073 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0074 % 0075 % DESCRIPTION: The input parameter will only be added if the key doesn't exist 0076 % in the plist. Throw an error if the key exist in the plist. 0077 % 0078 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0079 function pl = add_param(pl, param) 0080 0081 for ii = 1:nparams(pl) 0082 if strcmpi(pl.params(ii).key, param.key) 0083 error('### The key [%s] exist in the parameter list.\n\n### Please use the function pset.',param.key); 0084 % pl.params(ii).val = param.val; 0085 return 0086 end 0087 end 0088 0089 % Convert all key characters into upper case characters 0090 param.key = upper(param.key); 0091 0092 pl.params = [pl.params param]; 0093 0094 % END 0095