function p = checkParameter(p,Name,Size)
% Checks that P is a parameter with the specified name and (optionally) size.
%
% P.Value is enforced to be non-sparse and double

%   Copyright 1986-2018 The MathWorks, Inc.
if ~isa(p,'param.Continuous')
   ctrlMsgUtils.error('Control:pmodel:badp',Name)
elseif ~strcmp(p.Name,Name)
   ctrlMsgUtils.error('Control:pmodel:rename',Name)
end
% Optional size check
if nargin>2 && ~isequal(getSize(p),Size)
   ctrlMsgUtils.error('Control:pmodel:resize',Name)
end
% Make sure value is a full double array
Val = p.Value;
isModified = false();
if issparse(Val)
    isModified = true();
    Val = full(Val);
end
if ~isa(Val, 'double')
    isModified = true();
    Val = double(Val);
end
if isModified
    p.Value = Val;
end
end