]> Creatis software - CreaPhase.git/blob - octave_packages/m/optimization/__all_opts__.m
update packages
[CreaPhase.git] / octave_packages / m / optimization / __all_opts__.m
1 ## Copyright (C) 2009-2012 VZLU Prague
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave 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 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{names} =} __all_opts__ (@dots{})
21 ## Undocumented internal function.
22 ## @end deftypefn
23
24 ## Query all options from all known optimization functions and return a
25 ## list of possible values.
26
27 function names = __all_opts__ (varargin)
28
29   persistent saved_names = {};
30
31   ## do not clear this function
32   mlock ();
33
34   ## guard against recursive calls.
35   persistent recursive = false;
36
37   if (recursive)
38     names = {};
39   elseif (nargin == 0)
40     names = saved_names;
41   else
42     ## query all options from all known functions. These will call optimset,
43     ## which will in turn call us, but we won't answer.
44     recursive = true;
45     names = saved_names;
46     for i = 1:nargin
47       try
48         opts = optimset (varargin{i});
49         fn = fieldnames (opts).';
50         names = [names, fn];
51       catch
52         # throw the error as a warning.
53         warning (lasterr ());
54       end_try_catch
55     endfor
56     names = unique (names);
57     [lnames, idx] = unique (tolower (names));
58     if (length (lnames) < length (names))
59       ## This is bad.
60       error ("__all_opts__: duplicate options with inconsistent case");
61     else
62       names = names(idx);
63     endif
64     saved_names = names;
65     recursive = false;
66   endif
67
68 endfunction
69
70
71 ## No test needed for internal helper function.
72 %!assert (1)
73