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
0040
0041
0042
0043
0044 VERSION = '$Id: single_operation.m,v 1.11 2007/11/27 13:19:19 ingo Exp $';
0045
0046
0047 if nargin == 2
0048 if isa(varargin{1}, 'fsdata') && ischar(varargin{2})
0049 in = char(varargin{2});
0050 if strcmp(in, 'Params')
0051 varargout{1} = getDefaultPL();
0052 return
0053 elseif strcmp(in, 'Version')
0054 varargout{1} = VERSION;
0055 return
0056 end
0057 end
0058 end
0059
0060
0061 if (nargin == 3)
0062
0063 data = varargin {1};
0064 op = varargin {2};
0065 pl = varargin {3};
0066 a = varargin {end};
0067 y = data.y;
0068 x = data.x;
0069
0070
0071 if ~isa(data, 'fsdata')
0072 error ('### fsdata/single_operation: The first input must be a fsdata.');
0073 end
0074 if ~ischar(op)
0075 error ('### fsdata/single_operation: The second input must be a string.');
0076 end
0077 if ~isa(plist, 'plist')
0078 error ('### fsdata/single_operation: The third input must be a plist.');
0079 end
0080
0081
0082 pl_default = getDefaultPL();
0083
0084
0085 if ~isempty(pl)
0086 pl = combine(pl);
0087 else
0088 pl = combine(pl_default);
0089 end
0090
0091 option = find(pl, 'option');
0092 dim = find(pl, 'dim');
0093 weight_vector = find(pl, 'W');
0094 do_xdata = find(pl, 'xdata');
0095 do_ydata = find(pl, 'ydata');
0096
0097
0098
0099 if ischar(option) && ~isempty(option)
0100 if ~strcmp(option(1), '''')
0101 option = ['''' option];
0102 end
0103 if ~strcmp(option(end), '''')
0104 option = [option ''''];
0105 end
0106 end
0107
0108
0109 if isnumeric(option) || islogical(option)
0110 option = num2str(option);
0111 end
0112
0113
0114 if isnumeric(dim) || islogical (dim)
0115 dim = num2str(dim);
0116 end
0117
0118
0119
0120
0121 if ~isempty(option) && ~isempty(dim)
0122 warning ('### xydata/single_operation: The param list contain a ''option'' and a ''dim''. It is computed %s(ao,option).', op);
0123 end
0124
0125
0126 if isempty(do_xdata) && isempty(do_ydata)
0127 do_ydata = 'y';
0128 end
0129
0130
0131 if (nargout >= 2)
0132
0133
0134
0135
0136 y_new = '[';
0137 for i = 1:nargout-1
0138 new_var_name = genvarname (sprintf('y_new%d',i));
0139 eval ([new_var_name '= 0;']);
0140
0141 y_new = strcat(y_new, sprintf (' y_new%d',i));
0142 end
0143 y_new = strcat (y_new, ' ]');
0144
0145
0146
0147
0148 x_new = '[';
0149 for i = 1:nargout-1
0150 new_var_name = genvarname (sprintf('x_new%d',i));
0151 eval ([new_var_name '= 0;']);
0152
0153 x_new = strcat(x_new, sprintf (' x_new%d',i));
0154 end
0155 x_new = strcat (x_new, ' ]');
0156
0157
0158
0159 for i = 1:nargout-1
0160 new_var_name = genvarname (sprintf('data_out%d',i));
0161 eval ([new_var_name '= data;']);
0162 end
0163
0164
0165 if ~isempty(do_ydata)
0166
0167 try
0168
0169
0170 if ~isempty(option)
0171 cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0172 eval (cmd_line);
0173
0174
0175
0176 elseif ~isempty(dim) && ~isempty(weight_vector)
0177 cmd_line = sprintf('%s = %s(y,weight_vector,%s);',y_new, op, dim);
0178 eval (cmd_line);
0179
0180
0181
0182 elseif ~isempty(dim)
0183 cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0184 eval (cmd_line);
0185
0186
0187
0188 elseif ~isempty(weight_vector)
0189 cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0190 eval (cmd_line);
0191
0192
0193
0194 else
0195 cmd_line = sprintf('%s = %s(y);',y_new, op);
0196 eval (cmd_line);
0197 end
0198
0199 catch
0200 l_error = lasterror;
0201 disp(sprintf('\n\n%s', l_error.message));
0202 error('### cdata/single_operation: Can not command:\n### %s\n### Have a look to the param list', cmd_line);
0203 end
0204
0205 end
0206
0207
0208 if ~isempty(do_xdata)
0209
0210 try
0211
0212
0213 if ~isempty(option)
0214 cmd_line = sprintf('%s = %s(x,%s);',x_new, op, option);
0215 eval (cmd_line);
0216
0217
0218
0219 elseif ~isempty(dim) && ~isempty(weight_vector)
0220 cmd_line = sprintf('%s = %s(x,weight_vector,%s);',x_new, op, dim);
0221 eval (cmd_line);
0222
0223
0224
0225 elseif ~isempty(dim)
0226 cmd_line = sprintf('%s = %s(x,%s);',x_new, op, dim);
0227 eval (cmd_line);
0228
0229
0230
0231 elseif ~isempty(weight_vector)
0232 cmd_line = sprintf('%s = %s(x,weight_vector);',x_new, op);
0233 eval (cmd_line);
0234
0235
0236
0237 else
0238 cmd_line = sprintf('%s = %s(x);',x_new, op);
0239 eval (cmd_line);
0240 end
0241
0242 catch
0243 l_error = lasterror;
0244 disp(sprintf('\n\n%s', l_error.message));
0245 error('### cdata/single_operation: Can not command:\n### %s\n### Have a look to the param list', cmd_line);
0246 end
0247
0248 end
0249
0250
0251
0252 for i = 1:nargout-1
0253
0254
0255
0256 if ~isempty(do_ydata)
0257 eval (sprintf('data_out%d.y = y_new%d;',i,i));
0258 eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0259 eval (sprintf('data_out%d.yunits = ''%s(%s)'';',i,op,data.yunits));
0260 end
0261
0262 if ~isempty(do_xdata)
0263 eval (sprintf('data_out%d.x = x_new%d;',i,i));
0264 eval (sprintf('data_out%d.name = ''%s(%s)'';',i,op,data.name));
0265 eval (sprintf('data_out%d.xunits = ''%s(%s)'';',i,op,data.xunits));
0266 end
0267
0268
0269 eval (sprintf('varargout{i+1} = data_out%d;',i))
0270
0271 end
0272
0273
0274 h = history(op, VERSION);
0275
0276 varargout{1} = h;
0277
0278 else
0279 error ('### fsdata/single_operation: This function need at least two output variables.');
0280 end
0281
0282 else
0283 error ('### fsdata/single_operation: This function need three input variables.')
0284 end
0285
0286
0287 function pl_default = getDefaultPL()
0288
0289 pl_default = plist('option', '', ...
0290 'dim', '', ...
0291 'W', [], ...
0292 'xdata', '', ...
0293 'ydata', 'y');
0294