Mercurial > hg > octave-thorsten
changeset 3414:f6c1c9deb22a
[project @ 2000-01-10 16:43:05 by hodelas]
sysidx now calls listidx to identify signal indices.
author | hodelas |
---|---|
date | Mon, 10 Jan 2000 16:43:05 +0000 |
parents | 604ede10160f |
children | 48aa44151317 |
files | scripts/control/is_signal_list.m scripts/control/listidx.m scripts/control/sysidx.m |
diffstat | 3 files changed, 89 insertions(+), 130 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/control/is_signal_list.m +++ b/scripts/control/is_signal_list.m @@ -1,36 +1,32 @@ -## Copyright (C) 1996, 1998 Auburn University. All rights reserved. -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by the -## Free Software Foundation; either version 2, or (at your option) any -## later version. -## -## Octave is distributed in the hope that it will be useful, but WITHOUT -## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -## for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. +# Copyright (C) 1996,1998,2000 Auburn University. All rights reserved. +# +# This file is part of Octave. +# +# Octave is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2, or (at your option) any +# later version. +# +# Octave is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# for more details. +# +# You should have received a copy of the GNU General Public License +# along with Octave; see the file COPYING. If not, write to the Free +# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -## -*- texinfo -*- -## @deftypefn {Function File} {@var{flg} =} is_signal_list (@var{mylist}) -## Returns true if mylist is a list of individual strings (legal for -## input to @var{syssetsignals}). -## @end deftypefn - -function flg = is_signal_list (mylist) - - flg = is_list(mylist); - if(flg) - for ii=1:length(mylist) - if(!(isstr(nth(mylist,ii)) & rows(nth(mylist,ii)) ==1) ) - flg = 0; - endif - endfor - endif +function flg = is_signal_list(mylist) +# function flg = is_signal_list(mylist) +# returns true if mylist is a list of individual strings. +# +flg = is_list(mylist); +if(flg) + for ii=1:length(mylist) + if(!(isstr(nth(mylist,ii)) & rows(nth(mylist,ii)) ==1) ) + flg = 0; + endif + endfor +endif endfunction
--- a/scripts/control/listidx.m +++ b/scripts/control/listidx.m @@ -1,4 +1,4 @@ -## Copyright (C) 1996, 1998 Auburn University. All rights reserved. +## Copyright (C) 2000 Auburn University. All rights reserved. ## ## This file is part of Octave. ## @@ -16,31 +16,24 @@ ## along with Octave; see the file COPYING. If not, write to the Free ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{idxvec}, @var{errmsg}] =} listidx(@var{listvar}, @var{strlist}) +## [idxvec, errmsg] = listidx(listvar, strlist) ## return indices of string entries in listvar that match strings in strlist -## @strong{Inputs} -## @table @var -## @item listvar -## list of strings to be searched -## @item strlist -## list of strings to be located in listvar. -## @end table -## @strong{Note} @var{listvar}, @var{strlist} may be passed as strings or -## string matrices; in this case, each entry is processed by deblank() -## prior to searching for the entries of @var{strlist} in @var{listvar}. -## @strong{Outputs} -## @table @var -## @item idxvec -## vector of indices in @var{listvar}; -## @var{listvar}(@var{idxvec}(@var{k})) == @var{strlist}(@var{kk}). -## @item errmsg -## if strlist contains a string not in @var{listvar}, then -## an error message is returned in @var{errmsg}. If only one output -## argument is requested, e.g., @code{idxvec = listidex(listvar, strlist)}, -## then @var{listidx} prints @var{errmsg} to the screen and exits with +## Inputs: +## listvar: list of strings to be searched +## strlist: list of strings to be located in listvar. +## Note: listvar, strlist may be passed as strings or string matrices; +## in this case, each entry is processed by deblank() prior to searching +## for the entries of strlist in listvar. +## Outputs: +## idxvec +## vector of indices in listvar; +## listvar(idxvec(k)) == strlist(kk). +## errmsg +## if strlist contains a string not in listvar, then +## an error message is returned in errmsg. If only one output +## argument is requested, e.g., idxvec = listidx(listvar, strlist), +## then listidx prints errmsg to the screen and exits with ## an error. -## @end table ## function [idxvec,errmsg] = listidx(listvar,strlist) @@ -55,7 +48,6 @@ for kk=1:rows(tmp) strlist(kk) = deblank(tmp(kk,:)); endfor - strlist endif if(isstr(listvar)) @@ -66,12 +58,23 @@ endfor endif -if(!is_signal_list(listvar)) error("listvar must be a list of strings"); -elseif(!is_signal_list(strlist)) error("strlist must be a list of strings"); +## initialize size of idxvec (for premature return) +idxvec = zeros(length(strlist),1); + +errmsg = ""; +if(!is_signal_list(listvar)) + errmsg = "listvar must be a list of strings"; +elseif(!is_signal_list(strlist)) + errmsg = "strlist must be a list of strings"; +endif + +if(length(errmsg)) + if(nargout < 2) error(errmsg); + else return; + endif endif nsigs = length(listvar); -idxvec = zeros(length(strlist),1); for idx = 1:length(strlist) signame = nth(strlist,idx); for jdx = 1:nsigs
--- a/scripts/control/sysidx.m +++ b/scripts/control/sysidx.m @@ -1,74 +1,34 @@ -## Copyright (C) 1999 Auburn University. All rights reserved. -## -## This file is part of Octave. -## -## Octave is free software; you can redistribute it and/or modify it -## under the terms of the GNU General Public License as published by the -## Free Software Foundation; either version 2, or (at your option) any -## later version. -## -## Octave is distributed in the hope that it will be useful, but WITHOUT -## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -## for more details. -## -## You should have received a copy of the GNU General Public License -## along with Octave; see the file COPYING. If not, write to the Free -## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. - -## idxvec = sysidx(sys,sigtype,signamelist) -## return indices of signals with specified signal names -## inputs: -## sys: OCST system data structure -## sigtype: signal type to be selected: "in", "out", "st" -## signamelist: list of desired signal names -## outputs: -## idxvec: vector of signal indices (appropriate for use with sysprune) - -## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> - -function idxvec = sysidx (sys, sigtype, signamelist) +function idxvec = sysidx(sys,sigtype,signamelist) +# idxvec = sysidx(sys,sigtype,signamelist) +# return indices of signals with specified signal names +# inputs: +# sys: OCST system data structure +# sigtype: signal type to be selected: "in", "out", "st" +# signamelist: list of desired signal names +# outputs: +# idxvec: vector of signal indices (appropriate for use with sysprune) - if(nargin != 3) usage("idxvec = sysidx(sys,sigtype,signamelist)"); - elseif(!is_struct(sys)) error("sys must be a system data structure"); - elseif(!isstr(sigtype)) error("sigtype must be a string"); - elseif(rows(sigtype) != 1) - error("sigtype (%d x %d) must be a single string", ... - rows(sigtype),columns(sigtype)); - elseif(!is_signal_list(signamelist)) - error("signamelist must be a list of strings"); - endif - - sigtype_list = list("input","output","state"); - sigtnum = 0; - for idx = 1:length(sigtype_list) - thistype = nth(sigtype_list,idx); - if(strcmp(sigtype, thistype(1:length(sigtype)) )) sigtnum = idx; endif - endfor - if(sigtnum == 0) error("Illegal sigtype value = %s\n",sigtype); endif - - syssiglist = sysgetsignals(sys,sigtype); +if(nargin != 3) + usage("idxvec = sysidx(sys,sigtype,signamelist)"); +elseif(!is_struct(sys)) + error("sys must be a system data structure"); +elseif(!isstr(sigtype)) + error("sigtype must be a string"); +elseif(rows(sigtype) != 1) + error("sigtype (%d x %d) must be a single string", ... + rows(sigtype),columns(sigtype)); +end - for idx = 1:length(signamelist) - signame = nth(signamelist,idx); - idxvec(idx) = 0; - nsigs = sysdimensions(sys,sigtype); - for jdx = 1:nsigs - ## printf("idx=%d jdx=%d signame=-%s- thissig=-%s-\n",idx,jdx,signame, ... - ## sysgetsignals(sys,sigtype,jdx,1)); - if(strcmp(signame,sysgetsignals(sys,sigtype,jdx,1))) - if(idxvec(idx) != 0) - warning("Duplicate system input %s (%d,%d)\n", ... - sysgetsignals(sys,sigtype,jdx,1),jdx,idxvec(idx)); - else - idxvec(idx) = jdx; - endif - endif - endfor - if(idxvec(idx) == 0) - error("Did not find %s %s",nth(sigtype_list,sigtnum),signame); - endif - endfor +# extract correct set of signal names values +[idxvec,msg] = listidx( list("in","out","st","yd"), sigtype); +if(msg) + error("Illegal sigtype=%s",sigtype); +endif +syssiglist = sysgetsignals(sys,sigtype); +[idxvec,msg] = listidx(syssiglist,signamelist); +if(length(msg)) + error("sysidx(sigtype=%s): %s",sigtype, strrep(msg,"strlist","signamelist")); +end endfunction