home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / sysgetsg.m < prev    next >
Text File  |  1999-04-29  |  4KB  |  108 lines

  1. # Copyright (C) 1998 A. Scottedward Hodel 
  2. #
  3. # This file is part of Octave. 
  4. #
  5. # Octave is free software; you can redistribute it and/or modify it 
  6. # under the terms of the GNU General Public License as published by the 
  7. # Free Software Foundation; either version 2, or (at your option) any 
  8. # later version. 
  9. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function [stname,inname,outname,yd] = sysgetsg(sys,sigid,signum,strflg)
  18.   # [stname,inname,outname,yd] = sysgetsg(sys)
  19.   # -or- siglist = sysgetsg(sys,sigid)
  20.   # -or- signame = sysgetsg(sys,sigid,signum{,strflg})
  21.   # Get signal names from a system
  22.   # inputs:
  23.   #    sys: system data structure for the state space system
  24.   #    sigid: signal id: string, must be one of:
  25.   #      "in": input signals
  26.   #     "out": output signals
  27.   #      "st": state signals
  28.   #      "yd": value of yd
  29.   #    signum: index of signal  (e.g., out4 = sysgetsg(sys,"out",4)
  30.   #            sets out4 to the name of the 4th output)
  31.   #    strflg: flag to return a string instead of a list;
  32.   #           strflg = 0: (default) return a list
  33.   #           strflg = 1: return a string; exits with an error if 
  34.   #                       length(signum) > 1
  35.   # outputs:
  36.   #   if sigid is not specified:
  37.   #      stname, inname, outname: signal names (lists);  names of states,
  38.   #          inputs, and outputs, respectively
  39.   #      yd: binary vector; yd(ii) is nonzero if output y is discrete.
  40.   #   if sigid is specified but signum is not specified:
  41.   #      stname: 
  42.   #          is the list of state names (sigid = "st")
  43.   #          is the list input names (sigid = "in")
  44.   #          is the list output names (sigid = "out")
  45.   #          is the logical vector indicate discrete outputs (sigid = "yd")
  46.   #   if all three input arguments are specified:
  47.   #          is the list of specified state, input, or output name(s) 
  48.   #          (sigid = "st", "in", or "out").  
  49.   #          is a logical flag indicating if output signum is continous
  50.   #               (sigval=0) or discrete (sigval = 1)
  51.   # 
  52.  
  53.   # Adapted from ss2sys
  54.  
  55.   if(nargin < 1 | nargin > 4 | nargout > 4)
  56.     usage("[stname{,inname,outname,yd}] = sysgetsg(sys{,sigid,signum})")
  57.   elseif(nargin > 1 & nargout > 1)
  58.     usage("sig = sysgetsg(sys,sigid{,signum,strflg})")
  59.   elseif( ! is_struct(sys) )
  60.     error("input argument must be a system data structure");
  61.   endif
  62.   if(nargin < 4)  strflg = 0; endif
  63.   if(nargin == 1)
  64.     sys = sysupdat(sys,"ss");        #make sure ss is up to date
  65.     stname = sysgetsg(sys,"st");
  66.     inname = sysgetsg(sys,"in");
  67.     outname = sysgetsg(sys,"out");
  68.     yd = sysgetsg(sys,"yd");
  69.   elseif(!(isstr(sigid) & min(size(sigid)) == 1))
  70.     error(sprintf("sigid(%dx%d) must be a string)",rows(sigid),columns(sigid)));
  71.   else
  72.     if(strcmp("st",sigid))         stname = sys.stname;
  73.     elseif(strcmp("in",sigid))     stname = sys.inname;
  74.     elseif(strcmp("out",sigid))    stname = sys.outname;
  75.     elseif(strcmp("yd",sigid))     stname = vec(sys.yd)';
  76.     else
  77.       error(sprintf("sigid=%s must be \"st\", \"in\", \"out\", or \"yd\"", ...
  78.     sigid));
  79.     endif
  80.     if(nargin >= 3)
  81.       if(signum > length(stname))
  82.         error(sprintf("sysgetsg(sys,\"%s\",%d):only %d entries.\n", ...
  83.       sigid,signum, rows(stname)));
  84.       else
  85.         if(!is_scal(strflg)) 
  86.           error("strflg must be a scalar");
  87.         endif
  88.         switch(strflg)
  89.         case(0),
  90.           stname = stname(signum);
  91.         case(1),
  92.           if(length(signum) > 1)
  93.             error("strflg=1, length(signum) = %d",length(signum));
  94.           endif
  95.           stname = nth(stname,signum);
  96.         otherwise,
  97.           error("Illegal value of strflg=%e",strflg);
  98.         endswitch
  99.         
  100.       endif
  101.     endif
  102.   endif
  103.  
  104. endfunction
  105.  
  106.