3431
|
1 ## Copyright (C) 2000 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
7016
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
3431
|
9 ## |
7016
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
3431
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
3431
|
18 |
3452
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {[@var{idxvec}, @var{errmsg}] =} listidx (@var{listvar}, @var{strlist}) |
|
21 ## Return indices of string entries in @var{listvar} that match strings |
|
22 ## in @var{strlist}. |
3431
|
23 ## |
3452
|
24 ## Both @var{listvar} and @var{strlist} may be passed as strings or |
|
25 ## string matrices. If they are passed as string matrices, each entry |
|
26 ## is processed by @code{deblank} prior to searching for the entries. |
|
27 ## |
|
28 ## The first output is the vector of indices in @var{listvar}. |
|
29 ## |
|
30 ## If @var{strlist} contains a string not in @var{listvar}, then |
|
31 ## an error message is returned in @var{errmsg}. If only one output |
|
32 ## argument is requested, then @var{listidx} prints @var{errmsg} to the |
|
33 ## screen and exits with an error. |
|
34 ## @end deftypefn |
3431
|
35 |
|
36 function [idxvec,errmsg] = listidx(listvar,strlist) |
4771
|
37 error("listidx: don't use this anymore, ok?\n"); |
3431
|
38 |
|
39 if(nargin != 2) |
6046
|
40 print_usage (); |
3431
|
41 endif |
|
42 |
5443
|
43 if(ischar(strlist)) |
3431
|
44 tmp = strlist; |
|
45 strlist = list(); |
|
46 for kk=1:rows(tmp) |
|
47 strlist(kk) = deblank(tmp(kk,:)); |
|
48 endfor |
|
49 endif |
|
50 |
5443
|
51 if(ischar(listvar)) |
3431
|
52 tmp = listvar; |
|
53 listvar = list(); |
|
54 for kk=1:rows(tmp) |
|
55 listvar(kk) = deblank(tmp(kk,:)); |
|
56 endfor |
|
57 endif |
|
58 |
|
59 ## initialize size of idxvec (for premature return) |
|
60 idxvec = zeros(length(strlist),1); |
|
61 |
|
62 errmsg = ""; |
|
63 if(!is_signal_list(listvar)) |
|
64 errmsg = "listvar must be a list of strings"; |
|
65 elseif(!is_signal_list(strlist)) |
|
66 errmsg = "strlist must be a list of strings"; |
|
67 endif |
|
68 |
|
69 if(length(errmsg)) |
|
70 if(nargout < 2) error(errmsg); |
|
71 else return; |
|
72 endif |
|
73 endif |
|
74 |
|
75 nsigs = length(listvar); |
|
76 for idx = 1:length(strlist) |
4771
|
77 signame = strlist{idx}; |
3431
|
78 for jdx = 1:nsigs |
4771
|
79 if( strcmp(signame,listvar{jdx}) ) |
3431
|
80 if(idxvec(idx) != 0) |
|
81 warning("Duplicate signal name %s (%d,%d)\n", ... |
4771
|
82 listvar{jdx},jdx,idxvec(idx)); |
3431
|
83 else |
|
84 idxvec(idx) = jdx; |
|
85 endif |
|
86 endif |
|
87 endfor |
|
88 if(idxvec(idx) == 0) |
|
89 errmsg = sprintf("Did not find %s",signame); |
|
90 if(nargout == 1) |
|
91 error(errmsg); |
|
92 else |
|
93 break |
|
94 end |
|
95 endif |
|
96 endfor |
|
97 |
|
98 endfunction |