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

  1. function idxvec = sysidx(sys,sigtype,signamelist)
  2. # idxvec = sysidx(sys,sigtype,signamelist)
  3. # return indices of signals with specified signal names
  4. # inputs:
  5. #   sys:         OCST system data structure
  6. #   sigtype:     signal type to be selected: "in", "out", "st"
  7. #   signamelist: list of desired signal names
  8. # outputs:
  9. #   idxvec: vector of signal indices (appropriate for use with sysprune)
  10.  
  11. if(nargin != 3)         usage("idxvec = sysidx(sys,sigtype,signamelist)");
  12. elseif(!is_struct(sys)) error("sys must be a system data structure");
  13. elseif(!isstr(sigtype)) error("sigtype must be a string");
  14. elseif(rows(sigtype) != 1) 
  15.                         error("sigtype (%d x %d) must be a single string", ...
  16.                       rows(sigtype),columns(sigtype));
  17. elseif(!is_siglt(signamelist)) 
  18.                         error("signamelist must be a list of strings");
  19. endif
  20.  
  21. sigtype_list = list("input","output","state");
  22. sigtnum = 0;
  23. for idx = 1:length(sigtype_list)
  24.   thistype = nth(sigtype_list,idx);
  25.   if(strcmp(sigtype, thistype(1:length(sigtype)) )) sigtnum = idx; endif
  26. endfor
  27. if(sigtnum == 0)  error("Illegal sigtype value = %s\n",sigtype); endif
  28.  
  29. syssiglist = sysgetsg(sys,sigtype);
  30.  
  31. for idx = 1:length(signamelist)
  32.   signame = nth(signamelist,idx);
  33.   idxvec(idx) = 0;
  34.   for jdx = 1:sysdimen(sys,sigtype)
  35.     if(strcmp(signame,sysgetsg(sys,sigtype,jdx,1)))
  36.       if(idxvec(idx) != 0)
  37.         warning("Duplicate system input %s (%d,%d)\n", ...
  38.           sysgetsg(sys,sigtype,jdx,1),jdx,idxvec(idx));
  39.       else
  40.         idxvec(idx) = jdx;
  41.       endif
  42.     endif
  43.   endfor
  44.   if(idxvec(idx) == 0)
  45.     error("Did not find %s %s",nth(sigtype_list,sigtnum),signame);
  46.   endif
  47. endfor
  48.  
  49.  
  50. endfunction
  51.