function [Ni,No,Nf] = checkPadeOrders(D,Ni,No,Nf)
% Checks that PADE approximation orders are properly sized

% Copyright 1986-2014 The MathWorks, Inc.
Delay = D.Delay;
nu = length(Delay.Input);
ny = length(Delay.Output);

% Input delays
Ni = localCheckData(Ni,[nu 1]);
if numel(Ni)~=nu
   ctrlMsgUtils.error('Control:transformation:pade1')
end

% Output delays
No = localCheckData(No,[ny 1]);
if numel(No)~=ny
   ctrlMsgUtils.error('Control:transformation:pade3')
end

% Internal delays
if isfield(Delay,'IO')
   % I/O delays
   Nf = localCheckData(Nf,[ny nu]);
   if numel(Nf)~=ny*nu
      ctrlMsgUtils.error('Control:transformation:pade6')
   end
else
   % Check NF against internal delays
   nfd = length(Delay.Internal);
   Nf = localCheckData(Nf,[nfd 1]);
   if numel(Nf)~=nfd
      ctrlMsgUtils.error('Control:transformation:pade5',nfd)
   end
end

%----------- Local functions -------------------------
function N = localCheckData(N,Size)
% Check order specs
N = N(:);
if ~isnumeric(N) || any(N~=round(N)) || any(N<0)
   ctrlMsgUtils.error('Control:transformation:pade7')
elseif isscalar(N)
   N = repmat(double(N),Size);
elseif numel(N)==prod(Size)
   N = reshape(double(N),Size);
end


