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