function name = getUniqueBlockName(this,block)
% GETUNIQUEBLOCKNAME(THIS,PORT) - Gets the unique block name given the full
% block path.  

%  Author(s): John Glass
%  Revised:
% Copyright 1986-2004 The MathWorks, Inc.
% $Revision: 1.1.6.2 $ $Date: 2004/12/26 21:58:24 $

%% Get the block name
blockname = get_param(block,'Name');

%% Find the shortest representation of the name for the block
block_diagram = this.getModelHandleFromBlock(block);
blocks = find_system(block_diagram.Name,...
    'findall','on',...
    'FollowLinks','on',...
    'LookUnderMasks','all',...
    'type','block',...
    'Name',blockname);

%% Remove the new line and carriage returns in the model/block name
blocks = regexprep(getfullname(blocks),'\n',' ');

%% Make into a cell array if needed
if ischar(blocks)
    blocks = {blocks};
end

%% Get the index into the blocks list and remove new line and carriage returns
block = regexprep(block,'\n',' ');
blk_ind = find(strcmp(block,blocks));
unblks = uniqname(this,blocks,true);
name = unblks{blk_ind};