Mercurial > hg > octave-nkf
diff src/DLD-FUNCTIONS/daspk.cc @ 3998:f6df65db67f9
[project @ 2002-07-24 18:10:39 by jwe]
author | jwe |
---|---|
date | Wed, 24 Jul 2002 18:10:40 +0000 |
parents | d4091aff6468 |
children | fc2048d4cd21 |
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/daspk.cc +++ b/src/DLD-FUNCTIONS/daspk.cc @@ -41,11 +41,11 @@ #include "utils.h" #include "variables.h" +#include "DASPK-opts.cc" + // Global pointer for user defined function required by daspk. static octave_function *daspk_fcn; -static DASPK_options daspk_opts; - // Is this a recursive call? static int call_depth = 0; @@ -275,180 +275,6 @@ return retval; } -typedef void (DASPK_options::*d_set_opt_mf) (double); -typedef double (DASPK_options::*d_get_opt_mf) (void); - -#define MAX_TOKENS 3 - -struct DASPK_OPTIONS -{ - const char *keyword; - const char *kw_tok[MAX_TOKENS + 1]; - int min_len[MAX_TOKENS + 1]; - int min_toks_to_match; - d_set_opt_mf d_set_fcn; - d_get_opt_mf d_get_fcn; -}; - -static DASPK_OPTIONS daspk_option_table [] = -{ - { "absolute tolerance", - { "absolute", "tolerance", 0, 0, }, - { 1, 0, 0, 0, }, 1, - &DASPK_options::set_absolute_tolerance, - &DASPK_options::absolute_tolerance, }, - - { "initial step size", - { "initial", "step", "size", 0, }, - { 1, 0, 0, 0, }, 1, - &DASPK_options::set_initial_step_size, - &DASPK_options::initial_step_size, }, - - { "maximum step size", - { "maximum", "step", "size", 0, }, - { 2, 0, 0, 0, }, 1, - &DASPK_options::set_maximum_step_size, - &DASPK_options::maximum_step_size, }, - - { "relative tolerance", - { "relative", "tolerance", 0, 0, }, - { 1, 0, 0, 0, }, 1, - &DASPK_options::set_relative_tolerance, - &DASPK_options::relative_tolerance, }, - - { 0, - { 0, 0, 0, 0, }, - { 0, 0, 0, 0, }, 0, - 0, 0, }, -}; - -static void -print_daspk_option_list (std::ostream& os) -{ - print_usage ("daspk_options", 1); - - os << "\n" - << "Options for daspk include:\n\n" - << " keyword value\n" - << " ------- -----\n\n"; - - DASPK_OPTIONS *list = daspk_option_table; - - const char *keyword; - while ((keyword = list->keyword) != 0) - { - os << " " - << std::setiosflags (std::ios::left) << std::setw (40) - << keyword - << std::resetiosflags (std::ios::left) - << " "; - - double val = (daspk_opts.*list->d_get_fcn) (); - if (val < 0.0) - os << "computed automatically"; - else - os << val; - - os << "\n"; - list++; - } - - os << "\n"; -} - -static void -set_daspk_option (const std::string& keyword, double val) -{ - DASPK_OPTIONS *list = daspk_option_table; - - while (list->keyword != 0) - { - if (keyword_almost_match (list->kw_tok, list->min_len, keyword, - list->min_toks_to_match, MAX_TOKENS)) - { - (daspk_opts.*list->d_set_fcn) (val); - - return; - } - list++; - } - - warning ("daspk_options: no match for `%s'", keyword.c_str ()); -} - -static octave_value_list -show_daspk_option (const std::string& keyword) -{ - octave_value retval; - - DASPK_OPTIONS *list = daspk_option_table; - - while (list->keyword != 0) - { - if (keyword_almost_match (list->kw_tok, list->min_len, keyword, - list->min_toks_to_match, MAX_TOKENS)) - { - double val = (daspk_opts.*list->d_get_fcn) (); - if (val < 0.0) - retval = "computed automatically"; - else - retval = val; - - return retval; - } - list++; - } - - warning ("daspk_options: no match for `%s'", keyword.c_str ()); - - return retval; -} - -DEFUN_DLD (daspk_options, args, , - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} daspk_options (@var{opt}, @var{val})\n\ -When called with two arguments, this function allows you set options\n\ -parameters for the function @code{lsode}. Given one argument,\n\ -@code{daspk_options} returns the value of the corresponding option. If\n\ -no arguments are supplied, the names of all the available options and\n\ -their current values are displayed.\n\ -@end deftypefn") -{ - octave_value_list retval; - - int nargin = args.length (); - - if (nargin == 0) - { - print_daspk_option_list (octave_stdout); - return retval; - } - else if (nargin == 1 || nargin == 2) - { - std::string keyword = args(0).string_value (); - - if (! error_state) - { - if (nargin == 1) - return show_daspk_option (keyword); - else - { - double val = args(1).double_value (); - - if (! error_state) - { - set_daspk_option (keyword, val); - return retval; - } - } - } - } - - print_usage ("daspk_options"); - - return retval; -} - /* ;;; Local Variables: *** ;;; mode: C++ ***