function mex = utilThrowPortAttrError(dev, msgType)
    %

    %   Copyright 2014 The MathWorks, Inc.
             
    if any(strcmp(msgType,{'error','warning'}))
        if ~isempty(dev.PrevAttr) && ~isempty(dev.OrigAttr) ...
                && ischar(dev.PrevAttr) && ischar(dev.OrigAttr)
            mex = MException('ModelSlicer:PortAttributeMismatch',...
                getString(message('Sldv:ModelSlicer:Transform:PortAttributeMismatchWas',...
                convertAttributeName(dev.Attribute),...
                getfullname(dev.OrigBlockHandle),dev.OrigAttr,...
                getfullname(dev.SliceBlockHandle),dev.PrevAttr)));
        else
            mex = MException('ModelSlicer:PortAttributeMismatch',...
                getString(message('Sldv:ModelSlicer:Transform:PortAttributeMismatchNoAttrStr',...
                convertAttributeName(dev.Attribute),...
                getfullname(dev.OrigBlockHandle),...
                getfullname(dev.SliceBlockHandle))));
        end
    else % information        
        if ~isempty(dev.FixedAttr)
            mex = MException('ModelSlicer:PortAttributeMismatchInfo',...
                getString(message('Sldv:ModelSlicer:Transform:PortAttributeMismatchInfo',...
                convertAttributeName(dev.Attribute), getfullname(dev.SliceBlockHandle),dev.FixedAttr)));
        else
            mex = MException('ModelSlicer:PortAttributeMismatchInfo',...
                getString(message('Sldv:ModelSlicer:Transform:PortAttributeMismatchInfoNoAttrStr',...
                convertAttributeName(dev.Attribute), getfullname(dev.SliceBlockHandle))));
        end
    end
end

function out = convertAttributeName(attr)
    switch attr
        case 'CompiledSampleTime'
            out = getString(message('Sldv:ModelSlicer:Transform:SampleTime'));
        case 'CompiledPortAliasedThruDataType'
            out = getString(message('Sldv:ModelSlicer:Transform:DataType'));
        case 'CompiledPortDesignMax'
            out = getString(message('Sldv:ModelSlicer:Transform:DesignMaximum'));
        case 'CompiledPortDesignMin'
            out = getString(message('Sldv:ModelSlicer:Transform:DesignMinimum'));
        case 'CompiledPortDimensions'
            out = getString(message('Sldv:ModelSlicer:Transform:PortDimensions'));
        case 'CompiledPortWidth'
            out = getString(message('Sldv:ModelSlicer:Transform:PortWidth'));
        otherwise
            out = attr;
    end
end