Skip to content

Commit e4eae01

Browse files
committed
indicating optional arguments and constraining the number of arguments
The word optional for arguments are not necessary have been included. Explicit constraints to the number of arguments of div, grad, and lap were added.
1 parent 51417dd commit e4eae01

9 files changed

Lines changed: 63 additions & 27 deletions

File tree

src/matlab/div.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
% k : Order of accuracy
88
% m : Number of cells
99
% dx : Step size
10-
% dc : a0 (2x1 vector for left and right vertices, resp.)
11-
% nc : b0 (2x1 vector for left and right vertices, resp.)
10+
% (optional) dc : a0 (2x1 vector for left and right vertices, resp.)
11+
% (optional) nc : b0 (2x1 vector for left and right vertices, resp.)
1212
%
1313
% ----------------------------------------------------------------------------
1414
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -17,8 +17,12 @@
1717
% ----------------------------------------------------------------------------
1818
%
1919

20+
if nargin ~= 3 && nargin ~= 5
21+
error('div:InvalidNumArgs', 'div expects 3 or 5 arguments');
22+
end
23+
2024
% for legacy code
21-
if nargin <= 3
25+
if nargin == 3
2226
D = divNonPeriodic(k, m, dx);
2327
return;
2428
end

src/matlab/div2D.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
% dx : Step size
1010
% n : Number of cells along y-axis
1111
% dy : Step size along y-axis
12-
% dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
13-
% nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
12+
% (optional) dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
13+
% (optional) nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
1414
%
1515
% ----------------------------------------------------------------------------
1616
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -19,8 +19,12 @@
1919
% ----------------------------------------------------------------------------
2020
%
2121

22+
if nargin ~= 5 && nargin ~= 7
23+
error('div:InvalidNumArgs', 'div expects 5 or 7 arguments');
24+
end
25+
2226
% for legacy code
23-
if nargin <= 5
27+
if nargin == 5
2428
D = divNonPeriodic2D(k, m, dx, n, dy);
2529
return;
2630
end

src/matlab/div3D.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
% dy : Step size along y-axis
1212
% o : Number of cells along z-axis
1313
% dz : Step size along z-axis
14-
% dc : a0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
15-
% nc : b0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
14+
% (optional) dc : a0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
15+
% (optional) nc : b0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
1616
%
1717
% ----------------------------------------------------------------------------
1818
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -21,8 +21,12 @@
2121
% ----------------------------------------------------------------------------
2222
%
2323

24+
if nargin ~= 7 && nargin ~= 9
25+
error('div:InvalidNumArgs', 'div expects 7 or 9 arguments');
26+
end
27+
2428
% for legacy code
25-
if nargin <= 7
29+
if nargin == 7
2630
D = divNonPeriodic3D(k, m, dx, n, dy, o, dz);
2731
return;
2832
end

src/matlab/grad.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
% k : Order of accuracy
88
% m : Number of cells
99
% dx : Step size
10-
% dc : a0 (2x1 vector for left and right vertices, resp.)
11-
% nc : b0 (2x1 vector for left and right vertices, resp.)
10+
% (optional) dc : a0 (2x1 vector for left and right vertices, resp.)
11+
% (optional) nc : b0 (2x1 vector for left and right vertices, resp.)
1212
%
1313
% ----------------------------------------------------------------------------
1414
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -17,8 +17,12 @@
1717
% ----------------------------------------------------------------------------
1818
%
1919

20+
if nargin ~= 3 && nargin ~= 5
21+
error('div:InvalidNumArgs', 'div expects 3 or 5 arguments');
22+
end
23+
2024
% for legacy code
21-
if nargin <= 3
25+
if nargin == 3
2226
G = gradNonPeriodic(k, m, dx);
2327
return;
2428
end

src/matlab/grad2D.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
% dx : Step size
1010
% n : Number of cells along y-axis
1111
% dy : Step size along y-axis
12-
% dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
13-
% nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
12+
% (optional) dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
13+
% (optional) nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
1414
%
1515
% ----------------------------------------------------------------------------
1616
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -19,8 +19,12 @@
1919
% ----------------------------------------------------------------------------
2020
%
2121

