SET set an analysis object property. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: SET set an analysis object property. CALL: ao = set(ao, 'name', 'name'); ao = set(ao, 'provenance', provenance-object); ao = set(ao, 'description','description'); ao = set(ao, 'hist', history-object); ao = set(ao, 'data', data); ao = set(ao, 'mfile', mfile); ao = set(ao, 'mfilename', 'mfilename'); ao = set(ao, 'mdlfile', 'mdlfile'); ao = set(ao, 'mdlfilename','mdlfilename'); ao = set(ao, 'version', 'cvs-version'); ao = set(ao, 'created', time-object); ao = set(ao, plist-object); --> plist-object with key/value paies ao = set(ao, 'data-property', value); --> ao.data.?? = value; ao = set(ao, 'fs', fs); --> ao.data.fs = fs; ao = set(ao, 't0', t0); --> ao.data.t0 = t0; ao = set(ao, 'xunits', 'xunits'); --> ao.data.xunits = 'xunits'; ao = set(ao, 'yunits', 'yunits'); --> ao.data.xunits = 'yunits'; The following call returns a parameter list object that contains the default parameter values: >> pl = set(ao, 'Params') The following call returns a string that contains the routine CVS version: >> version = set(ao,'Version') The following call returns a string that contains the routine category: >> category = set(ao,'Category') VERSION: $Id: set.m,v 1.32 2008/02/21 10:20:18 ingo Exp $ HISTORY: 30-01-07 M Hewitson Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function aos = set(varargin) 0002 % SET set an analysis object property. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: SET set an analysis object property. 0007 % 0008 % CALL: ao = set(ao, 'name', 'name'); 0009 % ao = set(ao, 'provenance', provenance-object); 0010 % ao = set(ao, 'description','description'); 0011 % ao = set(ao, 'hist', history-object); 0012 % ao = set(ao, 'data', data); 0013 % ao = set(ao, 'mfile', mfile); 0014 % ao = set(ao, 'mfilename', 'mfilename'); 0015 % ao = set(ao, 'mdlfile', 'mdlfile'); 0016 % ao = set(ao, 'mdlfilename','mdlfilename'); 0017 % ao = set(ao, 'version', 'cvs-version'); 0018 % ao = set(ao, 'created', time-object); 0019 % ao = set(ao, plist-object); --> plist-object with key/value paies 0020 % ao = set(ao, 'data-property', value); --> ao.data.?? = value; 0021 % ao = set(ao, 'fs', fs); --> ao.data.fs = fs; 0022 % ao = set(ao, 't0', t0); --> ao.data.t0 = t0; 0023 % ao = set(ao, 'xunits', 'xunits'); --> ao.data.xunits = 'xunits'; 0024 % ao = set(ao, 'yunits', 'yunits'); --> ao.data.xunits = 'yunits'; 0025 % 0026 % The following call returns a parameter list object that contains the 0027 % default parameter values: 0028 % 0029 % >> pl = set(ao, 'Params') 0030 % 0031 % The following call returns a string that contains the routine CVS version: 0032 % 0033 % >> version = set(ao,'Version') 0034 % 0035 % The following call returns a string that contains the routine category: 0036 % 0037 % >> category = set(ao,'Category') 0038 % 0039 % VERSION: $Id: set.m,v 1.32 2008/02/21 10:20:18 ingo Exp $ 0040 % 0041 % HISTORY: 30-01-07 M Hewitson 0042 % Creation 0043 % 0044 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0045 0046 %%% REMARK: This function don't use the generic set-function!!! 0047 0048 VERSION = '$Id: set.m,v 1.32 2008/02/21 10:20:18 ingo Exp $'; 0049 CATEGORY = 'Helper'; 0050 DEFAULT_PLIST = plist('name', '', ... 0051 'data', tsdata, ... 0052 'hist', history, ... 0053 'provenance', provenance, ... 0054 'description', '', ... 0055 'mfile', {''}, ... 0056 'mfilename', '', ... 0057 'mdlfile', '', ... 0058 'mdlfilename', '', ... 0059 'plist', '', ... 0060 'version', '', ... 0061 'created', time, ... 0062 'fs', [], ... 0063 't0', time, ... 0064 'xunits', '', ... 0065 'yunits', ''); 0066 0067 %%% Check if this is a special call: default parameter list, cvs-version, 0068 if isa(varargin{1}, 'ao') && ischar(varargin{2}) 0069 in = varargin{2}; 0070 if strcmp(in, 'Params') 0071 aos = DEFAULT_PLIST; 0072 return 0073 elseif strcmp(in, 'Version') 0074 aos = VERSION; 0075 return 0076 elseif strcmp(in, 'Category') 0077 aos = CATEGORY; 0078 return 0079 end 0080 end 0081 0082 aos = []; 0083 invars = {}; 0084 pls = plist(); 0085 propArgin = {}; 0086 0087 %%% collect input ao's, plist's and ao variable names 0088 for j=1:numel(varargin) 0089 0090 if isa(varargin{j}, 'ao') 0091 aos = [aos varargin{j}]; 0092 0093 ao_name = inputname(j); 0094 if isempty(ao_name) 0095 ao_name = 'no_ao_name'; 0096 end 0097 0098 % Memorise the variable name of the corresponding analysis object. 0099 % If the ao is an array or vector add the index to the variable name 0100 if numel(varargin{j}) == 1 0101 invars{end+1} = ao_name; 0102 else 0103 for ii=1:numel(varargin{j}) 0104 [I,J] = ind2sub(size(varargin{j}),ii); 0105 invars{end+1} = sprintf('%s(%d,%d)', ao_name, I, J); 0106 end 0107 end 0108 elseif isempty(propArgin) && isa(varargin{j}, 'plist') 0109 pls = [pls varargin{j}]; 0110 else 0111 propArgin{end+1} = varargin{j}; 0112 end 0113 end 0114 0115 pls = combine(pls); 0116 ao_fields = fieldnames(aos); 0117 data_fields = ''; 0118 if ~isempty(aos(1).data) 0119 data_fields = fieldnames(aos(1).data); 0120 end 0121 0122 %%% Exist a plist then add the key/value pairs to propArgin 0123 if isempty(propArgin) 0124 for ii = 1:nparams(pls) 0125 %% The 'key' name of a plist/param is always stored with upper case 0126 %% characters. To set a ao property with this key we have to lower the 0127 %% 'key' characters. 0128 propArgin{end+1} = lower(pls.params(ii).key); 0129 propArgin{end+1} = pls.params(ii).val; 0130 end 0131 end 0132 0133 hist_pl = plist(); 0134 0135 while length(propArgin) >= 2 0136 0137 prop = propArgin{1}; 0138 val = propArgin{2}; 0139 propArgin = propArgin(3:end); 0140 0141 %%% Normal case 0142 if ismember(prop, ao_fields) 0143 for jj = 1:numel(aos) 0144 aos(jj).(prop) = val; 0145 end 0146 0147 %%% Special case: Is prop a property of the data class then set the data class. 0148 elseif ismember(prop, data_fields) 0149 for jj = 1:numel(aos) 0150 aos(jj).data = set(aos(jj).data, prop, val); 0151 end 0152 0153 else 0154 error('### ''%s'' is not a valid %s-object property.', prop, class(aos)); 0155 end 0156 0157 hist_pl = append(hist_pl, prop, val); 0158 0159 end 0160 0161 for jj = 1:numel(aos) 0162 h = history('set', VERSION, hist_pl); 0163 h = set(h, 'inhists', aos(jj).hist); 0164 h = set(h, 'invars', cellstr(invars{jj})); 0165 0166 aos(jj).hist = h; 0167 end 0168 0169 if (nargout == 0) 0170 display(aos); 0171 error('\n### No output variable!\n### Please use: %s = set(%s, ''key'', ''value'');', inputname(1), inputname(1)); 0172 end 0173