Mercurial > hg > ltpda
view m-toolbox/classes/@ssm/setPortNames.m @ 4:e3c5468b1bfe database-connection-manager
Integrate with LTPDAPreferences
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
% SETPORTNAMES Sets names of the specified SSM ports. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DESCRIPTION: SETPORTNAMES Sets names of the specified SSM ports. % % CALL: obj = obj.setPortNames(plist); % % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setPortNames')">Parameters Description</a> % % VERSION: $Id: setPortNames.m,v 1.15 2011/04/08 08:56:22 hewitson Exp $ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function varargout = setPortNames(varargin) warning('This function is deprecated and will soon be removed. Please use ssm/setPortPorperties 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 [sys, 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(sys, nargout); %% parameters field = pl.find('field'); blockId = pl.find('block'); portIds = pl.find('ports'); newNames = pl.find('names'); if ischar(newNames) newNames = {newNames}; end if ischar(blockId) blockId = {blockId}; end if ischar(portIds) portIds = {portIds}; end %% Some error checking.... if isempty(field) error('### Please specify the field of the block to modify'); end if numel(newNames) ~= numel(portIds) error('### Please specify one new name per port'); end if numel(blockId)~=1 error('### Please specify the name or the index of the block containing the port(s) to modify'); end %% Loop over the input ssm objects for kk = 1:numel(sys) blocks = sys(kk).(field); % get the block if isnumeric(blockId) block = blocks(blockId); else pos = findBlockWithNames(blocks, blockId{1}); block = blocks(pos); end if isempty(block) if isnumeric(blockId) error('### block ''%d'' not found in SSM model ''%s'' %s', blockId, sys(kk).name, field); else error('### block ''%s'' not found in SSM model ''%s'' %s', blockId, sys(kk).name, field); end end %% now setting port names oldNames = block.portNames; oldNames = oldNames{1}; if isa(portIds, 'double') block.ports(portIds).setName(newNames, block.name); elseif iscellstr(portIds) for i=1:numel(portIds) position = strcmpi(oldNames, portIds{i}); if sum(position)==0 error(['block named ' portIds{i} ' could not be found in system ' sys(kk).name]) end block.ports(position).setName(newNames(i), block.name); end end % append history step if ~internal sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist); end end % End loop over blocks %% Set output if nargout == numel(sys) for ii = 1:numel(sys) varargout{ii} = sys(ii); end else varargout{1} = sys; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Local Functions % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FUNCTION: getInfo % % DESCRIPTION: Get Info Object % % HISTORY: 11-07-07 M Hewitson % Creation. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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: setPortNames.m,v 1.15 2011/04/08 08:56:22 hewitson Exp $', sets, pl); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % FUNCTION: getDefaultPlist % % DESCRIPTION: Get Default Plist % % HISTORY: 11-07-07 M Hewitson % Creation. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function plo = getDefaultPlist() plo = plist(); % field p = param({'field', 'The field containing the port being changed.'}, {1, {'inputs', 'outputs', 'states'}, paramValue.SINGLE}); plo.append(p); % block p = param({'block', 'Identifiers (strings or indices) of the block containing the port you want to modify.'}, paramValue.EMPTY_STRING); plo.append(p); % ports p = param({'ports', 'Identifiers (strings or indices) of the ports you want to modify.'}, paramValue.EMPTY_STRING); plo.append(p); % names p = param({'names', 'The new name(s) you want to set to the port(s). Use a cell-array, one entry for each port.'}, ... paramValue.EMPTY_STRING); plo.append(p); end