function removingInactiveInterface(extModelH, ssIOActivity)

    % Deleting unused inport blocks and storing active inport
    % handle.
    
    %   Copyright 2014 The MathWorks, Inc.
    
    % Deleting dead root-level outport blocks
    inBlkH = [...
        loc_find_system('BlockType','Inport');...
        loc_find_system('BlockType','InportShadow')...
        ];    
    deadInportIdx = find(~ssIOActivity.Inport);
    delInportBlk = [];    
    for i=1:length(inBlkH)
        thisPortNum = str2double(get_param(inBlkH(i),'Port'));
        if any(deadInportIdx == thisPortNum)
            delInportBlk(end+1) = inBlkH(i); %#ok<AGROW>
        end
    end    
    for i=1:length(delInportBlk)
        delete_block(delInportBlk(i));
    end
    
    % Deleting dead root-level outport blocks
    inactiveOutportIdx = find(~ssIOActivity.Outport);
    outpBlkH = loc_find_system('BlockType','Outport');
    delOutportBlk = [];
    for i=1:length(outpBlkH)
        thisPortNum = str2double(get_param(outpBlkH(i),'Port'));
        if any(inactiveOutportIdx == thisPortNum)
            delOutportBlk(end+1) = outpBlkH(i); %#ok<AGROW>
        end        
    end
    for i=1:length(delOutportBlk)
        delete_block(delOutportBlk(i));
    end
    
    % Deleting inactive DSMs whihc are created by ss2mdl.
    DSMBlks = find_system(extModelH,'FindAll','on','SearchDepth',1,...
        'BlockType','DataStoreMemory');
    DSM_DSNames = get_param(DSMBlks,'DataStoreName');
    DSWBlks = find_system(extModelH,'FindAll','on','SearchDepth',1,...
        'BlockType','DataStoreWrite');
    DSW_DSNames = get_param(DSWBlks,'DataStoreName');
    
    prevYPos = [];
    for i=1:length(DSMBlks)
        dsName = get_param(DSMBlks(i),'DataStoreName');
        thisDSMblkH = DSMBlks(strcmp(dsName,DSM_DSNames));
        thisDSWblkH = DSWBlks(strcmp(dsName,DSW_DSNames));
        if any(strcmp(dsName,ssIOActivity.DataStoreName.Active))
            % Move DSM next to DSW
            if length(thisDSWblkH) == 1
                dswPos = get_param(thisDSWblkH,'Position');
                lh = get_param(thisDSWblkH,'LineHandles');
                inBlkH = get_param(lh.Inport(1),'SrcBlockHandle');
                inPos = get_param(inBlkH,'Position');
                if isempty(prevYPos)
                    thisYPos = floor((dswPos(2)+dswPos(4))/2);
                else                    
                    thisYPos = prevYPos + 50;
                end
                % Aligning Inport--DSW DSM to fill deleted spaces
                set_param(inBlkH,'Position',[inPos(1) thisYPos-7 inPos(3) thisYPos+7]);
                set_param(thisDSWblkH,'Position',[dswPos(1) thisYPos-10 dswPos(3) thisYPos+10]);                
                set_param(thisDSMblkH,'Position',...
                    [dswPos(3)+50 thisYPos-10 (2*dswPos(3)-dswPos(1))+50 thisYPos+10]);
                prevYPos = thisYPos;
            end
        else
            % inactive DSM block, Inport and DSW generated by subsystem
            % extraction.
            lh = get_param(thisDSWblkH,'LineHandles');
            inportH = get_param(lh.Inport(1),'SrcBlockHandle');
            delete_block(DSMBlks(i));
            delete_line(lh.Inport(1));
            delete_block(thisDSWblkH);
            delete_block(inportH);
        end
    end
    
    function out = loc_find_system(varargin)
        out = find_system(extModelH,'FindAll','on',...
            'LookUnderMasks','all','FollowLinks','on','SearchDepth',1,...
            varargin{:});
    end
end

