function [] = quit(~, ~)
%QUIT Closes all windows, cleans up workspace and quits ARTOA4.

global artoaGui;

if ~exist('artoaGui', 'var') || isempty(artoaGui)
    delete(gcf);
    clearvars -global artoaGui artoaDataInput artoaDataOutput artoaWorkspace;
    return;
end

openedFigures = fieldnames(artoaGui.figures);
for i = 1:length(openedFigures)
    current = openedFigures{i};
    if strcmp(current, 'main')
        continue;
    end
    delete(artoaGui.figures.(current).Number);
end

% Close main figure
try
    delete(artoaGui.figures.main.Number);
catch
end

clearvars -global artoaGui artoaDataInput artoaDataOutput artoaWorkspace;

end

