function sys = append(varargin)
%APPEND  Group LTI systems by appending inputs and outputs.
%
%   SysOut = APPEND(Sys1,Sys2, ...)  produces the aggregate system
% 
%                 [ Sys1  0       ]
%        SysOut = [  0   Sys2     ]
%                 [           .   }
%                 [             . ]
%
%   This operation amounts to concatenation of the input and output
%   vectors of the systems Sys1, Sys2, ...
%
%   See also  SERIES, PARALLEL, FEEDBACK.

%       Author(s): P. Gahinet, 4-9-96
%       Copyright (c) 1986-97 by The MathWorks, Inc.
%	$Revision: 1.4 $  $Date: 1997/04/09 00:27:18 $

ni = nargin;
sys = tf(varargin{1});
if nargin==1,
   return
end

[Num,Den] = tfdata(sys);
Slti = sys.lti;
Dmode = sys.Variable;
[Out,In] = size(Den);
 
% Incrementally build resulting system
for j=2:ni,
   sysj = tf(varargin{j});
   [num,den] = tfdata(sysj);
   [out,in] = size(den);
   
   % LTI inheritance management   
   gflags = [isgain(Num,Den) isgain(num,den)];
   [Slti,stat,Ts] = inherit('append',Slti,sysj.lti,gflags);
   eval(stat);

   % Append transfer functions
   pad12 = cell(Out,in); 
   pad21 = cell(out,In);
   pad12(:) = {0};   pad21(:) = {0};
   Num = [Num , pad12 ; pad21 , num];
   pad12(:) = {1};   pad21(:) = {1};
   Den = [Den , pad12 ; pad21 , den];
   Dmode = varpick(Dmode,sysj.Variable,Ts);

   In = In + in;
   Out = Out + out;
end
   
sys.num = Num;
sys.den = Den;
sys.Variable = Dmode;
sys.lti = Slti;


% end @tf/append.m
