diff m-toolbox/classes/@ssm/setBlockNames.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/m-toolbox/classes/@ssm/setBlockNames.m	Wed Nov 23 19:22:13 2011 +0100
@@ -0,0 +1,135 @@
+% SETBLOCKNAMES Sets names of the specified SSM blocks.
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% DESCRIPTION: SETBLOCKNAMES Sets names of the specified SSM blocks.
+%
+% CALL:        obj = obj.setBlockNames(plist);
+%
+%
+% <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setBlockNames')">Parameters Description</a>
+%
+% VERSION: $Id: setBlockNames.m,v 1.14 2011/04/08 08:56:22 hewitson Exp $
+% 
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+function varargout = setBlockNames(varargin)
+  warning('This function is deprecated and will soon be removed. Please use ssm/setBlockPorperties instead')
+  %%% 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
+  
+  [ssms, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
+  [pl, invars2, rest]  = utils.helper.collect_objects(rest(:), 'plist');
+  if ~isempty(rest)
+    pl = combine(pl, plist(rest{:}));
+  end
+  pl = combine(pl, getDefaultPlist());
+
+  %%% Internal call: Only one object + don't look for a plist
+  internal = strcmp(varargin{end}, 'internal');
+  
+  sys = copy(ssms, nargout);
+  
+  %% parameters
+    
+  field    = pl.find('field');
+  blockIds = pl.find('blocks');
+  newNames = pl.find('names');
+  
+  if ischar(newNames)
+    newNames = {newNames};
+  end
+  if ischar(blockIds)
+    blockIds = {blockIds};
+  end
+  
+  % Some error checking....
+  if isempty(field)
+    error('### Please specify the field of the block to modify');
+  end
+  if numel(newNames) ~= numel(blockIds)
+    error('### Please specify one new name per old name/position');
+  end
+  
+  %% Loop over the input ssm objects
+  for kk = 1:numel(sys)
+    block = sys(kk).(field);
+    if isa(blockIds, 'double')
+      block(blockIds).setBlockNames(newNames);
+    elseif iscellstr(blockIds)
+      for i=1:numel(blockIds)
+        oldNames = block.blockNames;
+        position = strcmpi(oldNames, blockIds{i});
+        if sum(position)==0
+          error(['block named ' blockIds{i} ' could not be found in system ' sys(kk).name])
+        end
+        block(position).setBlockNames(newNames);
+      end
+    end
+    if ~internal
+      % append history step
+      sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist);
+    end
+  end % End loop over block IDs
+  
+  %% Set output
+  if nargout == numel(sys)
+    for ii = 1:numel(sys)
+      varargout{ii} = sys(ii);
+    end
+  else
+    varargout{1} = sys;
+  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, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: setBlockNames.m,v 1.14 2011/04/08 08:56:22 hewitson Exp $', sets, pl);
+end
+
+%--------------------------------------------------------------------------
+% Get Default Plist
+%--------------------------------------------------------------------------
+
+function plo = getDefaultPlist()
+  plo = plist();
+  
+  % field
+  p = param({'field', 'The field being changed'}, {1, {'inputs', 'outputs', 'states'}, paramValue.SINGLE});
+  plo.append(p);
+  
+  % blocks
+  p = param({'blocks', 'Identifiers (strings or indices) of the blocks you want to modify'}, {1, {[]}, paramValue.SINGLE});
+  plo.append(p);
+  
+  % names
+  p = param({'names', 'The new name(s) you want to set to the block(s). Use a cell-array, one entry for each block.'}, ...
+    {1, {[]}, paramValue.SINGLE});
+  plo.append(p);
+  
+end
+