eharley0142

all_opts__.m

May 10th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.02 KB | None | 0 0
  1. % Copyright (C) 2009 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.   persistent saved_names;
  31.   % saved_names = {};
  32.  
  33.   % do not clear this function
  34.   mlock ();
  35.  
  36.   % guard against recursive calls.
  37. %  persistent recursive = false;
  38.   persistent recursive;
  39.   % recursive = false;
  40.  
  41.   if (recursive)
  42.     names = {};
  43.   elseif (nargin == 0)
  44.     names = saved_names;
  45.   else
  46.     % query all options from all known functions. These will call optimset,
  47.     % which will in turn call us, but we won't answer.
  48.     recursive = true;
  49.     names = saved_names;
  50.     for i = 1:nargin
  51.       try
  52.         opts = optimset (varargin{i});
  53.         fn = fieldnames (opts).';
  54.         names = [names, fn];
  55.       catch
  56.         % throw the error as a warning.
  57.         warning (lasterr ());
  58.       end
  59.     end
  60.     names = unique (names);
  61.     lnames = unique (tolower (names));
  62.     if (length (lnames) < length (names))
  63.       % This is bad.
  64.       error ('all_opts__: duplicate options with inconsistent case');
  65.     end
  66.     saved_names = names;
  67.     recursive = false;
  68.   end
  69.  
  70. end
Advertisement
Add Comment
Please, Sign In to add comment