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