view m-toolbox/classes/@ltpda_tf/setIunits.m @ 40:977eb37f31cb database-connection-manager

User friendlier errors from utils.mysql.connect
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Mon, 05 Dec 2011 18:04:03 +0100
parents f0afece42f48
children
line wrap: on
line source

% SETIUNITS sets the 'iunits' property a transfer function object.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: SETIUNITS sets the 'iunits' property a transfer function object.
%
% CALL:        objs.setIunits(val);
%              objs.setIunits(val1, val2);
%              objs.setIunits(plist('iunits', val));
%              objs = objs.setIunits(val);
%
% INPUTS:      objs: Can be a vector, matrix, list, or a mix of them.
%              val:
%                 1. Single string e.g. 'Hz'
%                      Each transfer function object get this value.
%                 2. Single string in a cell-array e.g. {'Hz'}
%                      Each transfer function object get this value.
%                 3. cell-array with the same number of strings as in objs
%                    e.g. {'Hz', 'V', 's'} and 3 transfer function objects in objs
%                      Each transfer function object get its corresponding
%                      value from the cell-array
%
% <a href="matlab:utils.helper.displayMethodInfo('ltpda_tf', 'setIunits')">Parameters Description</a>
%
% VERSION:     $Id: setIunits.m,v 1.12 2011/09/16 05:04:03 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = setIunits(varargin)
  
  % Check if this is a call from a class method
  callerIsMethod = utils.helper.callerIsMethod;
  
  if callerIsMethod
    fb     = varargin{1};
    values = varargin(2:end);
    
  else
    % Check if this is a call for parameters
    if utils.helper.isinfocall(varargin{:})
      varargout{1} = getInfo(varargin{3});
      return
    end
    
    import utils.const.*
    utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
    
    % Collect input variable names
    in_names = cell(size(varargin));
    for ii = 1:nargin,in_names{ii} = inputname(ii);end
    
    % Collect all ltpda transfer objects
    [fb,  fb_invars, rest] = utils.helper.collect_objects(varargin(:), 'ltpda_tf', in_names);
    [pls, invars,    rest] = utils.helper.collect_objects(rest(:), 'plist');
    
    % Define property name
    pName = 'iunits';
    
    % Get values for the ltpda transfer objects
    [fb, values] = processSetterValues(fb, pls, rest, pName);
    
    % Combine input plists and default PLIST
    pls = combine(pls, getDefaultPlist());
    
  end % callerIsMethod
  
  % Decide on a deep copy or a modify
  fb = copy(fb, nargout);
  
  for j=1:numel(fb)
    if numel(values) == 1
      fb(j).iunits = values{1};
    else
      fb(j).iunits = values{j};
    end
    if ~callerIsMethod
      plh = pls.pset(pName, values{j});
      fb(j).addHistory(getInfo('None'), plh, fb_invars(j), fb(j).hist);
    end
  end
  
  % Set output
  nObjs = numel(fb);
  if nargout == nObjs;
    % List of outputs
    for ii = 1:nObjs
      varargout{ii} = fb(ii);
    end
  else
    % Single output
    varargout{1} = fb;
  end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                               Local Functions                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%--------------------------------------------------------------------------
% Get Info Object
%--------------------------------------------------------------------------
function ii = getInfo(varargin)
  
  if nargin == 1 && strcmpi(varargin{1}, 'None')
    sets = {};
    pl   = [];
  else
    sets = {'Default'};
    pl   = getDefaultPlist;
  end
  % Build info object
  ii = minfo(mfilename, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setIunits.m,v 1.12 2011/09/16 05:04:03 hewitson Exp $', sets, pl);
end

%--------------------------------------------------------------------------
% Get Default Plist
%--------------------------------------------------------------------------
function plout = getDefaultPlist()
  persistent pl;
  if exist('pl', 'var')==0 || isempty(pl)
    pl = buildplist();
  end
  plout = pl;
end

function pl = buildplist()
  pl = plist({'iunits', 'The unit to set.'}, paramValue.EMPTY_STRING);
end