diff src/DLD-FUNCTIONS/lsode.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/lsode.cc	Wed Jul 17 18:00:07 2002 +0000
+++ b/src/DLD-FUNCTIONS/lsode.cc	Wed Jul 24 18:10:40 2002 +0000
@@ -43,14 +43,14 @@
 #include "utils.h"
 #include "variables.h"
 
+#include "LSODE-opts.cc"
+
 // Global pointer for user defined function required by lsode.
 static octave_function *lsode_fcn;
 
 // Global pointer for optional user defined jacobian function used by lsode.
 static octave_function *lsode_jac;
 
-static LSODE_options lsode_opts;
-
 // Is this a recursive call?
 static int call_depth = 0;
 
@@ -313,354 +313,6 @@
   return retval;
 }
 
-typedef void (LSODE_options::*da_set_opt_mf) (const Array<double>&);
-typedef void (LSODE_options::*d_set_opt_mf) (double);
-typedef void (LSODE_options::*i_set_opt_mf) (int);
-typedef void (LSODE_options::*s_set_opt_mf) (const std::string&);
-
-typedef Array<double> (LSODE_options::*da_get_opt_mf) (void) const;
-typedef double (LSODE_options::*d_get_opt_mf) (void) const;
-typedef int (LSODE_options::*i_get_opt_mf) (void) const;
-typedef std::string (LSODE_options::*s_get_opt_mf) (void) const;
-
-#define MAX_TOKENS 3
-
-struct LSODE_OPTIONS
-{
-  const char *keyword;
-  const char *kw_tok[MAX_TOKENS + 1];
-  int min_len[MAX_TOKENS + 1];
-  int min_toks_to_match;
-  da_set_opt_mf da_set_fcn;
-  d_set_opt_mf d_set_fcn;
-  i_set_opt_mf i_set_fcn;
-  s_set_opt_mf s_set_fcn;
-  da_get_opt_mf da_get_fcn;
-  d_get_opt_mf d_get_fcn;
-  i_get_opt_mf i_get_fcn;
-  s_get_opt_mf s_get_fcn;
-};
-
-static LSODE_OPTIONS lsode_option_table [] =
-{
-  { "absolute tolerance",
-    { "absolute", "tolerance", 0, 0, },
-    { 1, 0, 0, 0, }, 1,
-    &LSODE_options::set_absolute_tolerance, 0, 0, 0,
-    &LSODE_options::absolute_tolerance, 0, 0, 0, },
-
-  { "initial step size",
-    { "initial", "step", "size", 0, },
-    { 3, 0, 0, 0, }, 1,
-    0, &LSODE_options::set_initial_step_size, 0, 0,
-    0, &LSODE_options::initial_step_size, 0, 0, },
-
-  { "integration method",
-    { "integration", "method", 0, 0, },
-    { 3, 0, 0, 0, }, 1,
-    0, 0, 0, &LSODE_options::set_integration_method,
-    0, 0, 0, &LSODE_options::integration_method, },
-
-  { "maximum step size",
-    { "maximum", "step", "size", 0, },
-    { 2, 0, 0, 0, }, 1,
-    0, &LSODE_options::set_maximum_step_size, 0, 0,
-    0, &LSODE_options::maximum_step_size, 0, 0, },
-
-  { "minimum step size",
-    { "minimum", "step", "size", 0, },
-    { 2, 0, 0, 0, }, 1,
-    0, &LSODE_options::set_minimum_step_size, 0, 0,
-    0, &LSODE_options::minimum_step_size, 0, 0, },
-
-  { "relative tolerance",
-    { "relative", "tolerance", 0, 0, },
-    { 1, 0, 0, 0, }, 1,
-    0, &LSODE_options::set_relative_tolerance, 0, 0,
-    0, &LSODE_options::relative_tolerance, 0, 0, },
-
-  { "step limit",
-    { "step", "limit", 0, 0, },
-    { 1, 0, 0, 0, }, 1,
-    0, 0, &LSODE_options::set_step_limit, 0,
-    0, 0, &LSODE_options::step_limit, 0, },
-
-  { 0,
-    { 0, 0, 0, 0, },
-    { 0, 0, 0, 0, }, 0,
-    0, 0, 0, 0,
-    0, 0, 0, 0, },
-};
-
-static void
-print_lsode_option_list (std::ostream& os)
-{
-  print_usage ("lsode_options", 1);
-
-  os << "\n"
-     << "Options for lsode include:\n\n"
-     << "  keyword                                  value\n"
-     << "  -------                                  -----\n\n";
-
-  LSODE_OPTIONS *list = lsode_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)
-	 << " ";
-
-      if (list->da_get_fcn)
-	{
-	  Array<double> val = (lsode_opts.*list->da_get_fcn) ();
-	  if (val.length () == 1)
-	    {
-	      if (val(0) < 0.0)
-		os << "computed automatically";
-	      else
-		os << val(0);
-	    }
-	  else
-	    {
-	      os << "\n\n";
-	      // XXX FIXME XXX
-	      Matrix tmp = Matrix (ColumnVector (val));
-	      octave_print_internal (os, tmp, false, 2);
-	      os << "\n";
-	    }
-	}
-      else if (list->d_get_fcn)
-	{
-	  double val = (lsode_opts.*list->d_get_fcn) ();
-	  if (val < 0.0)
-	    os << "computed automatically";
-	  else
-	    os << val;
-	}
-      else if (list->i_get_fcn)
-	{
-	  int val = (lsode_opts.*list->i_get_fcn) ();
-	  if (val < 0)
-	    os << "infinite";
-	  else
-	    os << val;
-	}
-      else if (list->s_get_fcn)
-	{
-	  os << (lsode_opts.*list->s_get_fcn) ();
-	}
-      else
-	panic_impossible ();
-
-      os << "\n";
-      list++;
-    }
-
-  os << "\n";
-}
-
-static void
-set_lsode_option (const std::string& keyword, double val)
-{
-  LSODE_OPTIONS *list = lsode_option_table;
-
-  while (list->keyword != 0)
-    {
-      if (keyword_almost_match (list->kw_tok, list->min_len, keyword,
-				list->min_toks_to_match, MAX_TOKENS))
-	{
-	  if (list->da_set_fcn)
-	    {
-	      Array<double> tmp (1, val);
-	      (lsode_opts.*list->da_set_fcn) (tmp);
-	    }
-	  else if (list->d_set_fcn)
-	    {
-	      (lsode_opts.*list->d_set_fcn) (val);
-	    }
-	  else
-	    {
-	      if (xisnan (val))
-		{
-		  error ("lsode_options: %s: expecting integer, found NaN",
-			 keyword.c_str ());
-		}
-	      else
-		(lsode_opts.*list->i_set_fcn) (NINT (val));
-	    }
-	  return;
-	}
-      list++;
-    }
-
-  warning ("lsode_options: no match for `%s'", keyword.c_str ());
-}
-
-static void
-set_lsode_option (const std::string& keyword, const Array<double>& val)
-{
-  LSODE_OPTIONS *list = lsode_option_table;
-
-  while (list->keyword != 0)
-    {
-      if (keyword_almost_match (list->kw_tok, list->min_len, keyword,
-				list->min_toks_to_match, MAX_TOKENS))
-	{
-	  if (list->da_set_fcn)
-	    (lsode_opts.*list->da_set_fcn) (val);
-	  else
-	    error ("lsode_options: no function to handle vector option");
-
-	  return;
-	}
-      list++;
-    }
-
-  warning ("lsode_options: no match for `%s'", keyword.c_str ());
-}
-
-static void
-set_lsode_option (const std::string& keyword, const std::string& val)
-{
-  LSODE_OPTIONS *list = lsode_option_table;
-
-  while (list->keyword != 0)
-    {
-      if (keyword_almost_match (list->kw_tok, list->min_len, keyword,
-				list->min_toks_to_match, MAX_TOKENS))
-	{
-	  if (list->s_set_fcn)
-	    (lsode_opts.*list->s_set_fcn) (val);
-	  else
-	    error ("lsode_options: no function to handle string option");
-
-	  return;
-	}
-      list++;
-    }
-
-  warning ("lsode_options: no match for `%s'", keyword.c_str ());
-}
-
-static octave_value_list
-show_lsode_option (const std::string& keyword)
-{
-  octave_value retval;
-
-  LSODE_OPTIONS *list = lsode_option_table;
-
-  while (list->keyword != 0)
-    {
-      if (keyword_almost_match (list->kw_tok, list->min_len, keyword,
-				list->min_toks_to_match, MAX_TOKENS))
-	{
-	  if (list->da_get_fcn)
-	    {
-	      Array<double> val = (lsode_opts.*list->da_get_fcn) ();
-	      if (val.length () == 1)
-		{
-		  if (val(0) < 0.0)
-		    retval = "computed automatically";
-		  else
-		    retval = val(0);
-		}
-	      else
-		retval = ColumnVector (val);
-	    }
-	  else if (list->d_get_fcn)
-	    {
-	      double val = (lsode_opts.*list->d_get_fcn) ();
-	      if (val < 0.0)
-		retval = "computed automatically";
-	      else
-		retval = val;
-	    }
-	  else if (list->i_get_fcn)
-	    {
-	      int val = (lsode_opts.*list->i_get_fcn) ();
-	      if (val < 0)
-		retval = "infinite";
-	      else
-		retval = static_cast<double> (val);
-	    }
-	  else if (list->s_get_fcn)
-	    {
-	      retval = (lsode_opts.*list->s_get_fcn) ();
-	    }
-	  else
-	    panic_impossible ();
-
-	  return retval;
-	}
-      list++;
-    }
-
-  warning ("lsode_options: no match for `%s'", keyword.c_str ());
-
-  return retval;
-}
-
-DEFUN_DLD (lsode_options, args, ,
-  "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} lsode_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{lsode_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_lsode_option_list (octave_stdout);
-    }
-  else if (nargin == 1 || nargin == 2)
-    {
-      std::string keyword = args(0).string_value ();
-
-      if (! error_state)
-	{
-	  if (nargin == 1)
-	    retval = show_lsode_option (keyword);
-	  else
-	    {
-	      if (args(1).is_string ())
-		{
-		  std::string val = args(1).string_value ();
-
-		  if (! error_state)
-		    set_lsode_option (keyword, val);
-		}
-	      else if (args(1).is_scalar_type ())
-		{
-		  double val = args(1).double_value ();
-
-		  if (! error_state)
-		    set_lsode_option (keyword, val);
-		}
-	      else
-		{
-		  Array<double> val = args(1).vector_value ();
-
-		  if (! error_state)
-		    set_lsode_option (keyword, val);
-		}
-	    }
-	}
-    }
-  else
-    print_usage ("lsode_options");
-
-  return retval;
-}
-
 /*
 ;;; Local Variables: ***
 ;;; mode: C++ ***