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.html,v 1.7 2008/03/31 10:27:43 hewitson Exp $';
0053 CATEGORY = 'Internal';
0054 
0055 % Check if this is a call for parameters
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 % Only the call from an analysis object is allowed.
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 %% Verify input variables and set default parameter
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   %% Set default parameter list
0095   pl_default = getDefaultPL();
0096 
0097   %% Combine the handover param-list and the default param-list
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   %% Check the <char> option if it begins and ends  with a quote '
0112   %% If not then add the quote.
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   %% Convert the <double> option into a char
0123   if isnumeric(option) || islogical(option)
0124     option = num2str(option);
0125   end
0126 
0127   %% Convert the dim into a char
0128   if isnumeric(dim) || islogical(dim)
0129     dim = num2str(dim);
0130   end
0131 
0132   %% The operation can only compute with a 'option' or with a 'dimension'.
0133   %% e.g. operation(ao, 'option')
0134   %%      operation(ao, dim)
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 %% %% Ensure that the called function have at least two output variables
0145   if (nargout >= 2)
0146 
0147 %%  %% xdata:
0148     %% Create the output string for the eval command
0149     %% e.g.: x_new = '[ x_new1 x_new2 ]'
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     %% ydata:
0160     %% Create the output string for the eval command
0161     %% e.g.: y_new = '[ y_new1 y_new2 ]'
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 %%  %% Create the output variables
0172     %% e.g.: data_out1 = data;
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 %%  Execute the command for the xdata
0179     if ~isempty(do_xdata)
0180 
0181       try
0182         %% Execute with a option
0183         %% >> operation(x,'option');
0184         if ~isempty(option)
0185           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, option);
0186           eval (cmd_line);
0187 
0188         %% Execute with a weight vector and dimension
0189         %% >> operation(x,W,dim);
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         %% Execute with a dimension
0195         %% >> operation(x,dim);
0196         elseif ~isempty(dim)
0197           cmd_line = sprintf('%s = %s(x,%s);',x_new, op, dim);
0198           eval (cmd_line);
0199 
0200         %% Execute with a weight vector
0201         %% >> operation(x,W);
0202         elseif ~isempty(weight_vector)
0203           cmd_line = sprintf('%s = %s(x,weight_vector);',x_new, op);
0204           eval (cmd_line);
0205 
0206         %% Execute without parameter or option
0207         %% >> operation(x)
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 %%  Execute the command for the ydata
0222     if ~isempty(do_ydata)
0223 
0224       try
0225         %% Execute with a option or a dimension
0226         %% >> operation(y,'option');
0227         if ~isempty(option)
0228           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, option);
0229           eval (cmd_line);
0230 
0231         %% Execute with a weight vector and dimension
0232         %% >> operation(y,W,dim);
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         %% Execute with a option or a dimension
0238         %% >> operation(y,dim);
0239         elseif ~isempty(dim)
0240           cmd_line = sprintf('%s = %s(y,%s);',y_new, op, dim);
0241           eval (cmd_line);
0242 
0243         %% Execute with a weight vector
0244         %% >> operation(y,W);
0245         elseif ~isempty(weight_vector)
0246           cmd_line = sprintf('%s = %s(y,weight_vector);',y_new, op);
0247           eval (cmd_line);
0248 
0249         %% Execute without parameter or option
0250         %% >> operation(y)
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 %%  %% The result from eval is in x_new1, y_new1, ...
0265     %% Create a xydata object from this results and write it into the output
0266     for i = 1:nargout-1
0267 
0268       %% Create xydata
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       %% Write to output
0281       eval (sprintf('varargout{i+1} = data_out%d;',i))
0282 
0283     end
0284 
0285     %% Create a new history object
0286     h = history(op, VERSION);
0287 
0288     varargout{1} = h;
0289 
0290   else % (nargout < 2)
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

Generated on Mon 31-Mar-2008 12:20:24 by m2html © 2003