changeset 13768:5f96b91b4e0c

interpft.m: Miscellaneous code cleanup. Add more input validation tests. * interpft.m: Miscellaneous code cleanup. Add more input validation tests.
author Rik <octave@nomad.inbox5.com>
date Thu, 27 Oct 2011 23:00:58 -0700
parents 2b98014771b4
children b0bb7bd9e0c8 e36817e2ee60
files scripts/general/interpft.m
diffstat 1 files changed, 17 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/general/interpft.m	Thu Oct 27 22:17:03 2011 -0700
+++ b/scripts/general/interpft.m	Thu Oct 27 23:00:58 2011 -0700
@@ -46,32 +46,29 @@
     print_usage ();
   endif
 
+  if (! (isscalar (n) && n == fix (n)))
+    error ("interpft: N must be a scalar integer");
+  endif
+
   if (nargin == 2)
-    if (isvector (x) && size (x, 1) == 1)
+    if (isrow (x))
       dim = 2;
     else
       dim = 1;
     endif
   endif
 
-  if (! isscalar (n))
-    error ("interpft: N must be an integer scalar");
-  endif
-
   nd = ndims (x);
 
   if (dim < 1 || dim > nd)
-    error ("interpft: integrating over invalid dimension");
+    error ("interpft: invalid dimension DIM");
   endif
 
   perm = [dim:nd, 1:(dim-1)];
   x = permute (x, perm);
-  m = size (x, 1);
+  m = rows (x);
 
-  inc = 1;
-  while (inc*n < m)
-    inc++;
-  endwhile
+  inc = max (1, fix (m/n));
   y = fft (x) / m;
   k = floor (m / 2);
   sz = size (x);
@@ -90,8 +87,10 @@
   endif
 
   z = ipermute (z, perm);
+
 endfunction
 
+
 %!demo
 %! t = 0 : 0.3 : pi; dt = t(2)-t(1);
 %! n = length (t); k = 100;
@@ -108,5 +107,10 @@
 %!assert (interpft(y', n), y', 20*eps);
 %!assert (interpft([y,y],n), [y,y], 20*eps);
 
-%!error (interpft(y,n,0))
-%!error (interpft(y,[n,n]))
+%% Test input validation
+%!error interpft ()
+%!error interpft (1)
+%!error interpft (1,2,3)
+%!error (interpft(1,[n,n]))
+%!error (interpft(1,2,0))
+%!error (interpft(1,2,3))