# HG changeset patch
# User Nicholas R. Jankowski <jankowskin@asme.org>
# Date 1483673543 18000
#      Thu Jan 05 22:32:23 2017 -0500
# Node ID b96acd9f95d2279ce10fac25fe412f522bf2fd80
# Parent  ad7e5d12d69ad6bd4e72114a599a95f026584a93
Corrected output orientation and nargout = 0 & 1 behavior for signal package functions (bugs #49318, bug #49990)

* inst/cheby1.m, cheby2.m, ellip.m, butter.m: nargout fix, orientation fix, and tests

diff -r ad7e5d12d69a -r b96acd9f95d2 inst/butter.m
--- a/inst/butter.m	Sat Dec 03 02:21:37 2016 +0100
+++ b/inst/butter.m	Thu Jan 05 22:32:23 2017 -0500
@@ -56,7 +56,7 @@
 
 function [a, b, c, d] = butter (n, w, varargin)
 
-  if (nargin > 4 || nargin < 2 || nargout > 4 || nargout < 2)
+  if (nargin > 4 || nargin < 2 || nargout > 4)
     print_usage ();
   endif
 
@@ -118,13 +118,14 @@
     [zero, pole, gain] = bilinear (zero, pole, gain, T);
   endif
 
-  ## convert to the correct output form
-  if (nargout == 2)
+  ## convert to the correct output form 
+  ## note that poly always outputs a row vector
+  if (nargout <= 2)
     a = real (gain * poly (zero));
     b = real (poly (pole));
   elseif (nargout == 3)
-    a = zero;
-    b = pole;
+    a = zero(:);
+    b = pole(:);
     c = gain;
   else
     ## output ss results
@@ -178,6 +179,29 @@
 %!error [a, b] = butter (.5, .2)
 %!error [a, b] = butter (3, .2, "invalid")
 
+%% Test output orientation for matlab compatibility
+%!test
+%! butter (9, .6);
+%! assert (isrow (ans), true);
+%!test
+%! A = butter (9, .6);
+%! assert (isrow (A), true);
+%!test
+%! [A, B] = butter (9, .6);
+%! assert (isrow (A), true);
+%! assert (isrow (B), true);
+%!test
+%! [z, p, g] = butter (9, .6);
+%! assert (iscolumn (z), true);
+%! assert (iscolumn (p), true);
+%! assert (isscalar (g), true);
+%!test
+%! [a, b, c, d] = butter (9, .6);
+%! assert (ismatrix (a), true);
+%! assert (iscolumn (b), true);
+%! assert (isrow (c), true);
+%! assert (isscalar (d), true);
+
 %!demo
 %! sf = 800; sf2 = sf/2;
 %! data=[[1;zeros(sf-1,1)],sinetone(25,sf,1,1),sinetone(50,sf,1,1),sinetone(100,sf,1,1)];
diff -r ad7e5d12d69a -r b96acd9f95d2 inst/cheby1.m
--- a/inst/cheby1.m	Sat Dec 03 02:21:37 2016 +0100
+++ b/inst/cheby1.m	Thu Jan 05 22:32:23 2017 -0500
@@ -54,7 +54,7 @@
 
 function [a, b, c, d] = cheby1 (n, rp, w, varargin)
 
-  if (nargin > 5 || nargin < 3 || nargout > 4 || nargout < 2)
+  if (nargin > 5 || nargin < 3 || nargout > 4)
     print_usage ();
   endif
 
@@ -127,12 +127,13 @@
   endif
 
   ## convert to the correct output form
-  if (nargout == 2)
+  ## note that poly always outputs a row vector
+  if (nargout <= 2)
     a = real (gain * poly (zero));
     b = real (poly (pole));
   elseif (nargout == 3)
-    a = zero;
-    b = pole;
+    a = zero(:);
+    b = pole(:);
     c = gain;
   else
     ## output ss results
@@ -149,3 +150,25 @@
 %!error [a, b] = cheby1 (.5, 2, .2)
 %!error [a, b] = cheby1 (3, 2, .2, "invalid")
 
+%% Test output orientation for matlab compatibility
+%!test
+%! cheby1 (3, 4, .5);
+%! assert (isrow (ans), true);
+%!test
+%! A = cheby1 (3, 4, .5);
+%! assert (isrow (A), true);
+%!test
+%! [A, B] = cheby1 (3, 4, .5);
+%! assert (isrow (A), true);
+%! assert (isrow (B), true);
+%!test
+%! [z, p, g] = cheby1 (3, 4, .5);
+%! assert (iscolumn (z), true);
+%! assert (iscolumn (p), true);
+%! assert (isscalar (g), true);
+%!test
+%! [a, b, c, d] = cheby1 (3, 4, .5);
+%! assert (ismatrix (a), true);
+%! assert (iscolumn (b), true);
+%! assert (isrow (c), true);
+%! assert (isscalar (d), true);
\ No newline at end of file
diff -r ad7e5d12d69a -r b96acd9f95d2 inst/cheby2.m
--- a/inst/cheby2.m	Sat Dec 03 02:21:37 2016 +0100
+++ b/inst/cheby2.m	Thu Jan 05 22:32:23 2017 -0500
@@ -54,7 +54,7 @@
 
 function [a, b, c, d] = cheby2 (n, rs, w, varargin)
 
-  if (nargin > 5 || nargin < 3 || nargout > 4 || nargout < 2)
+  if (nargin > 5 || nargin < 3 || nargout > 4)
     print_usage ();
   endif
 
@@ -134,13 +134,14 @@
     [zero, pole, gain] = bilinear (zero, pole, gain, T);
   endif
 
-  ## convert to the correct output form
-  if (nargout == 2)
+  ## convert to the correct output form 
+  ## note that poly always outputs a row vector
+  if (nargout <= 2)
     a = real (gain * poly (zero));
     b = real (poly (pole));
   elseif (nargout == 3)
-    a = zero;
-    b = pole;
+    a = zero(:);
+    b = pole(:);
     c = gain;
   else
     ## output ss results
@@ -156,4 +157,26 @@
 %!error [a, b] = cheby2 (1, 2, 3, 4, 5, 6)
 %!error [a, b] = cheby2 (.5, 40, .2)
 %!error [a, b] = cheby2 (3, 40, .2, "invalid")
-
+%
+%% Test output orientation for matlab compatibility
+%!test
+%! cheby2 (3, 4, .5);
+%! assert (isrow (ans), true);
+%!test
+%! A = cheby2 (3, 4, .5);
+%! assert (isrow (A), true);
+%!test
+%! [A, B] = cheby2 (3, 4, .5);
+%! assert (isrow (A), true);
+%! assert (isrow (B), true);
+%!test
+%! [z, p, g] = cheby2 (3, 4, .5);
+%! assert (iscolumn (z), true);
+%! assert (iscolumn (p), true);
+%! assert (isscalar (g), true);
+%!test
+%! [a, b, c, d] = cheby2 (3, 4, .5);
+%! assert (ismatrix (a), true);
+%! assert (iscolumn (b), true);
+%! assert (isrow (c), true);
+%! assert (isscalar (d), true);
diff -r ad7e5d12d69a -r b96acd9f95d2 inst/ellip.m
--- a/inst/ellip.m	Sat Dec 03 02:21:37 2016 +0100
+++ b/inst/ellip.m	Thu Jan 05 22:32:23 2017 -0500
@@ -58,7 +58,7 @@
 
 function [a, b, c, d] = ellip (n, rp, rs, w, varargin)
 
-  if (nargin > 6 || nargin < 4 || nargout > 4 || nargout < 2)
+  if (nargin > 6 || nargin < 4 || nargout > 4)
     print_usage ();
   endif
 
@@ -122,13 +122,14 @@
     [zero, pole, gain] = bilinear (zero, pole, gain, T);
   endif
 
-  ## convert to the correct output form
-  if (nargout == 2)
+  ## convert to the correct output form 
+  ## note that poly always outputs a row vector
+  if (nargout <= 2)
     a = real (gain * poly (zero));
     b = real (poly (pole));
   elseif (nargout == 3)
-    a = zero;
-    b = pole;
+    a = zero(:);
+    b = pole(:);
     c = gain;
   else
     ## output ss results
@@ -162,3 +163,25 @@
 %!error [a, b] = ellip (.5, 2, 40, .2)
 %!error [a, b] = ellip (3, 2, 40, .2, "invalid")
 
+%% Test output orientation for matlab compatibility\
+%!test
+%! ellip (6, 3, 50, .6);
+%! assert (isrow (ans), true);
+%!test
+%! A = ellip (6, 3, 50, .6);
+%! assert (isrow (A), true);
+%!test
+%! [A, B] = ellip (6, 3, 50, .6);
+%! assert (isrow (A), true);
+%! assert (isrow (B), true);
+%!test
+%! [z, p, g] = ellip (6, 3, 50, .6);
+%! assert (iscolumn (z), true);
+%! assert (iscolumn (p), true);
+%! assert (isscalar (g), true);
+%!test
+%! [a, b, c, d] = ellip (6, 3, 50, .6);
+%! assert (ismatrix (a), true);
+%! assert (iscolumn (b), true);
+%! assert (isrow (c), true);
+%! assert (isscalar (d), true);
