function [out_opt_struct, ok ] = output_options

ok = -1;

% Load saved output options if the temporary file exists:
if exist('tmp_output_options.mat','file'), load('tmp_output_options'); end
% If saved options are not found, set to default options:
field_names = {'ts_plot','obs_pks','est_pks','mult_pks','pk_loads'};
if ~exist('out_opt_struct','var') || ~isstruct(out_opt_struct) || ~isempty(setdiff(field_names,fieldnames(out_opt_struct)))
    out_opt_struct.ts_plot = 1;
    out_opt_struct.obs_pks = 1;
    out_opt_struct.est_pks = 1;
    out_opt_struct.mult_pks = 1;
    out_opt_struct.pk_loads = 1;
end
% Define variables from the fields of 'out_opt_struct', which will be changed through the GUI: 
ts_plot = out_opt_struct.ts_plot;
obs_pks = out_opt_struct.obs_pks;
est_pks = out_opt_struct.est_pks;
mult_pks = out_opt_struct.mult_pks;
pk_loads = out_opt_struct.pk_loads;

scrsz = get(0,'ScreenSize');
Xc = scrsz(3)*.4;
Yc = scrsz(4)*.4;
X0 = scrsz(3)*.25;
Y0 = scrsz(4)*.25;
clr = get(0,'DefaultUicontrolBackgroundColor');

h = dialog('Color',clr,'Position',[Xc Yc X0 Y0],'Name','Select results for output');%,'CloseRequestFcn',@CloseCallback);

set( h, 'Units', 'character');
Size = get( h, 'Position');
Xc = Size(1);
Yc = Size(2);
X0 = 80;
yA = 4;
yB = 6;
yC = 6;
yD = 4;
yE = 4;
Y0 = yA+yB+yC+yD+yE;
set(h,'Position',[Xc Yc X0 Y0]);

hA = uipanel('Parent',h,'BackgroundColor',clr,'Units','character','Position',[0 Y0-yA X0 yA],...
    'Title','Plotting (and storing) of time series:');
hB = uipanel('Parent',h,'BackgroundColor',clr,'Units','character','Position',[0 Y0-(yA+yB) X0 yB],...
    'Title','Method of computing peaks (select one or both):');
hC = uipanel('Parent',h,'BackgroundColor',clr,'Units','character','Position',[0 Y0-(yA+yB+yC) X0 yC],...
    'Title','Results obtained by symmetry (select one):');
hD = uipanel('Parent',h,'BackgroundColor',clr,'Units','character','Position',[0 Y0-(yA+yB+yC+yD) X0 yD],...
    'Title','"Worst-case" load distributions:');
hE = uipanel('Parent',h,'BackgroundColor',clr,'Units','character','Position',[0 0 X0 yE]);

TS_chkbox = uicontrol(hA, 'Style','checkbox','String','Display time series during analysis (enables storing of time series)',...
    'Units','characters','Value',ts_plot,'Position',[2 yA-3 X0-4 1.5],'Callback',@TSdispCallback);
% TS_txt = uicontrol(hA,'BackgroundColor',clr, 'Style', 'text', 'String','(enables optional storing of time series)',...
%     'HorizontalAlignment','left','Units','character','Position',[7 yA-4.5 X0-8 1.5]);

ObsPks_radio = uicontrol(hB, 'Style','radiobutton','String','Observed peaks (maximum and minimum of time series)',...
    'Value',obs_pks,'Units','character','Position',[2 yB-3 X0-4 1.5],'Callback',@ObsPksCallback);
EstPks_radio = uicontrol(hB, 'Style','radiobutton','String','Estimated peaks (expected value of peak from probability distribution)',...
    'Value',est_pks,'Units','character','Position',[2 yB-5 X0-4 1.5],'Callback',@EstPksCallback);
% If only one type of peak is selected, disable the corresponding radio button so that it can't be deselected:
if obs_pks & ~est_pks
    set(ObsPks_radio,'Enable','inactive');
elseif est_pks & ~obs_pks
    set(EstPks_radio,'Enable','inactive');
end

MultPks_radio =  uicontrol(hC, 'Style','radiobutton','String','Store multiple peaks for each wind direction as well as averaged peaks',...
    'Value',mult_pks,'Units','character','Position',[2 yB-3 X0-4 1.5],'Callback',@MultPksCallback);
AvgPks_radio =  uicontrol(hC, 'Style','radiobutton','String','Store averaged peaks only',...
    'Value',~mult_pks,'Units','character','Position',[2 yB-5 X0-4 1.5],'Callback',@AvgPksCallback);
% Disable the selected radio button, so that changes can only be made by pressing the other button:
if mult_pks
    set(MultPks_radio,'Enable','inactive');
else
    set(AvgPks_radio,'Enable','inactive');
end

PkLoads_chkbox = uicontrol(hD, 'Style','checkbox','String','Store load distributions producing peak responses',...
    'Value',pk_loads,'Units','character','Position',[2 yD-3 X0-4 1.5],'Callback',@PkLoadsCallback);

save_button = uicontrol(hE, 'Style','pushbutton','String','Save selections','Units','character','Position',[X0*.5-30-4 yE-3 30 2],...
    'Callback',@SaveCallback);
cancel_button = uicontrol(hE, 'Style','pushbutton','String','Cancel','Units','character','Position',[X0*.5+4 yE-3 30 2],...
    'Callback',@CancelCallback);

uiwait(h);
    
% function CloseCallback(src, evendata)
%     % reset output options to default settings if user presses cancel or closes dialog box
%     if ok==-1
%         out_opt_struct = DefaultSettings;
%     end
% end 

function TSdispCallback(src, eventdata)
    ts_plot = get(TS_chkbox,'Value');
end
function ObsPksCallback(src, eventdata)
    obs_pks = get(ObsPks_radio,'Value');
    if obs_pks
        set( EstPks_radio, 'Enable', 'on');
    else
        set( EstPks_radio, 'Enable', 'inactive');
    end
end
function EstPksCallback(src, eventdata)
    est_pks = get(EstPks_radio,'Value');
    if est_pks
        set( ObsPks_radio, 'Enable', 'on');
    else
        set( ObsPks_radio, 'Enable', 'inactive');
    end
end

function AvgPksCallback(src, eventdata)
    mult_pks = 0;
    set(MultPks_radio, 'Value', 0,'Enable','on');
    set(AvgPks_radio, 'Enable', 'inactive');
end
function MultPksCallback(src, eventdata)
    mult_pks = 1;
    set(AvgPks_radio, 'Value', 0,'Enable','on');
    set(MultPks_radio,'Enable', 'inactive');
end

function PkLoadsCallback(src, eventdata)
    pk_loads = get(PkLoads_chkbox,'Value');
    % 1 -> save, 0 -> don't save
end

function SaveCallback(src, eventdata)
    out_opt_struct.ts_plot = ts_plot;
    out_opt_struct.obs_pks = obs_pks;
    out_opt_struct.est_pks = est_pks;
    out_opt_struct.mult_pks = mult_pks;
    out_opt_struct.pk_loads = pk_loads;
    save('tmp_output_options','out_opt_struct');
    ok = 1;
    close(h);
end
function CancelCallback(src, eventdata)
    close(h);
end

end