Home > classes > @plist > pset.m

pset

PURPOSE ^

PSET set parameter list properties.

SYNOPSIS ^

function pl = pset(pl, varargin)

DESCRIPTION ^

 PSET set parameter list properties.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: PSET set or add a key/value pair into the parameter list. Exist
              the key in the parameter list then becomes the value the new
              value.

 CALL:        pl = set(pl, key, val);
              pl = set(pl, key1, val1, key2, val2);

 VERSION:     $Id: pset.m,v 1.4 2007/11/23 15:34:47 ingo Exp $

 HISTORY:     30-01-07 M Hewitson
                 Creation

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function pl = pset(pl, varargin)
0002 % PSET set parameter list properties.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: PSET set or add a key/value pair into the parameter list. Exist
0007 %              the key in the parameter list then becomes the value the new
0008 %              value.
0009 %
0010 % CALL:        pl = set(pl, key, val);
0011 %              pl = set(pl, key1, val1, key2, val2);
0012 %
0013 % VERSION:     $Id: pset.m,v 1.4 2007/11/23 15:34:47 ingo Exp $
0014 %
0015 % HISTORY:     30-01-07 M Hewitson
0016 %                 Creation
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 VERSION = '$Id: pset.m,v 1.4 2007/11/23 15:34:47 ingo Exp $';
0021 
0022 % Check if this is a call for parameters or for the cvs-version number
0023 if nargin == 2
0024   if isa(pl, 'plist') && ischar(varargin{1})
0025     in = varargin{1};
0026     if strcmp(in, 'Params')
0027       pl = plist();
0028       return
0029     elseif strcmp(in, 'Version')
0030       pl = VERSION;
0031       return
0032     end
0033   end
0034 end
0035 
0036 if (nargout ~= 0)
0037 
0038   propArgin = varargin;
0039 
0040   while length(propArgin) >= 1
0041 
0042     %%%%%   Set a parameter object   %%%%%
0043     if isa(propArgin{1}, 'param')
0044       prop = upper(propArgin{1}.key);
0045       val  =       propArgin{1}.val;
0046       propArgin = propArgin(2:end);
0047 
0048     %%%%%   Set key/value pair   %%%%%
0049     elseif length(propArgin) >= 2
0050       prop = upper(propArgin{1});
0051       val  =       propArgin{2};
0052       propArgin = propArgin(3:end);
0053 
0054     else
0055       error('### There is only one key[%s] without a value left.',char(propArgin{1}));
0056     end
0057 
0058     % check to see if this is one of the parameters we can set, otherwise
0059     % add it
0060     found = 0;
0061     for j=1:length(pl.params)
0062       if strcmpi(pl.params(j).key, prop)
0063         pl.params(j).key = prop;
0064         pl.params(j).val = val;
0065         found = 1;
0066       end
0067     end
0068     % add this parameter if necessary
0069     if ~found
0070       pl = append(pl, param(prop, val));
0071     end
0072 
0073   end
0074 
0075 else
0076   if ischar(varargin{2})
0077     error('### please use: %s = set(%s, ''%s'', ''%s'');', ...
0078                         inputname(1), ...
0079                         inputname(1), ...
0080                         varargin{1},  ...
0081                         varargin{2});
0082   elseif isnumeric(varargin{2})
0083     error('### please use: %s = set(%s, ''%s'', %d);', ...
0084                         inputname(1), ...
0085                         inputname(1), ...
0086                         varargin{1},  ...
0087                         varargin{2});
0088   else
0089     error('### please use: %s = set(%s, key, ''value'');', ...
0090                         inputname(1), ...
0091                         inputname(1));
0092   end
0093 end
0094 
0095 % END

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003