function s=mksys(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,...
    v16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26,v27,v28,v29,v30,v31,v32,...
    v33,v34,v35,v36,v37,v38,v39,v40,v41,v42,v43,v44,v45,v46,v47,v48,v49,v50)
% S=MKSYS(A,B,C,D) or 
% S=MKSYS(V1,V2,...,VN, TY) packs matrices describing a system into TREE
% vector S under variable names depending on the STRING TY as follows:
% -----   -------------------------------  ---------------------------
% TY      V1,V2,...,VN                     Description
% -----   -------------------------------  ---------------------------
% 'ss'    'a,b,c,d,ty'                        Standard Statespace (default)
% 'des'   'a,b,c,d,e,ty'                      Descriptor System
% 'tss'   'a,b1,b2,c1,c2,d11,d12,d21,d22,ty'  Two-port Statespace 
% 'tdes'  'a,b1,b2,c1,c2,d11,d12,d21,d22,e,ty'Two-port Descriptor
% 'gss'   'sm,dimx,dimu,dimy,ty'              General statespace
% 'gdes'  'e,sm,dimx,dimu,dimy,ty'            General descriptor
% 'gpsm'  'psm,deg,dimx,dimu,dimy,ty'         General polynom. sys. matrix
% 'tf'    'num,den,ty'                        Transfer function
% 'tfm'   'num,den,m,n,ty'                    Transfer function matrix
% 'imp'   'y,ts,nu,ny'                        Impulse response
% ----------------------------------------------------------------------
% The BRANCH function recovers matrices packed into S, e.g., the 'c'
% and 'a' matrices from a standard statespace system S are returned by
% the command [C,A]=BRANCH(S,'c','a').  Alternatively, the command 
% [AG,BG,CG,DG,TY]=BRANCH(S) returns all the matrices in the order in 
% which they were originally packed.
%
% See also TREE, BRANCH, GRAFT

% R. Y. Chiang & M. G. Safonov 10/25/90	
% Copyright (c) 1990 by the MathWorks, Inc.
% All Rights Reserved.
% ---------------------------------------------------------------------------

nin=nargin;
sysmagic=27591;  % number installed in any system TREE in position 4
                 % to distinguish it from ordinary tree vectors

% Determine TY and set NIN equal to number of input arguments other than TY 
if nin<1
  error('Too few input arguments')
else 
  eval(['ty=v' num2str(nin) ';'])
  if isstr(ty),               % If TY is present
     nin=nin-1;
  else
     ty='ss';                 % Default TY
  end
end

% Convert TY to lowercase
ind=find(ty<'a');
[rind,cind]=size(ind);
if cind>0,
   ty(ind)=ty(ind)+('a'-'A')*ones(1,cind);
end

vars=vrsys(ty);
nvars=max(size(find(vars==',')))+1;
if nvars>nin,
   error(['Too few input arguments for system type ' ty]),
elseif nvars<nin,
   error(['Too many input arguments for system type ' ty]),
end
vars = [vars ',ty'];
temp=[];
for i=1:nin,
    temp = [temp ',v' num2str(i)];
end
temp=['s=tree(''' vars '''' temp ',''' ty ''');'];
eval(temp)
s(4)=sysmagic;
%  -------- End MKSYS.M -----------RYC/MGS 10/25/90 %
