0001 function varargout = single_operation (varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 VERSION = '$Id: single_operation.m,v 1.14 2008/02/12 19:54:05 hewitson Exp $';
0040 CATEGORY = 'Internal';
0041
0042
0043 if nargin == 2
0044 if isa(varargin{1}, 'cdata') && ischar(varargin{2})
0045 in = char(varargin{2});
0046 if strcmp(in, 'Params')
0047 varargout{1} = getDefaultPL();
0048 return
0049 elseif strcmp(in, 'Version')
0050 varargout{1} = VERSION;
0051 return
0052 elseif strcmp(in, 'Category')
0053 varargout{1} = CATEGORY;
0054 return
0055 end
0056 end
0057 end
0058
0059
0060 if (nargin == 3)
0061
0062 data = varargin {1};
0063 op = varargin {2};
0064 pl = varargin {3};
0065 a = varargin {end};
0066 y = data.y;
0067
0068
0069 if ~isa(data, 'cdata')
0070 error ('### cdata/single_operation: The first input must be a cdata.');
0071 end
0072 if ~ischar(op)
0073 error ('### cdata/single_operation: The second input must be a string.');
0074 end
0075 if ~isa(plist, 'plist')
0076 error ('### cdata/single_operation: The third input must be a plist.');
0077 end
0078
0079
0080 pl_default = getDefaultPL();
0081
0082
0083 if ~isempty(pl)
0084 pl = combine(pl);
0085 else
0086 pl = combine(pl_default);
0087 end
0088
0089 option = find(pl, 'option');
0090 dim = find(pl, 'dim');
0091 weight_vector = find(pl, 'W');
0092 do_xdata = find(pl, 'xdata');
0093 do_ydata = find(pl, 'ydata');
0094
0095
0096
0097 if ischar(option) && ~isempty(option)
0098 if ~strcmp(option(1), '''')
0099 option = ['''' option];
0100 end
0101 if ~strcmp(option(end), '''')
0102 option = [option ''''];
0103 end
0104 end
0105
0106
0107 if isnumeric(option) || islogical(option)
0108 option = num2str(option);
0109 end
0110
0111
0112 do_xdata = 'x';
0113 do_ydata = 'y';
0114
0115
0116 if isnumeric(dim) || islogical (dim)
0117 dim = num2str(dim);
0118 end
0119
0120
0121
0122
0123 if ~isempty(option) && ~isempty(dim)
0124 warning ('### xydata/single_operation: The param list contain a ''option'' and a ''dim''. It is computed %s(ao,option).', op);
0125 end
0126
0127
0128 if (nargout >= 2)
0129
0130
0131
0132 y_new = '[';
0133 for i = 1:nargout-1
0134 new_var_name = genvarname (sprintf('y_new%d',i));
0135 eval ([new_var_name '= 0;']);
0136
0137 y_new = strcat(y_new, sprintf (' y_new%d',i));
0138 end
0139 y_new = strcat (y_new, ' ]');
0140
0141
0142
0143 for i = 1:nargout-1
0144 new_var_name = genvarname (sprintf('data_out%d',i));
0145 eval ([new_var_name '= data;']);
0146 end
0147
0148
0149
0150 try
0151
0152
0153
0154 if ~isempty(option)
0155 cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0156 eval (cmd_line);
0157
0158
0159
0160 elseif ~isempty(dim) && ~isempty(weight_vector)
0161 cmd_line = sprintf('%s = %s(y,weight_vector,%s);',y_new, op, dim);
0162 eval (cmd_line);
0163
0164
0165
0166 elseif ~isempty(dim)
0167 cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0168 eval (cmd_line);
0169
0170
0171
0172 elseif ~isempty(weight_vector)
0173 cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0174 eval (cmd_line);
0175
0176
0177
0178 else
0179 cmd_line = sprintf('%s = %s(y);',y_new, op);
0180 eval (cmd_line);
0181 end
0182
0183 catch
0184 l_error = lasterror;
0185 disp(sprintf('\n\n%s', l_error.message));
0186 error('### cdata/single_operation: Can not command:\n### %s\n### Have a look to the param list', cmd_line);
0187 end
0188
0189
0190
0191
0192 for i = 1:nargout-1
0193
0194
0195 eval (sprintf('data_out%d.y = y_new%d;',i,i));
0196 eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0197
0198
0199 eval (sprintf('varargout{i+1} = data_out%d;',i))
0200
0201 end
0202
0203
0204 h = history(op, VERSION);
0205
0206 varargout{1} = h;
0207
0208 else
0209 error ('### cdata/single_operation: This function need at least two output variables.');
0210 end
0211
0212 else
0213 error ('### cdata/single_operation: This function need three input variables.')
0214 end
0215
0216
0217 function pl_default = getDefaultPL()
0218
0219 pl_default = plist('option', '', ...
0220 'dim', '', ...
0221 'W', [], ...
0222 'xdata', 'x', ...
0223 'ydata', 'y');
0224