Mercurial > octave-nkf
comparison scripts/control/system/listidx.m @ 7136:59dcf01bb3e3
[project @ 2007-11-08 20:18:25 by jwe]
author | jwe |
---|---|
date | Thu, 08 Nov 2007 20:18:26 +0000 |
parents | a1dbe9d80eee |
children |
comparison
equal
deleted
inserted
replaced
7135:8aa770b6c5bf | 7136:59dcf01bb3e3 |
---|---|
32 ## an error message is returned in @var{errmsg}. If only one output | 32 ## an error message is returned in @var{errmsg}. If only one output |
33 ## argument is requested, then @var{listidx} prints @var{errmsg} to the | 33 ## argument is requested, then @var{listidx} prints @var{errmsg} to the |
34 ## screen and exits with an error. | 34 ## screen and exits with an error. |
35 ## @end deftypefn | 35 ## @end deftypefn |
36 | 36 |
37 function [idxvec,errmsg] = listidx(listvar,strlist) | 37 function [idxvec, errmsg] = listidx (listvar, strlist) |
38 error("listidx: don't use this anymore, ok?\n"); | |
39 | 38 |
40 if(nargin != 2) | 39 error ("listidx: don't use this anymore, ok?"); |
41 print_usage (); | |
42 endif | |
43 | 40 |
44 if(ischar(strlist)) | 41 if (nargin != 2) |
45 tmp = strlist; | 42 print_usage (); |
46 strlist = list(); | 43 endif |
47 for kk=1:rows(tmp) | |
48 strlist(kk) = deblank(tmp(kk,:)); | |
49 endfor | |
50 endif | |
51 | 44 |
52 if(ischar(listvar)) | 45 if (ischar (strlist)) |
53 tmp = listvar; | 46 tmp = strlist; |
54 listvar = list(); | 47 strlist = list(); |
55 for kk=1:rows(tmp) | 48 for kk = 1:rows(tmp) |
56 listvar(kk) = deblank(tmp(kk,:)); | 49 strlist(kk) = deblank (tmp(kk,:)); |
57 endfor | 50 endfor |
58 endif | 51 endif |
59 | 52 |
60 ## initialize size of idxvec (for premature return) | 53 if (ischar (listvar)) |
61 idxvec = zeros(length(strlist),1); | 54 tmp = listvar; |
55 listvar = list(); | |
56 for kk = 1:rows(tmp) | |
57 listvar(kk) = deblank (tmp(kk,:)); | |
58 endfor | |
59 endif | |
62 | 60 |
63 errmsg = ""; | 61 ## initialize size of idxvec (for premature return) |
64 if(!is_signal_list(listvar)) | 62 idxvec = zeros (length(strlist), 1); |
65 errmsg = "listvar must be a list of strings"; | |
66 elseif(!is_signal_list(strlist)) | |
67 errmsg = "strlist must be a list of strings"; | |
68 endif | |
69 | 63 |
70 if(length(errmsg)) | 64 errmsg = ""; |
71 if(nargout < 2) error(errmsg); | 65 if (! is_signal_list (listvar)) |
72 else return; | 66 errmsg = "listvar must be a list of strings"; |
67 elseif (! is_signal_list(strlist)) | |
68 errmsg = "strlist must be a list of strings"; | |
73 endif | 69 endif |
74 endif | |
75 | 70 |
76 nsigs = length(listvar); | 71 if (length (errmsg)) |
77 for idx = 1:length(strlist) | 72 if (nargout < 2) |
78 signame = strlist{idx}; | 73 error(errmsg); |
79 for jdx = 1:nsigs | 74 else |
80 if( strcmp(signame,listvar{jdx}) ) | 75 return; |
81 if(idxvec(idx) != 0) | 76 endif |
82 warning("Duplicate signal name %s (%d,%d)\n", ... | 77 endif |
83 listvar{jdx},jdx,idxvec(idx)); | 78 |
79 nsigs = length (listvar); | |
80 for idx = 1:length(strlist) | |
81 signame = strlist{idx}; | |
82 for jdx = 1:nsigs | |
83 if (strcmp (signame, listvar{jdx})) | |
84 if (idxvec(idx) != 0) | |
85 warning ("Duplicate signal name %s (%d,%d)\n", | |
86 listvar{jdx}, jdx, idxvec(idx)); | |
87 else | |
88 idxvec(idx) = jdx; | |
89 endif | |
90 endif | |
91 endfor | |
92 if (idxvec (idx) == 0) | |
93 errmsg = sprintf ("Did not find %s", signame); | |
94 if (nargout == 1) | |
95 error (errmsg); | |
84 else | 96 else |
85 idxvec(idx) = jdx; | 97 break; |
86 endif | 98 endif |
87 endif | 99 endif |
88 endfor | 100 endfor |
89 if(idxvec(idx) == 0) | |
90 errmsg = sprintf("Did not find %s",signame); | |
91 if(nargout == 1) | |
92 error(errmsg); | |
93 else | |
94 break | |
95 end | |
96 endif | |
97 endfor | |
98 | 101 |
99 endfunction | 102 endfunction |