22+
if nargin ~= 5 && nargin ~= 7
23+
error('div:InvalidNumArgs', 'div expects 5 or 7 arguments');
24+
end
25+
2226
% for legacy code
23-
if nargin <= 5
27+
if nargin == 5
2428
G = gradNonPeriodic2D(k, m, dx, n, dy);
2529
return;
2630
end

src/matlab/grad3D.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
% dy : Step size along y-axis
1212
% o : Number of cells along z-axis
1313
% dz : Step size along z-axis
14-
% dc : a0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
15-
% nc : b0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
14+
% (optional) dc : a0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
15+
% (optional) nc : b0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
1616
%
1717
% ----------------------------------------------------------------------------
1818
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -21,8 +21,12 @@
2121
% ----------------------------------------------------------------------------
2222
%
2323

24+
if nargin ~= 7 && nargin ~= 9
25+
error('div:InvalidNumArgs', 'div expects 7 or 9 arguments');
26+
end
27+
2428
% for legacy code
25-
if nargin <= 7
29+
if nargin == 7
2630
G = gradNonPeriodic3D(k, m, dx, n, dy, o, dz);
2731
return;
2832
end

src/matlab/lap.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
% k : Order of accuracy
88
% m : Number of cells
99
% dx : Step size
10-
% dc : a0 (2x1 vector for left and right vertices, resp.)
11-
% nc : b0 (2x1 vector for left and right vertices, resp.)
10+
% (optional) dc : a0 (2x1 vector for left and right vertices, resp.)
11+
% (optional) nc : b0 (2x1 vector for left and right vertices, resp.)
1212
%
1313
% ----------------------------------------------------------------------------
1414
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -17,8 +17,12 @@
1717
% ----------------------------------------------------------------------------
1818
%
1919

20+
if nargin ~= 3 && nargin ~= 5
21+
error('div:InvalidNumArgs', 'div expects 3 or 5 arguments');
22+
end
23+
2024
% for legacy code
21-
if nargin <= 3
25+
if nargin == 3
2226
L = lapNonPeriodic(k, m, dx);
2327
return;
2428
end

src/matlab/lap2D.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
% dx : Step size along x-axis
1010
% n : Number of cells along y-axis
1111
% dy : Step size along y-axis
12-
% dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
13-
% nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
12+
% (optional) dc : a0 (4x1 vector for left, right, bottom, top boundaries, resp.)
13+
% (optional) nc : b0 (4x1 vector for left, right, bottom, top boundaries, resp.)
1414
%
1515
% ----------------------------------------------------------------------------
1616
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -19,8 +19,12 @@
1919
% ----------------------------------------------------------------------------
2020
%
2121

22+
if nargin ~= 5 && nargin ~= 7
23+
error('div:InvalidNumArgs', 'div expects 5 or 7 arguments');
24+
end
25+
2226
% for legacy code
23-
if nargin <= 5
27+
if nargin == 5
2428
L = lapNonPeriodic2D(k, m, dx, n, dy);
2529
return;
2630
end

src/matlab/lap3D.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
% dy : Step size along y-axis
1212
% o : Number of cells along z-axis
1313
% dz : Step size along z-axis
14-
% dc : a0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
15-
% nc : b0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
14+
% (optional) dc : a0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
15+
% (optional) nc : b0 (6x1 vector for left, right, bottom, top, front, back boundary types, resp.)
1616
%
1717
% ----------------------------------------------------------------------------
1818
% SPDX-License-Identifier: GPL-3.0-or-later
@@ -21,8 +21,12 @@
2121
% ----------------------------------------------------------------------------
2222
%
2323

24+
if nargin ~= 7 && nargin ~= 9
25+
error('div:InvalidNumArgs', 'div expects 7 or 9 arguments');
26+
end
27+
2428
% for legacy code
25-
if nargin <= 7
29+
if nargin == 7
2630
L = lapNonPeriodic3D(k, m, dx, n, dy, o, dz);
2731
return;
2832
end

0 commit comments

Comments
 (0)