function bss = bssdeleteinterpolant(bss,evalfun)
%BSSDELETEINTERPOLANT Create an interpolant grid for a PDF or CDF
%
% INPUTS:
%
%    bss:
%       The B-Spline series data structure containing a gridded interpolant
%       to be deleted.
%
%    evalfun:
%       The gridded interpolant that is to be deleted. Allowed values are:
%
%          all      : Delete all of the gridded interpolants
%          pdf      : Delete the PDF gridded interpolant
%          cdf      : Delete the CDF gridded interpolant
%
% OUTPUTS:
%
%    bss:
%       A B-spline series data structure with the specified gridded
%       interpolant removed. If no gridded interpolant is present, or if
%       the specified gridded interpolant is not present, the input
%       B-spline series is simply returned.
%

%
% Copyright 2014-2023 Biometrics Northwest LLC
%

%
% Modified: 2023-03-07
% Author : Kevin R. Gehringer
%
%    Removed 'bss' as a valid function name.
%
%    The field for an interpolant is no longer removed, it is simply made
%    empty.
%
% Created: 2016-05-21
% Author : Kevin R. Gehringer
%

%
% We gotta have a B-spline series structure.
%
if ( ~exist('bss','var') )
   error('The B-spline series data structure was not provided.');
end

if ( isempty(bss) )
   error('The B-spline series data structure was empty.');
end

%
%   Check to see if an evaluation function was specified. If not,it's an
%   error.
%
if ( ~exist('evalfun','var') )
    error('To delete a gridded interpolant a name must be given. Valid names are ''all'', ''pdf'', and ''cdf''.');
end

%
% Validate the evaluation function. Valid values are: 'all', 'pdf', and
% 'cdf'.
%
okfuns = {'pdf';'cdf';'all'};
funok = strcmpi(evalfun,okfuns);
if ( ~any(funok,'all') )
    error('The evaluation function ''%s'' was not recognized.',evalfun);
end

if ( funok(3) )
    havegrid = [isfield(bss,okfuns(1:2))];
else
    havegrid = [isfield(bss,okfuns(1:2))];
    havegrid = havegrid & funok(1:2);
end

if ( any(havegrid,'all') )
    for i = 1:length(havegrid)
        if ( havegrid(i) && ~isempty(bss.(okfuns{i})))
            bss.(okfuns{i}) = [];
        end
    end
end
