Mercurial > octave
changeset 24217:2391bd89adf8
fix dasrt argument parsing for constraint function
* dasrt.cc (Fdasrt): Correct argument parsing to correctly allow
constraint function to be skipped. Detect too few arguments properly.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Nov 2017 18:45:09 -0500 |
parents | 81d723f0cdfe |
children | 3d26a174e143 |
files | libinterp/corefcn/dasrt.cc |
diffstat | 1 files changed, 27 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/dasrt.cc Wed Nov 08 16:30:07 2017 -0500 +++ b/libinterp/corefcn/dasrt.cc Wed Nov 08 18:45:09 2017 -0500 @@ -465,23 +465,37 @@ argp++; - if (args(1).is_function_handle () || args(1).is_inline_function ()) - dasrt_cf = args(1).function_value (); + if (args(1).isempty () && args(1).is_double_type ()) + { + // Allow [] to skip constraint function. This feature is + // undocumented now, but was supported by earlier versions. + + argp++; + } else { - fcn_name = unique_symbol_name ("__dasrt_constraint_fcn__"); - fname = "function g_out = "; - fname.append (fcn_name); - fname.append (" (x, t) g_out = "); - dasrt_cf = extract_function (f_arg, "dasrt", fcn_name, fname, - "; endfunction"); + if (args(1).is_function_handle () || args(1).is_inline_function ()) + dasrt_cf = args(1).function_value (); + else if (args(1).is_string ()) + { + fcn_name = unique_symbol_name ("__dasrt_constraint_fcn__"); + fname = "function g_out = "; + fname.append (fcn_name); + fname.append (" (x, t) g_out = "); + dasrt_cf = extract_function (args(1), "dasrt", fcn_name, fname, + "; endfunction"); + } + + if (dasrt_cf) + { + argp++; + + func.set_constraint_function (dasrt_user_cf); + } } - if (! dasrt_cf) - error ("dasrt: invalid constraint function G"); - - argp++; - func.set_constraint_function (dasrt_user_cf); + if (argp + 3 > nargin) + print_usage (); ColumnVector state = args(argp++).xvector_value ("dasrt: initial state X_0 must be a vector");