function buttonpreferences(hObject, eventdata, Empty_Button, Buttons, AxesD, AxesSOL, AxesAOM, RegSlider, RegText, lcs, LCS, usmn, usmf)

kind = 100;

% function regconPGA(hObject, eventdata, Empty_Button, Buttons, RegText, RegSlider, Recondition, kind)
data = get(Empty_Button,'UserData');

for i=1:6
    av(i) = get(RegSlider(i+3), 'Value');
end

fig = figure;
pause(.1);

if ispc
    basicfsz = 5;
else
    basicfsz = 6.5;
end
sty = 'Helvetica';
bgw = [1, 1, 1];
scrsz = get(0,'ScreenSize');

set(fig,'Position',[scrsz(3)/2 scrsz(4)/2 300 300]);
pause(.1);

set(fig,'Name','Set preferences','NumberTitle','off','MenuBar','none','Toolbar','none','color','white');

Textfield(1) = uicontrol('Style','text','String','step:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','TooltipString','','FontName',sty,'Position',[0.01, 0.85, 0.65, 0.115]);
Textfield(2) = uicontrol('Style','text','String','thinning threshold:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.725, 0.65, 0.115]);
Textfield(3) = uicontrol('Style','text','String','max thinning gap:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.6, 0.65, 0.115]);
Textfield(4) = uicontrol('Style','text','String','(coming soon):','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.475, 0.65, 0.115]);
Textfield(5) = uicontrol('Style','text','String','(later):','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.35, 0.65, 0.115]);
Textfield(6) = uicontrol('Style','text','String','(even later):','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.225, 0.65, 0.115]);

fname = mfilename;
calcf = mfilename('fullpath');
calcf = calcf(1:end-length(fname));
filename =calcf + "prefs/prefs.mat";
if exist(filename,'file') == 2
    load(filename,'prefs');
else
    prefs = [1 0.0025 30 0 0 0];
end

for i=1:6
    Regfield(i) = uicontrol('Style','edit','String',num2str(prefs(i)),'HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
        'Units','normalized','FontName',sty,'Position',get(Textfield(i),'Position')+[0.7 0 -0.4 0]);
end

Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Change','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.51, 0.04, 0.48, 0.1],...
    'Callback',{@innerbuttonsave, Empty_Button, Regfield, fig, Buttons, AxesD, AxesSOL, lcs, LCS, RegSlider, RegText, usmn, usmf});
%     'Callback',{@innerbuttonaccept, Empty_Button, Regfield, fig});

Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Cancel','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.04, 0.48, 0.1],...
    'Callback',{@innerbuttoncancel, fig});

waitfor(fig);
pause(.1);

data = get(Empty_Button,'UserData');

function innerbuttonsave(hobject, eventdata, Empty_Button, Regfield, parentfig, Buttons, AxesD, AxesSOL, lcs, LCS, RegSlider, RegText, usmn, usmf)
data = get(Empty_Button,'UserData');
for i =1:6
   prefs(i) = str2num(get(Regfield(i),'String'));
end

fname = mfilename;
calcf = mfilename('fullpath');
calcf = calcf(1:end-length(fname));
filename =calcf + "prefs/prefs.mat";
save(filename,"prefs");

data.step = prefs(1);

if data.isdata
    data.id = preprocPGA(data.D,prefs(2),prefs(3),prefs(4));
end

set(Empty_Button,'UserData',data);

if data.noc > 0
    buttonshowallPGA(hobject,eventdata,Empty_Button, Buttons, AxesSOL, lcs, LCS, RegSlider, RegText, usmn, usmf);
end

if data.isdata
    redrawAxesD(hobject,eventdata,Empty_Button,AxesD,lcs,LCS);
end

close(parentfig)

function innerbuttoncancel(hobject, eventdata, parentfig)
close(parentfig);
