annotate src/DLD-FUNCTIONS/daspk.cc @ 3912:f56cd411adb4

[project @ 2002-04-28 03:12:27 by jwe]
author jwe
date Sun, 28 Apr 2002 03:12:28 +0000
parents
children 3030cb6cb559
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3912
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
1 /*
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
2
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
3 Copyright (C) 1996, 1997, 2002 John W. Eaton
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
4
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
6
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
10 later version.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
11
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
15 for more details.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
16
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
20
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
21 */
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
22
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
25 #endif
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
26
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
27 #include <string>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
28
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
29 #include <iomanip>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
30 #include <iostream>
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
31
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
32 #include "DASPK.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
33
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
34 #include "defun-dld.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
35 #include "error.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
36 #include "gripes.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
37 #include "oct-obj.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
38 #include "ov-fcn.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
39 #include "pager.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
40 #include "unwind-prot.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
41 #include "utils.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
42 #include "variables.h"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
43
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
44 // Global pointer for user defined function required by daspk.
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
45 static octave_function *daspk_fcn;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
46
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
47 static DASPK_options daspk_opts;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
48
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
49 // Is this a recursive call?
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
50 static int call_depth = 0;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
51
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
52 ColumnVector
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
53 daspk_user_function (const ColumnVector& x, const ColumnVector& xdot,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
54 double t, int& ires)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
55 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
56 ColumnVector retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
57
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
58 int nstates = x.capacity ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
59
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
60 assert (nstates == xdot.capacity ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
61
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
62 octave_value_list args;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
63 args(2) = t;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
64
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
65 if (nstates > 1)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
66 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
67 Matrix m1 (nstates, 1);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
68 Matrix m2 (nstates, 1);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
69 for (int i = 0; i < nstates; i++)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
70 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
71 m1 (i, 0) = x (i);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
72 m2 (i, 0) = xdot (i);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
73 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
74 octave_value state (m1);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
75 octave_value deriv (m2);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
76 args(1) = deriv;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
77 args(0) = state;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
78 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
79 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
80 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
81 double d1 = x (0);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
82 double d2 = xdot (0);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
83 octave_value state (d1);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
84 octave_value deriv (d2);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
85 args(1) = deriv;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
86 args(0) = state;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
87 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
88
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
89 if (daspk_fcn)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
90 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
91 octave_value_list tmp = daspk_fcn->do_multi_index_op (1, args);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
92
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
93 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
94 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
95 gripe_user_supplied_eval ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
96 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
97 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
98
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
99 int tlen = tmp.length ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
100 if (tlen > 0 && tmp(0).is_defined ())
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
101 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
102 retval = ColumnVector (tmp(0).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
103
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
104 if (tlen > 1)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
105 ires = tmp(1).int_value ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
106
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
107 if (error_state || retval.length () == 0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
108 gripe_user_supplied_eval ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
109 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
110 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
111 gripe_user_supplied_eval ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
112 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
113
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
114 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
115 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
116
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
117 #define DASPK_ABORT() \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
118 do \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
119 { \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
120 unwind_protect::run_frame ("Fdaspk"); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
121 return retval; \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
122 } \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
123 while (0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
124
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
125 #define DASPK_ABORT1(msg) \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
126 do \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
127 { \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
128 ::error ("daspk: " msg); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
129 DASPK_ABORT (); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
130 } \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
131 while (0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
132
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
133 #define DASPK_ABORT2(fmt, arg) \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
134 do \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
135 { \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
136 ::error ("daspk: " fmt, arg); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
137 DASPK_ABORT (); \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
138 } \
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
139 while (0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
140
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
141 DEFUN_DLD (daspk, args, ,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
142 "-*- texinfo -*-\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
143 @deftypefn {Loadable Function} {[@var{x}, @var{xdot}] =} daspk (@var{fcn}, @var{x0}, @var{xdot0}, @var{t}, @var{t_crit})\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
144 Return a matrix of states and their first derivatives with respect to\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
145 @var{t}. Each row in the result matrices correspond to one of the\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
146 elements in the vector @var{t}. The first element of @var{t}\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
147 corresponds to the initial state @var{x0} and derivative @var{xdot0}, so\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
148 that the first row of the output @var{x} is @var{x0} and the first row\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
149 of the output @var{xdot} is @var{xdot0}.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
150 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
151 The first argument, @var{fcn}, is a string that names the function to\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
152 call to compute the vector of residuals for the set of equations.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
153 It must have the form\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
154 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
155 @example\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
156 @var{res} = f (@var{x}, @var{xdot}, @var{t})\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
157 @end example\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
158 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
159 @noindent\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
160 where @var{x}, @var{xdot}, and @var{res} are vectors, and @var{t} is a\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
161 scalar.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
162 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
163 The second and third arguments to @code{daspk} specify the initial\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
164 condition of the states and their derivatives, and the fourth argument\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
165 specifies a vector of output times at which the solution is desired, \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
166 including the time corresponding to the initial condition.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
167 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
168 The set of initial states and derivatives are not strictly required to\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
169 be consistent. In practice, however, @sc{Dassl} is not very good at\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
170 determining a consistent set for you, so it is best if you ensure that\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
171 the initial values result in the function evaluating to zero.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
172 \n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
173 The fifth argument is optional, and may be used to specify a set of\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
174 times that the DAE solver should not integrate past. It is useful for\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
175 avoiding difficulties with singularities and points where there is a\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
176 discontinuity in the derivative.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
177 @end deftypefn")
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
178 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
179 octave_value_list retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
180
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
181 unwind_protect::begin_frame ("Fdaspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
182
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
183 unwind_protect_int (call_depth);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
184 call_depth++;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
185
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
186 if (call_depth > 1)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
187 DASPK_ABORT1 ("invalid recursive call");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
188
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
189 int nargin = args.length ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
190
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
191 if (nargin > 3 && nargin < 6)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
192 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
193 daspk_fcn = extract_function
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
194 (args(0), "daspk", "__daspk_fcn__",
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
195 "function res = __daspk_fcn__ (x, xdot, t) res = ",
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
196 "; endfunction");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
197
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
198 if (! daspk_fcn)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
199 DASPK_ABORT ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
200
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
201 ColumnVector state = ColumnVector (args(1).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
202
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
203 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
204 DASPK_ABORT1 ("expecting state vector as second argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
205
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
206 ColumnVector deriv (args(2).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
207
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
208 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
209 DASPK_ABORT1 ("expecting derivative vector as third argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
210
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
211 ColumnVector out_times (args(3).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
212
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
213 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
214 DASPK_ABORT1 ("expecting output time vector as fourth argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
215
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
216 ColumnVector crit_times;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
217 int crit_times_set = 0;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
218 if (nargin > 4)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
219 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
220 crit_times = ColumnVector (args(4).vector_value ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
221
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
222 if (error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
223 DASPK_ABORT1 ("expecting critical time vector as fifth argument");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
224
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
225 crit_times_set = 1;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
226 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
227
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
228 if (state.capacity () != deriv.capacity ())
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
229 DASPK_ABORT1 ("x and xdot must have the same size");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
230
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
231 double tzero = out_times (0);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
232
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
233 DAEFunc func (daspk_user_function);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
234 DASPK dae (state, deriv, tzero, func);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
235 dae.copy (daspk_opts);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
236
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
237 Matrix output;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
238 Matrix deriv_output;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
239
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
240 if (crit_times_set)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
241 output = dae.integrate (out_times, deriv_output, crit_times);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
242 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
243 output = dae.integrate (out_times, deriv_output);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
244
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
245 if (! error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
246 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
247 retval.resize (2);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
248
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
249 retval(0) = output;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
250 retval(1) = deriv_output;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
251 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
252 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
253 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
254 print_usage ("daspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
255
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
256 unwind_protect::run_frame ("Fdaspk");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
257
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
258 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
259 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
260
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
261 typedef void (DASPK_options::*d_set_opt_mf) (double);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
262 typedef double (DASPK_options::*d_get_opt_mf) (void);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
263
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
264 #define MAX_TOKENS 3
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
265
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
266 struct DASPK_OPTIONS
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
267 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
268 const char *keyword;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
269 const char *kw_tok[MAX_TOKENS + 1];
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
270 int min_len[MAX_TOKENS + 1];
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
271 int min_toks_to_match;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
272 d_set_opt_mf d_set_fcn;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
273 d_get_opt_mf d_get_fcn;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
274 };
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
275
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
276 static DASPK_OPTIONS daspk_option_table [] =
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
277 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
278 { "absolute tolerance",
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
279 { "absolute", "tolerance", 0, 0, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
280 { 1, 0, 0, 0, }, 1,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
281 &DASPK_options::set_absolute_tolerance,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
282 &DASPK_options::absolute_tolerance, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
283
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
284 { "initial step size",
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
285 { "initial", "step", "size", 0, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
286 { 1, 0, 0, 0, }, 1,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
287 &DASPK_options::set_initial_step_size,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
288 &DASPK_options::initial_step_size, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
289
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
290 { "maximum step size",
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
291 { "maximum", "step", "size", 0, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
292 { 2, 0, 0, 0, }, 1,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
293 &DASPK_options::set_maximum_step_size,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
294 &DASPK_options::maximum_step_size, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
295
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
296 { "relative tolerance",
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
297 { "relative", "tolerance", 0, 0, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
298 { 1, 0, 0, 0, }, 1,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
299 &DASPK_options::set_relative_tolerance,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
300 &DASPK_options::relative_tolerance, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
301
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
302 { 0,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
303 { 0, 0, 0, 0, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
304 { 0, 0, 0, 0, }, 0,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
305 0, 0, },
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
306 };
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
307
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
308 static void
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
309 print_daspk_option_list (std::ostream& os)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
310 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
311 print_usage ("daspk_options", 1);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
312
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
313 os << "\n"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
314 << "Options for daspk include:\n\n"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
315 << " keyword value\n"
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
316 << " ------- -----\n\n";
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
317
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
318 DASPK_OPTIONS *list = daspk_option_table;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
319
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
320 const char *keyword;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
321 while ((keyword = list->keyword) != 0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
322 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
323 os << " "
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
324 << std::setiosflags (std::ios::left) << std::setw (40)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
325 << keyword
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
326 << std::resetiosflags (std::ios::left)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
327 << " ";
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
328
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
329 double val = (daspk_opts.*list->d_get_fcn) ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
330 if (val < 0.0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
331 os << "computed automatically";
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
332 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
333 os << val;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
334
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
335 os << "\n";
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
336 list++;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
337 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
338
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
339 os << "\n";
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
340 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
341
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
342 static void
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
343 set_daspk_option (const std::string& keyword, double val)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
344 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
345 DASPK_OPTIONS *list = daspk_option_table;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
346
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
347 while (list->keyword != 0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
348 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
349 if (keyword_almost_match (list->kw_tok, list->min_len, keyword,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
350 list->min_toks_to_match, MAX_TOKENS))
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
351 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
352 (daspk_opts.*list->d_set_fcn) (val);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
353
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
354 return;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
355 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
356 list++;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
357 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
358
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
359 warning ("daspk_options: no match for `%s'", keyword.c_str ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
360 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
361
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
362 static octave_value_list
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
363 show_daspk_option (const std::string& keyword)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
364 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
365 octave_value retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
366
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
367 DASPK_OPTIONS *list = daspk_option_table;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
368
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
369 while (list->keyword != 0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
370 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
371 if (keyword_almost_match (list->kw_tok, list->min_len, keyword,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
372 list->min_toks_to_match, MAX_TOKENS))
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
373 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
374 double val = (daspk_opts.*list->d_get_fcn) ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
375 if (val < 0.0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
376 retval = "computed automatically";
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
377 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
378 retval = val;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
379
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
380 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
381 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
382 list++;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
383 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
384
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
385 warning ("daspk_options: no match for `%s'", keyword.c_str ());
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
386
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
387 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
388 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
389
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
390 DEFUN_DLD (daspk_options, args, ,
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
391 "-*- texinfo -*-\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
392 @deftypefn {Loadable Function} {} daspk_options (@var{opt}, @var{val})\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
393 When called with two arguments, this function allows you set options\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
394 parameters for the function @code{lsode}. Given one argument,\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
395 @code{daspk_options} returns the value of the corresponding option. If\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
396 no arguments are supplied, the names of all the available options and\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
397 their current values are displayed.\n\
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
398 @end deftypefn")
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
399 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
400 octave_value_list retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
401
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
402 int nargin = args.length ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
403
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
404 if (nargin == 0)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
405 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
406 print_daspk_option_list (octave_stdout);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
407 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
408 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
409 else if (nargin == 1 || nargin == 2)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
410 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
411 std::string keyword = args(0).string_value ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
412
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
413 if (! error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
414 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
415 if (nargin == 1)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
416 return show_daspk_option (keyword);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
417 else
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
418 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
419 double val = args(1).double_value ();
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
420
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
421 if (! error_state)
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
422 {
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
423 set_daspk_option (keyword, val);
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
424 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
425 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
426 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
427 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
428 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
429
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
430 print_usage ("daspk_options");
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
431
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
432 return retval;
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
433 }
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
434
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
435 /*
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
436 ;;; Local Variables: ***
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
437 ;;; mode: C++ ***
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
438 ;;; End: ***
f56cd411adb4 [project @ 2002-04-28 03:12:27 by jwe]
jwe
parents:
diff changeset
439 */