diff scripts/control/system/sysappend.m @ 4460:cef48c4b902d

[project @ 2003-07-11 18:37:48 by jwe]
author jwe
date Fri, 11 Jul 2003 18:37:48 +0000
parents 22bd65326ec1
children b8105302cfe8
line wrap: on
line diff
--- a/scripts/control/system/sysappend.m
+++ b/scripts/control/system/sysappend.m
@@ -77,114 +77,116 @@
 
 function retsys = sysappend (sys, b, c, d, outname, inname, yd)
 
-  sav_empty_list_elements_ok = empty_list_elements_ok;
+  save_warn_empty_list_elements = warn_empty_list_elements;
+  unwind_protect
+    warn_empty_list_elements = 0;
 
-  empty_list_elements_ok = 1;
+    ## check input arguments
+    if ( (nargin < 2) | (nargin > 7) | (!isstruct(sys)))
+      usage("retsys = sysappend(sys,b,c[,d,outname,inname,yd]) ");
+    elseif(!isstruct(sys))
+      error("sys must be a system data structure");
+    endif
 
-  ## check input arguments
-  if ( (nargin < 2) | (nargin > 7) | (!isstruct(sys)))
-    usage("retsys = sysappend(sys,b,c[,d,outname,inname,yd]) ");
-  elseif(!isstruct(sys))
-    error("sys must be a system data structure");
-  endif
+    ## default system type must be state space form
+    [Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,Ayd] = sys2ss(sys);
+    [Ann,Anz,Am,Ap] = sysdimensions(sys);
 
-  ## default system type must be state space form
-  [Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,Ayd] = sys2ss(sys);
-  [Ann,Anz,Am,Ap] = sysdimensions(sys);
+    ## default c
+    if(nargin < 3)      c = [];                                endif
 
-  ## default c
-  if(nargin < 3)      c = [];                                endif
+    ## default d
+    if(nargin < 4)     make_d = 1;
+    elseif(isempty(d)) make_d = 1;
+    else               make_d = 0;                             endif
+    if(make_d)         d = zeros(rows(c)+Ap,columns(b) + Am);  endif
 
-  ## default d
-  if(nargin < 4)     make_d = 1;
-  elseif(isempty(d)) make_d = 1;
-  else               make_d = 0;                             endif
-  if(make_d)         d = zeros(rows(c)+Ap,columns(b) + Am);  endif
+    ## Append new input(s) if any
+    Bm = max(columns(d),columns(b)+Am);
+    if(Bm != Am)
+      ## construct new signal names
+      if(nargin >= 6)   # new names were passed
+	if(!isstr(inname))
+	  error("inname must be a string");
+	elseif(rows(inname) != (Bm - Am))
+	  error(sprintf("%d new inputs requested; inname(%dx%d)", ...
+	    (Bm-Am),rows(inname),columns(inname)));
+	endif
+      else
+	inname = __sysdefioname__(Bm,"u",(Am+1));
+      endif
+      if(Am)   Ain = append(Ain,inname);
+      else     Ain = inname;              endif
 
-  ## Append new input(s) if any
-  Bm = max(columns(d),columns(b)+Am);
-  if(Bm != Am)
-    ## construct new signal names
-    if(nargin >= 6)   # new names were passed
-      if(!isstr(inname))
-        error("inname must be a string");
-      elseif(rows(inname) != (Bm - Am))
-        error(sprintf("%d new inputs requested; inname(%dx%d)", ...
-          (Bm-Am),rows(inname),columns(inname)));
+      ## default b matrix
+      if(isempty(b))     b  = zeros(Ann+Anz,(Bm-Am));
+      elseif(rows(b) != Ann+Anz | columns(b) != (Bm-Am))
+	  error(sprintf("b(%dx%d); should be (%dx%d)", rows(b), columns(b), ...
+	    (Ann+Anz), (Bm-Am)));
       endif
-    else
-      inname = __sysdefioname__(Bm,"u",(Am+1));
-    endif
-    if(Am)   Ain = append(Ain,inname);
-    else     Ain = inname;              endif
 
-    ## default b matrix
-    if(isempty(b))     b  = zeros(Ann+Anz,(Bm-Am));
-    elseif(rows(b) != Ann+Anz | columns(b) != (Bm-Am))
-        error(sprintf("b(%dx%d); should be (%dx%d)", rows(b), columns(b), ...
-          (Ann+Anz), (Bm-Am)));
+      ## append new b matrix
+      Ab = [Ab,b];
     endif
 
-    ## append new b matrix
-    Ab = [Ab,b];    # empty_list_elements_ok=1 makes this ok
-  endif
-
-  ## Append new output(s) if any
-  Bp = max(rows(d),rows(c)+Ap);
-  if(Bp != Ap)
+    ## Append new output(s) if any
+    Bp = max(rows(d),rows(c)+Ap);
+    if(Bp != Ap)
 
