function oo_=save_display_classical_smoother_results(xparam1,M_,oo_,options_,dataset_,dataset_info,estim_params_,smoother_info,measurement_info)
% oo_=save_display_classical_smoother_results(xparam1,M_,oo_,options_,dataset_,dataset_info,estim_params_,smoother_info)
% Inputs:
%   xparam1         [double]        current values for the estimated parameters.
%   M_              [structure]     storing the model information
%   oo_             [structure]     storing the results
%   options_        [structure]     storing the options
%   dataset_        [structure]     storing the dataset
%   dataset_info    [structure]     information about the dataset (descriptive statistics and missing observations)
%   estim_params_   [structure]     storing information about estimated parameters
%
% Outputs:
%   oo_             [structure]     storing the results

% Copyright © 2023-2025 Dynare Team
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare.  If not, see <https://www.gnu.org/licenses/>.

smoother_error=false;
if options_.occbin.smoother.status && options_.occbin.smoother.inversion_filter
    Prior = dprior(estim_params_, M_, options_.prior_trunc);
    [~, info, ~, ~, ~, model_solution, smoother_results, oo_.occbin.smoother.regime_history] = occbin.IVF_posterior(xparam1,dataset_,dataset_info,options_,M_,estim_params_,Prior,prior_bounds(Prior,options_.prior_trunc),oo_.dr, oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state);
    if ismember(info(1),[303,304,306])
        fprintf('\nIVF: smoother did not succeed. No results will be written to oo_.\n')
        smoother_error=true;
    else
        smoother_results.model.mf = smoother_info.var_list(smoother_info.mf);
        options_nk=options_.nk;
        options_.nk=[]; %unset options_.nk and reset it later
        [oo_, yf]=store_smoother_results(M_,oo_,options_,smoother_info,dataset_,dataset_info,smoother_results);
        options_.nk=options_nk;
        oo_.dr=model_solution.dr; %required for subsequent call of forecasts.run
    end
else
    if options_.occbin.smoother.status
        [smoother_results, occbin_info] = ...
            occbin.DSGE_smoother(xparam1,M_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,options_,estim_params_,dataset_,dataset_info,smoother_info);
        if occbin_info.error_flag(1)==0
            [oo_, yf] = store_smoother_results(M_,oo_,options_,smoother_info,dataset_,dataset_info,smoother_results,occbin_info);
        else
            oo_.occbin.smoother.error_flag = occbin_info.error_flag;
            oo_.occbin.smoother.regime_history = occbin_info.regime_history;
            smoother_error=true;
            fprintf('\nOccBin: smoother did not succeed. No results will be written to oo_.\n')
        end
    else
        smoother_results = DsgeSmoother(xparam1,dataset_,dataset_info,M_,oo_.dr,oo_.steady_state,oo_.exo_steady_state,oo_.exo_det_steady_state,options_,estim_params_,smoother_info);
        [oo_,yf]=store_smoother_results(M_,oo_,options_,smoother_info,dataset_,dataset_info,smoother_results);
    end
    oo_.dr=smoother_results.model.dr; %required for subsequent call of forecasts.run
end
if ~smoother_error
    plot_classical_smoother_results(M_,oo_,options_,dataset_info,dataset_,estim_params_,yf);
end
