Home > classes > @xyzdata > single_operation.m

single_operation

PURPOSE ^

SINGLE_OPERATION implements specified operator overload for xyzdata objects.

SYNOPSIS ^

function varargout = single_operation (varargin)

DESCRIPTION ^

 SINGLE_OPERATION implements specified operator overload for xyzdata objects.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 THIS STILL NEEDS FINISHED
 THIS STILL NEEDS FINISHED
 THIS STILL NEEDS FINISHED
 THIS STILL NEEDS FINISHED
 THIS STILL NEEDS FINISHED
 
 DESCRIPTION: SINGLE_OPERATION implements specified operator overload
              for xyzdata objects.
              ATTENTION: Should only be called from a analysis function.

 CALL: [h, data_out] = single_operation(a.data, 'log', pl)

 varargin format: 1:   [xyzdata]
                  2:   ['operation']
                  3:   [plist]

 varargout format 1: [new_history]
                  2: [data_out1]
                  3: [data_out2]      optional
                  4: [data_out3]      optional
                         ...          optional

 With the plist values you can control the command line.
 Possible key values are: option   <double> or <char>
                          dim      <double> or <char>
                          W        <vector>
                          xdata    <char>
                          ydata    <char>
                          xdata    <char>
 With the keys xdata,ydata or zdata you can control which data are to compute.
 Attention the value of the key 'xdata', 'ydata' or 'zdata' must apply to the 
 data class.
 The other values are to control the command line:

 >> operation(data,'option')         option <char>
 >> operation(data,option)           option <double>
 >> operation(data,W,dim)
 >> operation(data,dim)
 >> operation(data,W)
 >> operation(data)

 HISTORY: 24-12-2007 Diepholz
             Creation.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = single_operation (varargin)
0002 % SINGLE_OPERATION implements specified operator overload for xyzdata objects.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % THIS STILL NEEDS FINISHED
0007 % THIS STILL NEEDS FINISHED
0008 % THIS STILL NEEDS FINISHED
0009 % THIS STILL NEEDS FINISHED
0010 % THIS STILL NEEDS FINISHED
0011 %
0012 % DESCRIPTION: SINGLE_OPERATION implements specified operator overload
0013 %              for xyzdata objects.
0014 %              ATTENTION: Should only be called from a analysis function.
0015 %
0016 % CALL: [h, data_out] = single_operation(a.data, 'log', pl)
0017 %
0018 % varargin format: 1:   [xyzdata]
0019 %                  2:   ['operation']
0020 %                  3:   [plist]
0021 %
0022 % varargout format 1: [new_history]
0023 %                  2: [data_out1]
0024 %                  3: [data_out2]      optional
0025 %                  4: [data_out3]      optional
0026 %                         ...          optional
0027 %
0028 % With the plist values you can control the command line.
0029 % Possible key values are: option   <double> or <char>
0030 %                          dim      <double> or <char>
0031 %                          W        <vector>
0032 %                          xdata    <char>
0033 %                          ydata    <char>
0034 %                          xdata    <char>
0035 % With the keys xdata,ydata or zdata you can control which data are to compute.
0036 % Attention the value of the key 'xdata', 'ydata' or 'zdata' must apply to the
0037 % data class.
0038 % The other values are to control the command line:
0039 %
0040 % >> operation(data,'option')         option <char>
0041 % >> operation(data,option)           option <double>
0042 % >> operation(data,W,dim)
0043 % >> operation(data,dim)
0044 % >> operation(data,W)
0045 % >> operation(data)
0046 %
0047 % HISTORY: 24-12-2007 Diepholz
0048 %             Creation.
0049 %
0050 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0051 
0052 VERSION  = '$Id: single_operation.m,v 1.1 2007/12/24 19:47:06 hewitson Exp $';
0053 
0054 % Check if this is a call for parameters
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 % Only the call from an analysis object is allowed.
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 %% Verify input variables and set default parameter
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   %% Set default parameter list
0091   pl_default = getDefaultPL();
0092 
0093   %% Combine the handover param-list and the default param-list
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   %% Check the <char> option if it begins and ends  with a quote '
0108   %% If not then add the quote.
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   %% Convert the <double> option into a char
0119   if isnumeric(option) || islogical(option)
0120     option = num2str(option);
0121   end
0122 
0123   %% Convert the dim into a char
0124   if isnumeric(dim) || islogical(dim)
0125     dim = num2str(dim);
0126   end
0127 
0128   %% The operation can only compute with a 'option' or with a 'dimension'.
0129   %% e.g. operation(ao, 'option')
0130   %%      operation(ao, dim)
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 %% %% Ensure that the called function have at least two output variables
0141   if (nargout >= 2)
0142 
0143 %%  %% xdata:
0144     %% Create the output string for the eval command
0145     %% e.g.: x_new = '[ x_new1 x_new2 ]'
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     %% ydata:
0156     %% Create the output string for the eval command
0157     %% e.g.: y_new = '[ y_new1 y_new2 ]'
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 %%  %% Create the output variables
0168     %% e.g.: data_out1 = data;
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 %%  Execute the command for the xdata
0175     if ~isempty(do_xdata)
0176 
0177       try
0178         %% Execute with a option
0179         %% >> operation(x,'option');
0180         if ~isempty(option)
0181           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, option);
0182           eval (cmd_line);
0183 
0184         %% Execute with a weight vector and dimension
0185         %% >> operation(x,W,dim);
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         %% Execute with a dimension
0191         %% >> operation(x,dim);
0192         elseif ~isempty(dim)
0193           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, dim);
0194           eval (cmd_line);
0195 
0196         %% Execute with a weight vector
0197         %% >> operation(x,W);
0198         elseif ~isempty(weight_vector)
0199           cmd_line = sprintf('%s = %s(x,weight_vector);',x_new, op);
0200           eval (cmd_line);
0201 
0202         %% Execute without parameter or option
0203         %% >> operation(x)
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 %%  Execute the command for the ydata
0218     if ~isempty(do_ydata)
0219 
0220       try
0221         %% Execute with a option or a dimension
0222         %% >> operation(y,'option');
0223         if ~isempty(option)
0224           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0225           eval (cmd_line);
0226 
0227         %% Execute with a weight vector and dimension
0228         %% >> operation(y,W,dim);
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         %% Execute with a option or a dimension
0234         %% >> operation(y,dim);
0235         elseif ~isempty(dim)
0236           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0237           eval (cmd_line);
0238 
0239         %% Execute with a weight vector
0240         %% >> operation(y,W);
0241         elseif ~isempty(weight_vector)
0242           cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0243           eval (cmd_line);
0244 
0245         %% Execute without parameter or option
0246         %% >> operation(y)
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 %%  %% The result from eval is in x_new1, y_new1, ...
0261     %% Create a xydata object from this results and write it into the output
0262     for i = 1:nargout-1
0263 
0264       %% Create xydata
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       %% Write to output
0277       eval (sprintf('varargout{i+1} = data_out%d;',i))
0278 
0279     end
0280 
0281     %% Create a new history object
0282     h = history(op, VERSION);
0283 
0284     varargout{1} = h;
0285 
0286   else % (nargout < 2)
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

Generated on Tue 22-Jan-2008 10:39:13 by m2html © 2003