-    ## construct new signal names, output classification
-    if(nargin >= 5)  # new names were passed
-      if(!isstr(outname))
-        error("outname must be a string");
-      elseif(rows(outname) != (Bp - Ap))
-        error(sprintf("%d new outputs requested; outname(%dx%d)", ...
-          (Bp-Ap),rows(outname),columns(outname)));
+      ## construct new signal names, output classification
+      if(nargin >= 5)  # new names were passed
+	if(!isstr(outname))
+	  error("outname must be a string");
+	elseif(rows(outname) != (Bp - Ap))
+	  error(sprintf("%d new outputs requested; outname(%dx%d)", ...
+	    (Bp-Ap),rows(outname),columns(outname)));
+	endif
+      else
+	outname = __sysdefioname__(Bp,"y",(Ap+1));
       endif
-    else
-      outname = __sysdefioname__(Bp,"y",(Ap+1));
-    endif
-    if(Ap)   Aout = append(Aout,outname);
-    else     Aout = outname;                endif
+      if(Ap)   Aout = append(Aout,outname);
+      else     Aout = outname;                endif
 
-    ## construct new yd entries
-    if(nargin == 7)
-      if(!isvector(yd))
-        error(sprintf("yd(%dx%d) must be a vector",rows(yd),columns(yd)))
-      elseif(rows(c) != length(yd) & rows(d) != length(yd))
-        error(sprintf("length(yd) = %d; c(%dx%d), d(%dx%d); mismatch", ...
-          length(yd), rows(c), columns(c),rows(d),columns(d)));
+      ## construct new yd entries
+      if(nargin == 7)
+	if(!isvector(yd))
+	  error(sprintf("yd(%dx%d) must be a vector",rows(yd),columns(yd)))
+	elseif(rows(c) != length(yd) & rows(d) != length(yd))
+	  error(sprintf("length(yd) = %d; c(%dx%d), d(%dx%d); mismatch", ...
+	    length(yd), rows(c), columns(c),rows(d),columns(d)));
+	endif
+      else
+	## default yd values
+	yd = ones(1,Bp)*( (Ats > 0) & (Ann == 0)  & isempty(find(Ayd == 0)) ) ;
       endif
-    else
-      ## default yd values
-      yd = ones(1,Bp)*( (Ats > 0) & (Ann == 0)  & isempty(find(Ayd == 0)) ) ;
-    endif
-    Ayd = [vec(Ayd);vec(yd)];
+      Ayd = [vec(Ayd);vec(yd)];
 
-    ## default c matrix
-    if(isempty(c))      c = zeros((Bp-Ap),Ann+Anz);
-    elseif(columns(c) != Ann+Anz | rows(c) != (Bp-Ap))
-        error(sprintf("c(%dx%d); should be (%dx%d)", rows(c), columns(c), ...
-          (Bp-Ap), (Ann+Anz) ));
+      ## default c matrix
+      if(isempty(c))      c = zeros((Bp-Ap),Ann+Anz);
+      elseif(columns(c) != Ann+Anz | rows(c) != (Bp-Ap))
+	  error(sprintf("c(%dx%d); should be (%dx%d)", rows(c), columns(c), ...
+	    (Bp-Ap), (Ann+Anz) ));
+      endif
+
+      ## append new c matrix
+      Ac = [Ac;c];
     endif
 
-    ## append new c matrix
-    Ac = [Ac;c];    # empty_list_elements_ok=1 makes this ok
-  endif
+    ## check d matrix
+    if(isempty(d)) d = zeros(Bp,Bm);
+    elseif(rows(d) != Bp | columns(d) != Bm)
+      error(sprintf("d(%dx%d) should be (%dx%d)",rows(d), columns(d), Bp, Bp));
+    endif
 
-  ## check d matrix
-  if(isempty(d)) d = zeros(Bp,Bm);
-  elseif(rows(d) != Bp | columns(d) != Bm)
-    error(sprintf("d(%dx%d) should be (%dx%d)",rows(d), columns(d), Bp, Bp));
-  endif
+    ## Splice in original D matrix
+    if(Am & Ap)          d(1:Ap, 1:Am) = Ad;       endif
+    Ad = d;
 
-  ## Splice in original D matrix
-  if(Am & Ap)          d(1:Ap, 1:Am) = Ad;       endif
-  Ad = d;
+    ## construct return system
+    retsys = ss2sys(Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,find(Ayd == 1));
 
-  ## construct return system
-  retsys = ss2sys(Aa,Ab,Ac,Ad,Ats,Ann,Anz,Ast,Ain,Aout,find(Ayd == 1));
-
-  empty_list_elements_ok = sav_empty_list_elements_ok;
+  unwind_protect_cleanup
+    warn_empty_list_elements = save_warn_empty_list_elements;
+  end_unwind_protect
 
 endfunction