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.5 2008/02/14 08:29:09 mauro 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.5 2008/02/14 08:29:09 mauro Exp $
0014 %
0015 % HISTORY:     30-01-07 M Hewitson
0016 %                 Creation
0017 %
0018 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0019 
0020 VERSION = '$Id: pset.m,v 1.5 2008/02/14 08:29:09 mauro Exp $';
0021 CATEGORY = 'Helper';
0022 
0023 % Check if this is a call for parameters or for the cvs-version number
0024 if nargin == 2
0025   if isa(pl, 'plist') && ischar(varargin{1})
0026     in = varargin{1};
0027     if strcmp(in, 'Params')
0028       pl = plist();
0029       return
0030     elseif strcmp(in, 'Version')
0031       pl = VERSION;
0032       return
0033     elseif strcmp(in, 'Category')
0034       pl = CATEGORY;
0035       return
0036     end
0037   end
0038 end
0039 
0040 if (nargout ~= 0)
0041 
0042   propArgin = varargin;
0043 
0044   while length(propArgin) >= 1
0045 
0046     %%%%%   Set a parameter object   %%%%%
0047     if isa(propArgin{1}, 'param')
0048       prop = upper(propArgin{1}.key);
0049       val  =       propArgin{1}.val;
0050       propArgin = propArgin(2:end);
0051 
0052     %%%%%   Set key/value pair   %%%%%
0053     elseif length(propArgin) >= 2
0054       prop = upper(propArgin{1});
0055       val  =       propArgin{2};
0056       propArgin = propArgin(3:end);
0057 
0058     else
0059       error('### There is only one key[%s] without a value left.',char(propArgin{1}));
0060     end
0061 
0062     % check to see if this is one of the parameters we can set, otherwise
0063     % add it
0064     found = 0;
0065     for j=1:length(pl.params)
0066       if strcmpi(pl.params(j).key, prop)
0067         pl.params(j).key = prop;
0068         pl.params(j).val = val;
0069         found = 1;
0070       end
0071     end
0072     % add this parameter if necessary
0073     if ~found
0074       pl = append(pl, param(prop, val));
0075     end
0076 
0077   end
0078 
0079 else
0080   if ischar(varargin{2})
0081     error('### please use: %s = set(%s, ''%s'', ''%s'');', ...
0082                         inputname(1), ...
0083                         inputname(1), ...
0084                         varargin{1},  ...
0085                         varargin{2});
0086   elseif isnumeric(varargin{2})
0087     error('### please use: %s = set(%s, ''%s'', %d);', ...
0088                         inputname(1), ...
0089                         inputname(1), ...
0090                         varargin{1},  ...
0091                         varargin{2});
0092   else
0093     error('### please use: %s = set(%s, key, ''value'');', ...
0094                         inputname(1), ...
0095                         inputname(1));
0096   end
0097 end
0098 
0099 % END

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003