function eml_check_numeric_nonempty_finite(u, varargin)
%EML_CHECK_NUMERIC_NONEMPTY_FINITE Checks for numeric, non-empty, isfinite

% Copyright 2010-2014 The MathWorks, Inc.

%#codegen

coder.allowpcode('plain');
coder.internal.prefer_const(u);

if nargin > 1
    customErrorID = varargin{1};
else
    customErrorID = 'fixed:coder:fxpUArgValsMustBeNumericNonemptyFinite';
end

doUArgCheckEMLAssert(isnumeric(u), customErrorID);
    
if isfi(u)
    doUArgCheckEMLAssert(~isboolean(u), customErrorID);
end

if isscalar(u)
    doUArgCheckEMLAssert(~isempty(u), customErrorID);
    if isfloat(u)
        doUArgCheckEMLAssert(isfinite(u), customErrorID);
    end
else
    % NON-SCALAR U
    if isfi(u)
        uLength = numberofelements(u);
    else
        uLength = numel(u);
    end

    doUArgCheckEMLAssert(uLength >= 1, customErrorID);
    
    for idx = 1:uLength
        doUArgCheckEMLAssert(~isempty(u(idx)), customErrorID);
        if isfloat(u)
            doUArgCheckEMLAssert(isfinite(u(idx)), customErrorID);
        end
    end
end

end % function


function doUArgCheckEMLAssert(condition, customErrorID)
coder.internal.prefer_const(condition);
coder.internal.prefer_const(customErrorID);
eml_invariant(condition, ...
    customErrorID);
end % function


