function [alpha_sid_pro, v_sid_rec, varargin_out] = load_parameters(filename)
% LOAD_PARAMETERS Loads the model parameters from a .mat file.
%
% This function loads the mandatory matrices alpha_sid_pro and v_sid_rec from the .mat file.
% For optional parameters ('e', 'u', 'migr', 'gamma', 'd', 'R_sup'), it checks if they exist in the file;
% if present, they are included in varargin_out as name-value pairs; if not, they are omitted (not read).
% This allows passing varargin_out directly to the ODE function, where missing parameters will use defaults.
%
% Inputs:
%   filename: String specifying the .mat file to load (e.g., 'params.mat').
%
% Outputs:
%   alpha_sid_pro: Loaded (N_spe x N_sid) matrix of allocation fractions alpha_ij.
%   v_sid_rec:     Loaded (N_spe x N_sid) matrix of receptor allocation fractions v_ij.
%   varargin_out:  Cell array of name-value pairs for optional parameters present in the file.
%
% Example:
%   [alpha, v, varargs] = load_parameters('params.mat');
%   f = ODE_siderophore_iron_partition(alpha, v, varargs{:});

% Load the entire .mat file into a struct.
loaded = load(filename);

% Extract mandatory parameters (assume they exist; error if not).
alpha_sid_pro = loaded.alpha_sid_pro;
v_sid_rec = loaded.v_sid_rec;

% Initialize empty cell for varargin_out.
optionals = {'e', 'u', 'migr', 'gamma', 'd', 'R_sup'};

% 初始化 varargin_out 为空结构体
varargin_out = struct();

% 检查每个可选参数，如果在 loaded 中存在，则添加到 varargin_out 结构体
for i = 1:length(optionals)
    field = optionals{i};
    if isfield(loaded, field)
        varargin_out.(field) = loaded.(field); % 直接赋值到结构体的字段
    end
end

end