]> Creatis software - CreaPhase.git/blob - octave_packages/m/deprecated/cellidx.m
update packages
[CreaPhase.git] / octave_packages / m / deprecated / cellidx.m
1 ## Copyright (C) 2000-2012 Auburn University.  All rights reserved.
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave program is free software; you can redistribute it and/or modify it
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.
9 ##
10 ## Octave program 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.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {[@var{idxvec}, @var{errmsg}] =} cellidx (@var{listvar}, @var{strlist})
21 ## Return indices of string entries in @var{listvar} that match strings
22 ## in @var{strlist}.
23 ##
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{cellidx} prints @var{errmsg} to the
33 ## screen and exits with an error.
34 ## @end deftypefn
35
36 ## deprecated in version 3.4
37
38 function [idxvec,errmsg]  = cellidx (listvar, strlist)
39
40   persistent warned = false;
41   if (! warned)
42     warned = true;
43     warning ("Octave:deprecated-function",
44              "cellidx is obsolete and will be removed from a future version of Octave; use ismember instead");
45   endif
46
47   if (nargin != 2)
48     print_usage ();
49   endif
50
51   if (ischar (strlist))
52     tmp = strlist;
53     strlist = {};
54     for kk = 1:rows(tmp)
55       strlist{kk} = deblank (tmp(kk,:));
56     endfor
57   endif
58
59   if (ischar (listvar))
60     tmp = listvar;
61     listvar = {};
62     for kk = 1:rows(tmp)
63       listvar{kk} = deblank (tmp(kk,:));
64     endfor
65   endif
66
67   ## initialize size of idxvec (for premature return)
68   idxvec = zeros (length(strlist), 1);
69
70   errmsg = "";
71   if (! iscellstr (listvar))
72     errmsg = "listvar must be a list of strings";
73   elseif (! iscellstr (strlist))
74     errmsg = "strlist must be a list of strings";
75   endif
76
77   if (length (errmsg))
78     if (nargout < 2)
79       error (errmsg);
80     else
81       return;
82     endif
83   endif
84
85   nsigs = length(listvar);
86   for idx = 1:length(strlist)
87     signame = strlist{idx};
88     for jdx = 1:nsigs
89       if (strcmp (signame, listvar{jdx}))
90         if (idxvec(idx) != 0)
91           warning ("Duplicate signal name %s (%d,%d)\n",
92                    listvar{jdx}, jdx, idxvec(idx));
93         else
94           idxvec(idx) = jdx;
95         endif
96       endif
97     endfor
98     if (idxvec(idx) == 0)
99       errmsg = sprintf ("Did not find %s", signame);
100       if (nargout == 1)
101         error (errmsg);
102       else
103         break;
104       endif
105     endif
106   endfor
107
108 endfunction