function [] = reloadRfb(~, ~)
%LOADRFB Creates a file selection dialog and reads the file into memory.

global artoaDataInput artoaWorkspace;

%% Check if path is available
if ~isfield(artoaDataInput, 'path_rfb')
    waitfor( ...
        msgbox( ...
            [ ...
                'You cannot reload the rfb file, because the reference is missing. ' ...
                'Please specify the path to the file in the next dialog.' ...
            ] ...
            , 'RFB Path missing' ...
            , 'error' ...
            ) ...
        );
    [filename, pathname] = uigetfile('*.rfb', 'Specify rfb filename');
    if filename == 0
        return;
    end

    artoaDataInput.path_rfb = fullfile(pathname, filename);
end

%% Check if file exists
if ~isfile(artoaDataInput.path_rfb)
    waitfor(msgbox(['The file ' artoaDataInput.path_rfb ' does not exist!'], 'Error', 'error'));
    artoaDataInput = rmfield(artoaDataInput, 'path_rfb');
    return;
end

%% Ask for confirmation
answer = questdlg( ...
        [ ...
            'Reload RFB file "'...
            artoaDataInput.path_rfb ...
            '"?' ...
        ], ...
        'Reload rfb file?', ...
        'Yes', ...
        'No', ...
        struct('Default', 'Yes', 'Interpreter', 'none') ...
    );

if strcmp(answer, 'No')
    return;
end

%% Load rfb file
rfb = artoa.load.rfb(artoaDataInput.path_rfb);

%% Update artoaDataInput variable
artoaDataInput.rfb.FLOAT = rfb.FLOAT;
artoaDataInput.rfb.SAT_FORMAT = rfb.SAT_FORMAT;
artoaDataInput.rfb.SAT_DATA = rfb.SAT_DATA;
artoaDataInput.rfb.VARIABLE_LIST = rfb.VARIABLE_LIST;

%% Update workspace
artoa.controller.copyRfbToWorkspace(true);
%% Update offset table
artoaWorkspace.editOffsets.offsets = artoa.offsets.generateOffsetTable( ...
    artoaWorkspace.float, ...
    artoa.controller.getSoundsourcesWithAppliedToa() ...
    );

%% Update GUI
artoa.controller.track.parameter.updateGui();
artoa.controller.edit.offsets.updateGui();

%% Update plots
artoa.controller.edit.updateAvailablePlots();

%% Update status text in main window
artoa.controller.main.updateLoadedFloatInformation();

end