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