function [maskdisplay, port] = mpc_update_outport(blk,AvailableBlocks,type_out_mask,type_out_block,index,name,port,mpcport,maskdisplay)
if type_out_mask(index)
    if ~type_out_block(index)
        add_outport(blk,name,port,['MPC/' num2str(mpcport)]);
    end
    set_param([blk '/' name],'icondisplay','port number');    
    maskdisplay=[maskdisplay char(10) 'port_label(''output'', ' num2str(port) ', ''' name ''')'];
    port = port + 1;
else
    if type_out_block(index)
        if ismember(name,AvailableBlocks)
            delete_outport(blk,name,['MPC/' num2str(mpcport)]);
        end
    end
end

function add_outport(blk,name,port,mpcport)
outportblk = [blk '/' name];
terminatorblk = [blk '/' name '_terminator']; 
delete_line(blk,mpcport,[name '_terminator/1']);
position = get_param(terminatorblk,'position');
delete_block(terminatorblk);
add_block([blk '/mv'],outportblk);
add_line(blk,mpcport,[name '/1']);
set_param(outportblk,'position',position,'orientation','left','port',int2str(port));

function delete_outport(blk,name,mpcport)
outportblk = [blk '/' name];
terminatorblk = [blk '/' name '_terminator']; 
delete_line(blk,mpcport,[name '/1']);
position = get_param(outportblk,'position');
delete_block(outportblk);
add_block('built-in/Terminator',terminatorblk);
add_line(blk,mpcport,[name '_terminator/1']);
set_param(terminatorblk,'position',position,'Orientation','left');
