function model = mpc_default_indist(unindex, indistchannels, TimeUnit, Ts, varargin)
% Generate default input disturbance model.  
%
% If "Uscale" is provided, return in engineering units according to
% Uscale(unindex), otherwise, return model in dimensionless form.
%
% Rule: for all the "unindex" channels, add an integrator with unity gain
% to each channel designated by "indistchannels". otherwise, add unity gain
% instead.  "indistchannels" is a sub-set of "1:length(unindex)".

%   Author:  N L Ricker, R. chen
%   Copyright 2001-2014 The MathWorks, Inc.

% The model has "nun" outputs, "nun" inputs and "nx" states.
nun = length(unindex);
nx = length(indistchannels);
% default to unity gain
A = eye(nx);
B = zeros(nx,nun);
C = zeros(nun,nx);
D = eye(nun);
% replace with integrator at designated channels
for ct = 1:nx
   j = indistchannels(ct);
   B(ct,j) = Ts;
   C(j,ct) = 1;
   D(j,j) = 0;
end
% return with engineering units if scale factor is provided
if nargin==5
    UNscale = varargin{1};
    for ct = 1:nun
        C(ct,:) = C(ct,:)*UNscale(ct);
        D(ct,:) = D(ct,:)*UNscale(ct);
    end
end
% assemble
model = ss(A, B, C, D, Ts, 'TimeUnit', TimeUnit);
