function [iod, IsModified] = checkIODelay(iod, Ts, iosize)
% Check the value of ioDelay.

%   Copyright 2010-2018 The MathWorks, Inc.

SizeCheck = nargin>2;
IsModified = false();
if ~isnumeric(iod) || any(isinf(iod(:))) || ~isreal(iod)
   ctrlMsgUtils.error('Control:pmodel:ioDelayValue')
elseif SizeCheck && ~isequal(size(iod),iosize)
   ny = iosize(1); nu = iosize(2);
   if ~any(iod(:))
      iod = zeros(iosize);
   elseif (ny~=1 || nu~=1) && isscalar(iod)
      iod = iod(ones(ny,1),ones(nu,1));
   else
      ctrlMsgUtils.error('Control:ltiobject:ltiProperties03')
   end
elseif any(iod(:)<0)   
   ctrlMsgUtils.error('Control:pmodel:tfIODelayValue')
elseif Ts~=0
   % Check that values are whole integers.
   if ~isequaln(floor(iod),iod)
      ctrlMsgUtils.error('Control:pmodel:nonIntDelayForDTModel','ioDelay')
   end
else
    if issparse(iod)
        IsModified = true();
        iod = full(iod);
    end
    if ~isa(iod, 'double')
        IsModified = true();
        iod = double(iod);
    end
end
end