Mercurial > octave
diff src/DLD-FUNCTIONS/dassl.cc @ 3243:dd00769643ae
[project @ 1999-05-28 04:19:00 by jwe]
author | jwe |
---|---|
date | Fri, 28 May 1999 04:19:24 +0000 |
parents | 9c5160c83bd2 |
children | 6923abb04e16 |
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/dassl.cc Fri Apr 09 00:20:06 1999 +0000 +++ b/src/DLD-FUNCTIONS/dassl.cc Fri May 28 04:19:24 1999 +0000 @@ -36,6 +36,7 @@ #include "oct-obj.h" #include "ov-fcn.h" #include "pager.h" +#include "unwind-prot.h" #include "utils.h" #include "variables.h" @@ -44,6 +45,9 @@ static DASSL_options dassl_opts; +// Is this a recursive call? +static int call_depth = 0; + ColumnVector dassl_user_function (const ColumnVector& x, const ColumnVector& xdot, double t) { @@ -117,88 +121,100 @@ { octave_value_list retval; - int nargin = args.length (); - - if (nargin < 4 || nargin > 5) - { - print_usage ("dassl"); - return retval; - } - - dassl_fcn = extract_function - (args(0), "dassl", "__dassl_fcn__", - "function res = __dassl_fcn__ (x, xdot, t) res = ", - "; endfunction"); - - if (! dassl_fcn) - return retval; - - ColumnVector state = args(1).vector_value (); + unwind_protect::begin_frame ("Fdassl"); - if (error_state) - { - error ("dassl: expecting state vector as second argument"); - return retval; - } + unwind_protect_int (call_depth); + call_depth++; - ColumnVector deriv = args(2).vector_value (); - - if (error_state) + if (call_depth > 1) { - error ("dassl: expecting derivative vector as third argument"); - return retval; - } - - ColumnVector out_times = args(3).vector_value (); - - if (error_state) - { - error ("dassl: expecting output time vector as fourth argument"); + error ("dassl: invalid recursive call"); return retval; } - ColumnVector crit_times; - int crit_times_set = 0; - if (nargin > 4) + int nargin = args.length (); + + if (nargin > 3 && nargin < 6) { - crit_times = args(4).vector_value (); + dassl_fcn = extract_function + (args(0), "dassl", "__dassl_fcn__", + "function res = __dassl_fcn__ (x, xdot, t) res = ", + "; endfunction"); + + if (! dassl_fcn) + return retval; + + ColumnVector state = args(1).vector_value (); if (error_state) { - error ("dassl: expecting critical time vector as fifth argument"); + error ("dassl: expecting state vector as second argument"); + return retval; + } + + ColumnVector deriv = args(2).vector_value (); + + if (error_state) + { + error ("dassl: expecting derivative vector as third argument"); + return retval; + } + + ColumnVector out_times = args(3).vector_value (); + + if (error_state) + { + error ("dassl: expecting output time vector as fourth argument"); return retval; } - crit_times_set = 1; - } + ColumnVector crit_times; + int crit_times_set = 0; + if (nargin > 4) + { + crit_times = args(4).vector_value (); - if (state.capacity () != deriv.capacity ()) - { - error ("dassl: x and xdot must have the same size"); - return retval; - } + if (error_state) + { + error ("dassl: expecting critical time vector as fifth argument"); + return retval; + } - double tzero = out_times (0); + crit_times_set = 1; + } - DAEFunc func (dassl_user_function); - DASSL dae (state, deriv, tzero, func); - dae.copy (dassl_opts); + if (state.capacity () != deriv.capacity ()) + { + error ("dassl: x and xdot must have the same size"); + return retval; + } + + double tzero = out_times (0); - Matrix output; - Matrix deriv_output; + DAEFunc func (dassl_user_function); + DASSL dae (state, deriv, tzero, func); + dae.copy (dassl_opts); - if (crit_times_set) - output = dae.integrate (out_times, deriv_output, crit_times); - else - output = dae.integrate (out_times, deriv_output); + Matrix output; + Matrix deriv_output; + + if (crit_times_set) + output = dae.integrate (out_times, deriv_output, crit_times); + else + output = dae.integrate (out_times, deriv_output); - if (! error_state) - { - retval.resize (2); + if (! error_state) + { + retval.resize (2); - retval(0) = output; - retval(1) = deriv_output; + retval(0) = output; + retval(1) = deriv_output; + } } + else + print_usage ("dassl"); + + unwind_protect::run_frame ("Fdassl"); return retval; }