12#include "DASSL-opts.h"
25struct DASSL_options_struct
30 int min_toks_to_match;
35static DASSL_options_struct DASSL_options_table [] =
37 {
"absolute tolerance",
38 {
"absolute",
"tolerance",
nullptr,
nullptr,
nullptr, },
39 { 1, 0, 0, 0, 0, }, 1, },
41 {
"relative tolerance",
42 {
"relative",
"tolerance",
nullptr,
nullptr,
nullptr, },
43 { 1, 0, 0, 0, 0, }, 1, },
45 {
"compute consistent initial condition",
46 {
"compute",
"consistent",
"initial",
"condition",
nullptr, },
47 { 1, 0, 0, 0, 0, }, 1, },
49 {
"enforce nonnegativity constraints",
50 {
"enforce",
"nonnegativity",
"constraints",
nullptr,
nullptr, },
51 { 1, 0, 0, 0, 0, }, 1, },
53 {
"initial step size",
54 {
"initial",
"step",
"size",
nullptr,
nullptr, },
55 { 1, 0, 0, 0, 0, }, 1, },
58 {
"maximum",
"order",
nullptr,
nullptr,
nullptr, },
59 { 1, 1, 0, 0, 0, }, 2, },
61 {
"maximum step size",
62 {
"maximum",
"step",
"size",
nullptr,
nullptr, },
63 { 1, 1, 0, 0, 0, }, 2, },
66 {
"step",
"limit",
nullptr,
nullptr,
nullptr, },
67 { 1, 0, 0, 0, 0, }, 1, },
71print_DASSL_options (std::ostream& os)
73 std::ostringstream buf;
76 <<
"Options for DASSL include:\n\n"
78 <<
" ------- -----\n";
80 DASSL_options_struct *list = DASSL_options_table;
84 << std::setiosflags (std::ios::left) << std::setw (50)
86 << std::resetiosflags (std::ios::left)
91 if (val.
numel () == 1)
106 << std::setiosflags (std::ios::left) << std::setw (50)
108 << std::resetiosflags (std::ios::left)
113 if (val.
numel () == 1)
115 os << val(0) <<
"\n";
128 << std::setiosflags (std::ios::left) << std::setw (50)
130 << std::resetiosflags (std::ios::left)
133 int val = dassl_opts.compute_consistent_initial_condition ();
140 << std::setiosflags (std::ios::left) << std::setw (50)
142 << std::resetiosflags (std::ios::left)
145 int val = dassl_opts.enforce_nonnegativity_constraints ();
152 << std::setiosflags (std::ios::left) << std::setw (50)
154 << std::resetiosflags (std::ios::left)
157 double val = dassl_opts.initial_step_size ();
164 << std::setiosflags (std::ios::left) << std::setw (50)
166 << std::resetiosflags (std::ios::left)
169 int val = dassl_opts.maximum_order ();
176 << std::setiosflags (std::ios::left) << std::setw (50)
178 << std::resetiosflags (std::ios::left)
181 double val = dassl_opts.maximum_step_size ();
188 << std::setiosflags (std::ios::left) << std::setw (50)
190 << std::resetiosflags (std::ios::left)
193 int val = dassl_opts.step_limit ();
202set_DASSL_options (
const std::string& keyword,
const octave_value& val)
204 DASSL_options_struct *list = DASSL_options_table;
206 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
207 keyword, list[0].min_toks_to_match,
MAX_TOKENS))
211 dassl_opts.set_absolute_tolerance (tmp);
213 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
214 keyword, list[1].min_toks_to_match,
MAX_TOKENS))
218 dassl_opts.set_relative_tolerance (tmp);
220 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
221 keyword, list[2].min_toks_to_match,
MAX_TOKENS))
225 dassl_opts.set_compute_consistent_initial_condition (tmp);
227 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
228 keyword, list[3].min_toks_to_match,
MAX_TOKENS))
232 dassl_opts.set_enforce_nonnegativity_constraints (tmp);
234 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
235 keyword, list[4].min_toks_to_match,
MAX_TOKENS))
239 dassl_opts.set_initial_step_size (tmp);
241 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
242 keyword, list[5].min_toks_to_match,
MAX_TOKENS))
246 dassl_opts.set_maximum_order (tmp);
248 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
249 keyword, list[6].min_toks_to_match,
MAX_TOKENS))
253 dassl_opts.set_maximum_step_size (tmp);
255 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
256 keyword, list[7].min_toks_to_match,
MAX_TOKENS))
260 dassl_opts.set_step_limit (tmp);
264 warning (
"dassl_options: no match for `%s'", keyword.c_str ());
269show_DASSL_options (
const std::string& keyword)
273 DASSL_options_struct *list = DASSL_options_table;
275 if (octave::keyword_almost_match (list[0].kw_tok, list[0].min_len,
276 keyword, list[0].min_toks_to_match,
MAX_TOKENS))
280 if (val.
numel () == 1)
289 else if (octave::keyword_almost_match (list[1].kw_tok, list[1].min_len,
290 keyword, list[1].min_toks_to_match,
MAX_TOKENS))
294 if (val.
numel () == 1)
303 else if (octave::keyword_almost_match (list[2].kw_tok, list[2].min_len,
304 keyword, list[2].min_toks_to_match,
MAX_TOKENS))
306 int val = dassl_opts.compute_consistent_initial_condition ();
308 retval =
static_cast<double> (val);
310 else if (octave::keyword_almost_match (list[3].kw_tok, list[3].min_len,
311 keyword, list[3].min_toks_to_match,
MAX_TOKENS))
313 int val = dassl_opts.enforce_nonnegativity_constraints ();
315 retval =
static_cast<double> (val);
317 else if (octave::keyword_almost_match (list[4].kw_tok, list[4].min_len,
318 keyword, list[4].min_toks_to_match,
MAX_TOKENS))
320 double val = dassl_opts.initial_step_size ();
324 else if (octave::keyword_almost_match (list[5].kw_tok, list[5].min_len,
325 keyword, list[5].min_toks_to_match,
MAX_TOKENS))
327 int val = dassl_opts.maximum_order ();
329 retval =
static_cast<double> (val);
331 else if (octave::keyword_almost_match (list[6].kw_tok, list[6].min_len,
332 keyword, list[6].min_toks_to_match,
MAX_TOKENS))
334 double val = dassl_opts.maximum_step_size ();
338 else if (octave::keyword_almost_match (list[7].kw_tok, list[7].min_len,
339 keyword, list[7].min_toks_to_match,
MAX_TOKENS))
341 int val = dassl_opts.step_limit ();
343 retval =
static_cast<double> (val);
347 warning (
"dassl_options: no match for `%s'", keyword.c_str ());
355DEFUN (dassl_options, args, ,
426 int nargin = args.
length ();
437 std::string keyword = args(0).xstring_value (
"dassl_options: expecting keyword as first argument");
440 retval = show_DASSL_options (keyword);
442 set_DASSL_options (keyword, args(1));
448OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
octave_idx_type numel() const
Number of elements in the array.
int int_value(bool req_int=false, bool frc_str_conv=false) const
Array< double > vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
octave_idx_type length() const
double double_value(bool frc_str_conv=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void octave_print_internal(std::ostream &os, const float_display_format &fmt, bool d, bool pr_as_read_syntax)