function err = mpc_chkdimension_previewing(signal,n,ports,portshandles,portnum,err)
% MPC_CHECK_Dimension_PREVIEW  detects whether ref/md signals are defined in workspace
% and specified in block dialog for previewing in a SL model before R2012a
% release.  If true, the function also instructs user how to connect
% previewing signals directly to the ref/md inport.
%
% Inputs: 
%   blkh: MPC block handle.
%   scope: either "mpc" or "multiple_mpc" 

% Author(s): Rong Chen 21-Sep-2011
% Copyright 2011 The MathWorks, Inc.

if ports(portnum).SrcBlock<0 
    % Signal is not connected
    return
else
    % Signal is connected
    Size = get_param(portshandles(portnum),'CompiledPortDimensions');
    if Size(1)==2 % 2-D matrix signal
        Size = Size(2:end); % Dimensions of the signal
    else
        if n==1, % scalar signal
            Size=[Size(2) 1]; % Interpret as a column vector
        else
            Size=[1 Size(2)]; % Interpret as a row vector
        end
    end
    if Size(2)~=n
        MsgID = ['MPC:utility:InvalidBlockSignalDimension' upper(signal)];
        err = sprintf('%s%s\n',err,ctrlMsgUtils.message(MsgID,n,Size(2)));
    end
end
