function [] = initializeArtoa4()
%INITIALIZEARTOA4 Initializes variables required for artoa4 and creates the main window if required.
%   

global artoaDataInput artoaDataOutput artoaWorkspace artoaGui;

%% When the gui exists, focus it
if isfield(artoaGui, 'figures') && isfield(artoaGui.figures, 'main')
    figure(artoaGui.figures.main.Number);
    return
end

%% Initalize required variables
artoaDataInput = struct();
artoaDataOutput = struct();
artoaWorkspace = struct();
artoaWorkspace.hideDeletedDataPoints = false;
artoaWorkspace.defaults = struct();
artoaWorkspace.defaults.trackingMethods = { ...
    'Least Square', ...
    'Exclusive Least Square', ...
    'Circular', ...
    'Hyperbolic' ...
};
artoaWorkspace.defaults.interpolationMethods = { ...
    'None', ...
    'Linear', ...
    'Spline', ...
    'Cubic' ...
};
artoaWorkspace.defaults.soundspeedMethods = { ...
    'Del Grosso', ...
    'Linear', ...
    'Soundsource file', ...
    'Levitus', ...
    'Manual' ...
};
artoaWorkspace.defaults.pickPointMarkerSize = 80;
artoaGui = struct();
artoaGui.figures = struct();
artoaGui.main = struct();

%% Read ini file if existent

try
    artoaDataInput.ini = artoa.load.tomlini('artoa.ini');
catch ex
    error([mfilename ': Reading artoa.ini failed with the following message: ' ex.message]);
end

if isempty(artoaDataInput.ini)
    error([mfilename ': artoa.ini has been found but is empty. Please use a valid artoa.ini!']);
end

%% Read soundsource file if existent
try
    soundsourceFilepath = artoaDataInput.ini.files.soundsourcefile;
    if ~isfile(soundsourceFilepath)
        error([mfilename ': ' soundsourceFilepath ' is not a file. Please check your artoa.ini!']);
    end
    artoaDataInput.soundsources = artoa.load.soundsources(soundsourceFilepath);
    artoa.soundsources.generateSoundSourceColors();
catch ex
    error([mfilename ': Reading soundsource file failed with the following message: ' ex.message]);
end

%% Start artoa4

artoa.gui.main();

%% Update the settings defined by ini
if artoa.data.getMember(artoaDataInput.ini, {'view', 'hidedeleteddatapoints'}, false)
    artoa.controller.switchHideDeletedPoints();
end

end

