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