annotate scripts/ode/private/check_default_input.m @ 28918:d8751a1dda2a

* ode/private/check_default_input.m: Fix nargin check.
author John W. Eaton <jwe@octave.org>
date Wed, 14 Oct 2020 00:26:55 -0400
parents 3c37ae43996a
children 7854d5752dd2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 ##
27919
1891570abac8 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 27918
diff changeset
3 ## Copyright (C) 2016-2020 The Octave Project Developers
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
4 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
7 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
8 ## This file is part of Octave.
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24008
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
11 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24008
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 22910
diff changeset
13 ## (at your option) any later version.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
14 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
24007
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 22910
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e8a74d95b4f3 maint: Use same format for Copyright statement throught code base.
Rik <rik@octave.org>
parents: 22910
diff changeset
18 ## GNU General Public License for more details.
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
19 ##
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
21 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24008
diff changeset
22 ## <https://www.gnu.org/licenses/>.
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 ##
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
25
28901
3c37ae43996a maint: Code cleanup associated with varargin checking.
Rik <rik@octave.org>
parents: 28041
diff changeset
26 function fun = check_default_input (fun, trange, solver, y0, yp0);
3c37ae43996a maint: Code cleanup associated with varargin checking.
Rik <rik@octave.org>
parents: 28041
diff changeset
27
28918
d8751a1dda2a * ode/private/check_default_input.m: Fix nargin check.
John W. Eaton <jwe@octave.org>
parents: 28901
diff changeset
28 if (nargin < 4)
28901
3c37ae43996a maint: Code cleanup associated with varargin checking.
Rik <rik@octave.org>
parents: 28041
diff changeset
29 print_usage ();
3c37ae43996a maint: Code cleanup associated with varargin checking.
Rik <rik@octave.org>
parents: 28041
diff changeset
30 endif
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
31
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
32 ## Check fun
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
33 validateattributes (fun, {"function_handle", "char"}, {}, solver, "fun");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
34
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
35 if (! (nargin (fun) == nargin - 2))
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
36 error ("Octave:invalid-input-arg",
28041
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
37 [solver ": invalid value assigned to field 'fun'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
38 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
39
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
40 if (ischar (fun))
28041
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
41 if (! exist (fun))
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
42 error ("Octave:invalid-input-arg",
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
43 [solver ": function '" fun "' not found"]);
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
44 endif
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
45 fun = str2func (fun);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
46 endif
25803
23483673ba43 Use is_function_handle instead of isa (x, "function_handle").
Rik <rik@octave.org>
parents: 25054
diff changeset
47 if (! is_function_handle (fun))
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
48 error ("Octave:invalid-input-arg",
28041
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
49 [solver ": invalid value assigned to field '" fun "'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
50 endif
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22901
diff changeset
51
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22901
diff changeset
52 ## Check trange
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
53 validateattributes (trange, {"float"}, {"vector", "real"}, solver, "trange");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22901
diff changeset
54
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
55 if (numel (trange) < 2)
28041
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
56 error ("Octave:invalid-input-arg",
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
57 [solver ": invalid value assigned to field 'trange'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
58 elseif (! ((all (diff (trange) > 0)) || all (diff (-trange) > 0)))
28041
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
59 error ("Octave:invalid-input-arg",
5e44268dca6f Replace input validation relying on str2func with alternatives (bug #57351).
Rik <rik@octave.org>
parents: 27923
diff changeset
60 [solver ": invalid value assigned to field 'trange'"]);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
61 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
62
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
63 ## Check y0 and yp0
24008
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
64 if (! isnumeric (y0) || ! isvector (y0))
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
65 error ("Octave:invalid-input-arg",
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
66 [solver ": Y0 must be a numeric vector"]);
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
67 endif
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
68 y0 = y0(:);
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
69
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
70 if (nargin == 5)
24008
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
71 if (! isnumeric (yp0) || ! isvector (yp0))
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
72 error ("Octave:invalid-input-arg",
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
73 [solver ": YP0 must be a numeric vector"]);
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
74 endif
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
75 yp0 = yp0(:);
6e7bb85e32b8 Allow ode15s and ode15i to work with row initial vectors (bug #50192).
Marco Caliari <marco.caliari@univr.it>
parents: 24007
diff changeset
76
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
77 n = numel (feval (fun, trange(1), y0, yp0));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
78 validateattributes (yp0, {"float"}, {"numel", n}, solver, "yp0");
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
79 else
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
80 n = numel (feval (fun, trange (1), y0));
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
81 endif
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
82
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
83 validateattributes (y0, {"float"}, {"numel", n}, solver, "y0");
22910
23847979b91e maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents: 22901
diff changeset
84
22901
4c56f3ffec04 Add functions ode15i and ode15s
Francesco Faccio <francesco.faccio@mail.polimi.it>
parents:
diff changeset
85 endfunction