function bsspartitionsizeok(n)
% BSSPARTITIONSIZEOK - Check the nominal partition size for a B-spline
% series for validity
%
% INPUTS:
%
%    n:
%       The nominal partition size or the number of subintervals to
%       use for the partition in each dimension.
%
%       The partition size for each dimension does NOT include the extra
%       subintervals that are created based on the order of the B-splines
%       that are used.
%
%       This is a row or column vector with NDIM elements.
%
%       N must:
%
%         be nonempty
%         be numeric
%         be row or column vector
%         have n(i) >= 3, i = 1:NDIM
%         and have n(i) be whole numbers, i = 1:NDIM
%
% OUTPUTS:
%
%    None.
%

%
% Copyright 2014-2023 Biometrics Northwest LLC
%

%
% Modified: 2023-02-13
% Author : Kevin R. Gehringer
%
%    Fixed errors in the header and deleted the description and commented
%    out tests for requiring the dimension to be 1, 2, 3.
%
%    Added a test to check for negative numbers.
%
%    Fixed problems with non-scalar value arguments to error(). This used
%    to work, but appears to be broken now. One the first bad values is
%    reported now with an error, rather than all of them at once.
%
%    Rewrote most of the tests for greater clarity.
%
% Modified: 2022-12-18
% Author : Kevin R. Gehringer
%
%    Removed the output flag. It was not necessary since the function
%    signals errors. If it returns without an error all is OK.
%
%    Changed the rounding function from fix() to floor() since the 
%    partition sizes must be positive integers.
%
% Created: 2014-11-25
% Author : Kevin R. Gehringer
%

%
% Begin the testing with nonempty and numeric.
%
if ( isempty(n) )
   error('The B-spline series partition size was empty.');
end

if ( ~isnumeric(n) )
   error('The B-spline series partition size was not numeric.');
end

%
%  Check to see if N is a scalar value, implying equal sizes for all
%  dimensions, or a vector.
%
if ( ~(isscalar(n) || isvector(n)) )
   error('The B-spline series partition size was not a scalar or vector value.');
end

%
% Verify there are no negative values.
%
if (~all(n>0,'all') )
    error('The partition size for each dimension must be positive (n > 0).');
end

%
% Check to see that all values are whole numbers by rounding toward zero.
%
if ( any(n-floor(n) ~= 0, 'all') )
    error('The partition size for each dimension must be an integer.');
end

%
% Check for enough points to specify a partition: 3 are necessary: end
% points and at least one in the middle.
%
if ( any(n < 3,'all' ) )
    error('The partition size for each dimension must be at least 3 (n >=3).');
end

end