function output = isFiniteNum(input, valRange)
% isFiniteNum 
%   isFiniteNum checks if the input value is a scalar, finite, and between the given
%   value range.
%   valRange: [val_1, val_2;val_1_included, val_2_included];

%   Project: IMPACT
%   Title of Code: isFiniteNum
%   Relevant additional documentation:
%   Developer: Carlos Gonzalez
%   External Dependencies: NA
%
%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with authors.


output = true;

% [] is numeric, not scalar
% nan is scalar, numeric
if ~isscalar(input)
    output = false;
    return
end

% struct may be scalar, not numeric
if ~isnumeric(input)
    output = false;
    return;
end

% check if there is a value range requirement
if nargin < 2
    if ~isfinite(input)
        output = false;
        return
    end
    
else
    
    % lower limit
    if valRange(2,1)==1 % included
%         if ~(input >= valRange(1,1))
%NB: nan
        if ~(input >= valRange(1,1))
            output = false;
            return
        end
    else % not included
        if ~(input > valRange(1,1))
            output = false;
            return
        end
    end

    % upper limit
    if valRange(2,2)==1 % included
        if ~(input <= valRange(1,2))
            output = false;
            return
        end
    else % not included
        if ~(input < valRange(1,2))
            output = false;
            return
        end
    end 
end

