annotate scripts/miscellaneous/inputname.m @ 30893:e1788b1a315f

maint: Use "fcn" as preferred abbreviation for "function" in m-files. * accumarray.m, accumdim.m, quadl.m, quadv.m, randi.m, structfun.m, __is_function__.m, uigetfile.m, uimenu.m, uiputfile.m, doc_cache_create.m, colorspace_conversion_input_check.m, imageIO.m, argnames.m, vectorize.m, vectorize.m, normest1.m, inputname.m, nthargout.m, display_info_file.m, decic.m, ode15i.m, ode15s.m, ode23.m, ode23s.m, ode45.m, odeset.m, check_default_input.m, integrate_adaptive.m, ode_event_handler.m, runge_kutta_23.m, runge_kutta_23s.m, runge_kutta_45_dorpri.m, runge_kutta_interpolate.m, starting_stepsize.m, __all_opts__.m, fminbnd.m, fminsearch.m, fminunc.m, fsolve.m, fzero.m, sqp.m, fplot.m, plotyy.m, __bar__.m, __ezplot__.m, flat_entry.html, profexport.m, movfun.m, bicg.m, bicgstab.m, cgs.m, eigs.m, gmres.m, pcg.m, __alltohandles__.m, __sprand__.m, qmr.m, tfqmr.m, dump_demos.m: Replace "func", "fun", "fn" in documentation and variable names with "fcn".
author Rik <rik@octave.org>
date Mon, 04 Apr 2022 18:14:56 -0700
parents 5d3faba0342e
children
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 2004-2022 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/>.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
7 ##
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
9 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23220
diff changeset
10 ## Octave is free software: you can redistribute it and/or modify it
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
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: 23220
diff changeset
12 ## the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
13 ## (at your option) any later version.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
14 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22323
diff changeset
18 ## GNU General Public License for more details.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
19 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
20 ## You should have received a copy of the GNU General Public License
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
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: 23220
diff changeset
22 ## <https://www.gnu.org/licenses/>.
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
23 ##
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ########################################################################
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
25 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
26 ## Original version by Paul Kienzle distributed as free software in the
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5838
diff changeset
27 ## public domain.
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
28
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
29 ## -*- texinfo -*-
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
30 ## @deftypefn {} {@var{namestr} =} inputname (@var{n})
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
31 ## @deftypefnx {} {@var{namestr} =} inputname (@var{n}, @var{ids_only})
10091
a115046d462d inputname: compatibility fix
John W. Eaton <jwe@octave.org>
parents: 7125
diff changeset
32 ## Return the name of the @var{n}-th argument to the calling function.
19195
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18202
diff changeset
33 ##
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
34 ## If the argument is not a simple variable name, return an empty string.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
35 ## Examples which will return @qcode{""} are numbers (@code{5.1}),
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
36 ## expressions (@code{@var{y}/2}), and cell or structure indexing
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
37 ## (@code{@var{c}@{1@}} or @code{@var{s}.@var{field}}).
21069
a1aadf619e3c inputname.m: Clarify docstring.
Rik <rik@octave.org>
parents: 20852
diff changeset
38 ##
a1aadf619e3c inputname.m: Clarify docstring.
Rik <rik@octave.org>
parents: 20852
diff changeset
39 ## @code{inputname} is only useful within a function. When used at the command
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
40 ## line or within a script it always returns an empty string.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
41 ##
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
42 ## By default, return an empty string if the @var{n}-th argument is not a valid
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
43 ## variable name. If the optional argument @var{ids_only} is false, return the
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
44 ## text of the argument even if it is not a valid variable name. This is an
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
45 ## Octave extension that allows the programmer to view exactly how the function
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
46 ## was invoked even when the inputs are complex expressions.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
47 ## @seealso{nargin, narginchk}
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
48 ## @end deftypefn
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
49
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
50 ## FIXME: Actually, it probably *isn't* worth fixing, but there are small
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
51 ## differences between Octave and Matlab.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
52 ##
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
53 ## 1) When called from the top-level or a script, Matlab throws an error
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
54 ##
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
55 ## inputname (1) % at command prompt
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
56 ## % Octave returns "", Matlab throws an error
26214
c0ac6fc191d7 allow inputname to return non-ID arguments (bug #55213)
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
57 ##
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
58 ## 2) cell or struct indexing causes all further names to be returned as ""
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
59 ##
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
60 ## c = {'a', 'b'}
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
61 ## y = 1; z = 2;
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30875
diff changeset
62 ## fcn (c, y, z)
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
63 ## % inputname() would return 'c', 'y', 'z' for the inputs.
30893
e1788b1a315f maint: Use "fcn" as preferred abbreviation for "function" in m-files.
Rik <rik@octave.org>
parents: 30875
diff changeset
64 ## fcn (c{1}, y, z)
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
65 ## % inputname() would return '', '', '' for the inputs.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
66 ##
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
67 ## 3) If inputname is not called from a function, Matlab walks up the stack
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
68 ## until it finds some valid code and then works from there. This could
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
69 ## be relevant for mex files or anonymous functions.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
70 ##
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
71 ## f = @(x) inputname (x);
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
72 ## a = 1:4;
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
73 ## arrayfun (fn, a, 'uniformoutput', false)
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
74 ## % output is {'fn', 'a', '', ''}
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
75
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
76 function namestr = inputname (n, ids_only = true)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
77
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 28749
diff changeset
78 if (nargin < 1)
7125
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
79 print_usage ();
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
80 endif
f084ba47812b [project @ 2007-11-08 02:29:23 by jwe]
jwe
parents: 7017
diff changeset
81
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
82 if (! isscalar (n) || ! isindex (n))
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
83 error ("inputname: N must be a scalar index");
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
84 endif
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
85
20759
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
86 try
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
87 namestr = evalin ("caller", sprintf ("__varval__ ('.argn.'){%d}", n));
20759
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
88 catch
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
89 namestr = "";
20759
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
90 return;
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
91 end_try_catch
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
92
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
93 ## For compatibility with Matlab, return empty string if argument name is
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
94 ## not a valid identifier.
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
95 if (ids_only && ! isvarname (namestr))
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
96 namestr = "";
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
97 elseif (ids_only)
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
98 ## More complicated checking is required to verify name (bug #59103).
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
99 ## NAME may be text, like "Inf", which is an acceptable variable name
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
100 ## that passes isvarname(), but that does not mean it is an actual
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
101 ## variable name, rather than a function or IEEE number.
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
102 try
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
103 v = evalin ("caller",
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
104 sprintf ("evalin ('caller', '__varval__ (\"%s\")')", namestr));
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
105 catch
30875
5d3faba0342e doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents: 30564
diff changeset
106 namestr = "";
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
107 end_try_catch
19195
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18202
diff changeset
108 endif
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18202
diff changeset
109
5837
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
110 endfunction
55404f3b0da1 [project @ 2006-06-01 19:05:31 by jwe]
jwe
parents:
diff changeset
111
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
112
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
113 %!function name = __iname1__ (arg1, arg2, arg3)
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
114 %! name = inputname (1);
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
115 %!endfunction
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
116
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
117 %!function name = __iname1_ID__ (arg1, arg2, arg3)
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
118 %! name = inputname (1, false);
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
119 %!endfunction
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
120
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
121 %!function name = __iname2__ (arg1, arg2, arg3)
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
122 %! name = inputname (2);
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
123 %!endfunction
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
124
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
125 %!function names = __iname3__ (arg1, arg2, arg3)
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
126 %! names = cell (1, 3);
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
127 %! for i = 1:3
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
128 %! names{i} = inputname (i);
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
129 %! endfor
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
130 %!endfunction
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
131
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
132 %!test
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
133 %! assert (__iname1__ ('xvar'), "");
29127
a948253f9976 maint: strip trailing spaces from code base.
Rik <rik@octave.org>
parents: 28929
diff changeset
134 %! xvar = 1;
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
135 %! assert (__iname1__ (xvar), "xvar");
20759
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
136
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
137 %!test
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
138 %! xvar = 1; yvar = 2;
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
139 %! assert (__iname2__ (xvar), "");
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
140 %! assert (__iname2__ (xvar, yvar), "yvar");
20759
2892f62fb37c inputname.m: Return "" rather than strange errors if fcn fails (partial fix for bug #41992).
Rik <rik@octave.org>
parents: 20427
diff changeset
141
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
142 %!test
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
143 %! xvar = 1; yvar = 2;
28929
9e43deb9bfc3 maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents: 28886
diff changeset
144 %! assert (__iname3__ (xvar), {"xvar", "", ""});
9e43deb9bfc3 maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents: 28886
diff changeset
145 %! assert (__iname3__ (xvar, yvar), {"xvar", "yvar", ""});
9e43deb9bfc3 maint: Use semicolon after assert statement inside %!test blocks.
Rik <rik@octave.org>
parents: 28886
diff changeset
146 %! assert (__iname3__ (xvar, 3, yvar), {"xvar", "", "yvar"});
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
147
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
148 ## Test numbers, expressions, indexing operations
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
149 %!test
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
150 %! assert (__iname1__ (1.0), "");
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
151 %! x = 1;
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
152 %! assert (__iname1__ (x / 2), "");
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
153 %! assert (__iname1__ (Inf), "");
26216
96b6b69a1575 * inputname.m: Fix tests for new argument; new tests.
John W. Eaton <jwe@octave.org>
parents: 26214
diff changeset
154
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
155 %!test
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
156 %! assert (__iname1_ID__ (1.0), "1.0");
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
157 %! x = 1;
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
158 %! assert (__iname1_ID__ (x / 2), "x / 2");
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
159 %! assert (__iname1_ID__ (Inf), "Inf");
19195
23519ad614da inputname.m: Overhaul function.
Rik <rik@octave.org>
parents: 18202
diff changeset
160
28886
d8318c12d903 test: remove unnecessary BIST tests in m-files checking for excessive number of inputs.
Rik <rik@octave.org>
parents: 28789
diff changeset
161 %!error <Invalid call> inputname ()
28749
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
162 %!error <N must be a scalar> inputname (ones (2,2))
4e10e25f0fc6 inputname.m: Closer compatibility with Matlab for special values (i,j,NaN,Inf) (bug #59103)
Rik <rik@octave.org>
parents: 27923
diff changeset
163 %!error <N must be a scalar index> inputname (-1)