function subGUI4PGA(version,nr,basicfsz)
% The toolbox FACPACK, which includes the function subGUI4PGA, provides software 
% for a Peak group analysis and for the computation of multi-component factorizations.
% Copyright (c) 2015 Mathias Sawall, University of Rostock, Department of Mathematics.
% Copyright (c) 2023 Lukas Prestin, University of Rostock, Department of Mathematics.
% 
% The software can be used for academic, research and other similar noncommercial uses. The user
% acknowledges that this software is still in the development stage and that it is provided by the
% copyright holders and contributors "as is" and any express or implied warranties, fitness for a
% particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable
% for any direct, indirect, incidental, special, exemplary, or consequential damages.
% 
% The copyright holders provide no reassurances that the source code provided does not infringe any
% patent, copyright, or any other intellectual property rights of third parties. The copyright
% holders disclaim any liability to any recipient for claims brought against recipient by any third
% party for infringement of that parties intellectual property rights.
% 
% The user has to respect the lapack license, see http://www.netlib.org/lapack/LICENSE.txt, and
% the license for the ACM routine nl2sol, see http://www.acm.org/publications/policies/softwarecrnotice,
% which are used in the associated C-code.

fname = mfilename;
calcp = mfilename('fullpath');
calcp = calcp(1:end-length(fname));
calcs = [calcp, 'subfcnsPGA'];
calclib = [calcp, 'subfcnsLIB'];
path(path, calcp);
path(path, calcs);
path(path, calclib);

filename =calcs + "preferences/preferences.mat";
%         isfile(filename)
if exist(filename,'file') == 2
    load(filename,'preferences');
else
    preferences = [1 3 0 0 0 0];
end
data.step = preferences(1);

levpeakmark = 1;

scrsz = get(0,'ScreenSize');
fig = figure(nr);
pause(.1);
set(fig,'Position',[1/20*scrsz(3:4) 9/10*scrsz(3:4)]);
set(fig,'Name',['FACPACK (Peak group analysis, version ',num2str(version,'%2.2f'), '-alpha)'],'NumberTitle','off',...
    'MenuBar','none','Toolbar','figure','color','white','Visible','off');

if ispc
%     basicfsz = 4.5;
%     basicfsz = 4.5 * scrsz(4)/1080;
    basichi = 0.025;
else
%     basicfsz = 5.5;
%     basicfsz = 5 * scrsz(4)/1080;
    basichi = 0.025;
end
basicfsz = basicfsz*scrsz(4)/1080;

Styles = {'bitstream charter';'clean';'Courier';'courier 10 pitch';'frank ruehl';'Helvetica';'Helvetica-Narrow';'itc bookman';'urw bookman l'};
sty = Styles{6};
bgc = 0.95*ones(3,1);
bgw = [1, 1, 1];
% lcs = [0 0 1;0 0.5 0;1 0 0;0 .8 .8;.8 0 .8;.8 .8 0;0 0 0];
lcs = [0 0.4470 0.7410; 0.8500 0.3250 0.0980; 0.9290 0.6940 0.1250; 0.4940 0.1840 0.5560; 0.4660 0.6740 0.1880; 0.3010 0.7450 0.9330];
LCS = [0.85 0.9 1; 0.995 0.8250 0.75; 1 0.9 0.75; 0.9 0.6 1; 0.7 1 0.5; 0.7 0.9 1];


% The title names
titles(1) = uicontrol('Style','text','String','Data and peak detection','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'FontWeight','bold','Position',[0.01, 0.955, 0.498, 0.7*basichi]);

titles(2) = uicontrol('Style','text','String','Singular values and singular vectors','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'FontWeight','bold','Position',[0.51, 0.955, 0.498, 0.7*basichi]);

titles(3) = uicontrol('Style','text','String','Optimization control','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'FontWeight','bold','Position',[0.01, 0.5-0.3*basichi, 0.498, basichi]);

titles(4) = uicontrol('Style','text','String',' Solutions and evaluation ','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'FontWeight','bold','Position',[0.51, 0.5, 0.498, 0.7*basichi]);

titles(5) = uicontrol('Style','text','String','Presets for weighting factors','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'FontWeight','bold','Position',[0.02, 0.16, 0.1825, 1.5*basichi]);

titles(6) = uicontrol('Style','text','String','filename','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.975, 0.98, .9*basichi]);


% The separating lines
SeparaterText(1) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0, 0.523, 1, 0.002]);

SeparaterText(2) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0.515, 0, 0.0015, 0.96]);

SeparaterText(3) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0, 0.2, 0.21, 0.0015]);

SeparaterText(4) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0.21, 0, 0.0011, 0.2015]);

SeparaterText(5) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0, 0.6, 0.135, 0.0015]);

SeparaterText(6) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0, 0.84, 0.135, 0.0015]);

SeparaterText(7) = uicontrol('Style','text','String','','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor',.7*[1 1 1],...
    'Units','normalized','FontName',sty,'Position',[0.135, 0.523, 0.0011, 0.3185]);

% The default weight factors
WeightButton(1) = uicontrol('Style','pushbutton','String','default 1','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.02, 0.14, 0.09, basichi + 0.01],...
    'TooltipString', sprintf('Change the weighting factors to preselected values.'));

WeightButton(2) = uicontrol('Style','pushbutton','String','default 2','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.1125, 0.14, 0.09, basichi + 0.01],...
    'TooltipString', sprintf('Change the weighting factors to preselected values.'));

WeightButton(3) = uicontrol('Style','pushbutton','String','default 3','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.02, 0.10, 0.09, basichi + 0.01],...
    'TooltipString', sprintf('Change the weighting factors to preselected values.'));

WeightButton(4) = uicontrol('Style','pushbutton','String','default 4','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.1125, 0.10, 0.09, basichi + 0.01],...
    'TooltipString', sprintf('Change the weighting factors to preselected values.'),'Enable','on');

WeightButton(5) = uicontrol('Style','pushbutton','String','default 5','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.02, 0.06, 0.09, basichi + 0.01],...
    'TooltipString', sprintf('Change the weighting factors to preselected values.'),'Enable','on');

WeightButton(6) = uicontrol('Style','pushbutton','String','default 6','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.1125, 0.06, 0.09, basichi + 0.01],...
    'TooltipString', sprintf('Change the weighting factors to preselected values.'),'Enable','on');

WeightsaveButton(1) = uicontrol('Style','pushbutton','String','save current weighting factors','Units','normalized','FontName',sty,'Fontsize',1.75*basicfsz,'Position',[0.02, 0.02, 0.1825, basichi + 0.01],...
    'TooltipString', sprintf('Save the current weighting factors as default 4,5 or 6.'),'Enable','on');


pos = [0.01, 0.9, 0.12, basichi];
DataText(1) = uicontrol('Style','text','String','','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',pos+[0, 0.04, 0, 0.03]);

DataText(2) = uicontrol('Style','text','String',' spectra: ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[0, 0.02, 0.06, 0]);

DataText(3) = uicontrol('Style','text','String',' channels: ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[0, 0.05, 0.06, 0]);

DataText(4) = uicontrol('Style','text','String','','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[-.065, 0.02, 0.065, 0]);

%
DataText(5) = uicontrol('Style','text','String','peak (left end):','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[0, 0.1, 0.0475, 0],'Visible','off');

DataText(6) = uicontrol('Style','text','String','','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[-.065, 0.05, 0.065, 0]);

DataText(7) = uicontrol('Style','text','String','peak (right end):','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[0, 0.13, 0.0475, 0],'Visible','off');

DataText(8) = uicontrol('Style','text','String','','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...%%
    'Units','normalized','FontName',sty,'Position',pos-[-.0775, 0.13, 0.0775, 0],'Visible','off');

DataText(9) = uicontrol('Style','text','String','','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos-[-.0775, 0.1, 0.0775, 0],'Visible','off');
%

pos = [0.53, 0.84, 0.095, basichi];
SVDText(1) = uicontrol('Style','listbox','String',{},'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.61, 0.095, 0.17-basichi],...
    'Value',[],'min',0,'max',5);

SVDText(2) = uicontrol('Style','text','String','Singular values: ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','bold','FontName',sty,'Position',[0.53, 0.78-basichi, 0.095, basichi]);

SVDText(3) = uicontrol('Style','text','String','Used singular            vectors: ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','bold','FontName',sty,'Position',[0.53, 0.61-2*basichi, 0.095, 1.5*basichi]);


pos = [0.01, 0.66, 0.12, basichi];
AutoPGAText(1) = uicontrol('Style','text','String','Automatic peak detection:','HorizontalAlignment','left','Fontsize',1.6*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',pos+[0, 0.06+0.04, 0, 0.05]);

AutoPGAText(2) = uicontrol('Style','text','String','Maximal detections:','HorizontalAlignment','left','Fontsize',1.6*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.675, .09, basichi]);

AutoPGAText(3) = uicontrol('Style','edit','String','10','HorizontalAlignment','center','Fontsize',1.6*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.1, 0.675, .03, basichi]);

AutoPGAText(4) = uicontrol('Style','text','String','Sensi.','HorizontalAlignment','left','Fontsize',1.6*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.715, .025, basichi]);

SensSlider(1) = uicontrol('Style','slider','String','','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',[0.04, 0.715, .09, basichi],'Min',0.1,'Max',1.9,'Value',1,...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the sensitivity of the automatic peak detetcion.'));

Radiogroup(4) = uibuttongroup('visible','on','Position',pos+[0, 0.09, 0, 0.04],'BackgroundColor',bgc);

rbgautopga(1) = uicontrol(Radiogroup(4),'Style','checkbox','String','2nd deriv. x','Units','normalized','Position',[0.01, 0.67, 0.98, 0.35],...
    'Fontsize',1.5*basicfsz,'FontWeight','normal','FontName',sty,'HandleVisibility','off','Value',1,...
    'BackgroundColor',bgc);

rbgautopga(2) = uicontrol(Radiogroup(4),'Style','checkbox','String','local var. x','Units','normalized','Position',[0.51, 0.67, 0.98, 0.35],...
    'Fontsize',1.5*basicfsz,'FontWeight','normal','FontName',sty,'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc);

rbgautopga(3) = uicontrol(Radiogroup(4),'Style','checkbox','String','sing. vectors','Units','normalized','Position',[0.01, 0.34, 0.98, 0.35],...
    'Fontsize',1.5*basicfsz,'FontWeight','normal','FontName',sty,'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc);

rbgautopga(4) = uicontrol(Radiogroup(4),'Style','checkbox','String','1st deriv. t','Units','normalized','Position',[0.51, 0.34, 0.98, 0.35],...
    'Fontsize',1.5*basicfsz,'FontWeight','normal','FontName',sty,'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc);

rbgautopga(5) = uicontrol(Radiogroup(4),'Style','checkbox','String','local var. t','Units','normalized','Position',[0.01, 0.01, 0.98, 0.35],...
    'Fontsize',1.5*basicfsz,'FontWeight','normal','FontName',sty,'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc);

rbgautopga(6) = uicontrol(Radiogroup(4),'Style','checkbox','String','KI','Units','normalized','Position',[0.51, 0.01, 0.98, 0.35],...
    'Fontsize',1.5*basicfsz,'FontWeight','normal','FontName',sty,'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc,'Visible','off');


pos = [0.01, 0.45, 0.11, basichi];
RegText(1) = uicontrol('Style','text','String','Objective functions','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','bold','FontName',sty,'Position',pos);

RegText(2) = uicontrol('Style','text','String','Weighting factors','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','bold','FontName',sty,'Position',pos+[0.12, 0, 0.06, 0]);

RegText(3) = uicontrol('Style','text','String','Contribution','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','bold','FontName',sty,'Position',pos+[0.4, 0, -0.05, 0]);

RegText(4) = uicontrol('Style','text','String','nonnegative C/S ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0, -0.04, 0, 0],...
    'TooltipString', sprintf('Penalizes negative entries in the wanted spectrum.\nFor noise control edit the noise-textfield.'));

RegText(5) = uicontrol('Style','text','String','local reconstruction ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0, -0.07, 0, 0],...
    'TooltipString', sprintf('Penalizes the reconstruction error in the magnifier.'));

RegText(6) = uicontrol('Style','text','String','norm S ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0, -0.1, 0, 0],...
    'TooltipString', sprintf('Regulates the norm of the wanted spectrum.'));

RegText(7) = uicontrol('Style','text','String','smooth S ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0, -0.13, 0, 0],...
    'TooltipString', sprintf('Regulates the smoothness of the wanted spectrum.'));

RegText(8) = uicontrol('Style','text','String','given spectrum ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0, -0.16, 0, 0],...
    'TooltipString', sprintf('Regulates variance to a given pattern-spectrum.\n Important: load the pattern-spectrum from workspace.'));

RegText(9) = uicontrol('Style','text','String','correlation ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0, -0.19, 0, 0],'Enable','off',...
    'TooltipString', sprintf('Regulates the correaltion with the already accepted spectra.'));

data.weights.dfault = [100 10 10 500 1 .5];
data.weights.start = [10 0.25 .1 0 0 0];
data.weights.max = data.weights.dfault;

RegText(24) = uicontrol('Style','edit','String',num2str(data.weights.start(1)),'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.24, -0.04, -0.06, 0],'TooltipString', sprintf('Weighting for the penalty function.'));

RegText(25) = uicontrol('Style','edit','String',num2str(data.weights.start(2)),'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.24, -0.07, -0.06, 0],'TooltipString', sprintf('Weighting for the penalty function.'));

RegText(26) = uicontrol('Style','edit','String',num2str(data.weights.start(3)),'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.24, -0.1, -0.06, 0],'TooltipString', sprintf('Weighting for the regularization.'));

RegText(27) = uicontrol('Style','edit','String',num2str(data.weights.start(4)),'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.24, -0.13, -0.06, 0],'TooltipString', sprintf('Weighting for the regularization.'));

RegText(28) = uicontrol('Style','edit','String',num2str(data.weights.start(5)),'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.24, -0.16, -0.06, 0],'TooltipString', sprintf('Weighting for the regularization.'));

RegText(29) = uicontrol('Style','edit','String',num2str(data.weights.start(6)),'HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.24, -0.19, -0.06, 0],'Enable','off','TooltipString', sprintf('Weighting for the regularization.'));

RegText(44) = uicontrol('Style','text','String','','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.4, -0.04, -0.05, 0],...
    'TooltipString', sprintf('Percentage affect of the penalty funtion in the optimization.'));

RegText(45) = uicontrol('Style','text','String','','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.4, -0.07, -0.05, 0],...
    'TooltipString', sprintf('Percentage affect of the penalty funtion in the optimization.'));

RegText(46) = uicontrol('Style','text','String','','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.4, -0.1, -0.05, 0],...
    'TooltipString', sprintf('Percentage affect of the regularization in the optimization.'));

RegText(47) = uicontrol('Style','text','String','','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.4, -0.13, -0.05, 0],...
    'TooltipString', sprintf('Percentage affect of the regularization in the optimization.'));

RegText(48) = uicontrol('Style','text','String','','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.4, -0.16, -0.05, 0],...
    'TooltipString', sprintf('Percentage affect of the regularization in the optimization.'));

RegText(49) = uicontrol('Style','text','String','','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.4, -0.19, -0.05, 0],...
    'TooltipString', sprintf('Percentage affect of the regularization in the optimization.'));

RegText(61) = uicontrol('Style','text','String','Further options','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','bold','FontName',sty,'Position',pos+[0.3, 0, -.02, 0]);

RegText(62) = uicontrol('Style','text','String',' noise:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.3, -0.04, -.07, 0]);

RegText(63) = uicontrol('Style','edit','String','0.0','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.345, -0.04, -.065, 0],...
    'TooltipString', sprintf('Noise-control: magnitude of tolerated negative entries.'));

RegText(67) = uicontrol('Style','text','String',' spctr:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos+[0.3, -0.16, -.07, 0]);

RegSlider(4) = uicontrol('Style','slider','String','Test','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.12, -0.04, 0, 0],'Min',1,'Max',data.weights.max(1),'Value',data.weights.start(1),...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the penalty function.'));

RegSlider(5) = uicontrol('Style','slider','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.12, -0.07, 0, 0],'Min',0,'Max',data.weights.max(2),'Value',data.weights.start(2),...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the penalty function.'));

RegSlider(6) = uicontrol('Style','slider','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.12, -0.1, 0, 0],'Min',0,'Max',data.weights.max(3),'Value',data.weights.start(3),...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the regularization.'));

RegSlider(7) = uicontrol('Style','slider','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.12, -0.13, 0, 0],'Min',0,'Max',data.weights.max(4),'Value',data.weights.start(4),...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the regularization.'));

RegSlider(8) = uicontrol('Style','slider','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.12, -0.16, 0, 0],'Min',0,'Max',data.weights.max(5),'Value',data.weights.start(5),...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the regularization.'));

RegSlider(9) = uicontrol('Style','slider','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgw,...
    'Units','normalized','FontName',sty,'Position',pos+[0.12, -0.19, 0, 0],'Min',0,'Max',data.weights.max(6),'Value',data.weights.start(6),'Enable','off',...
    'SliderStep',[0.005 .1],'TooltipString', sprintf('Weighting for the regularization.'));


pos1 = [0.23, 0.14, 0.095, 1.25*basichi];
pos2 = [0.33, 0.14, 0.07, 1.25*basichi];
Recondition(1) = uicontrol('Style','text','String',' data:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos1);

Recondition(2) = uicontrol('Style','text','String','missing','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos2,'ForegroundColor','r',...
    'TooltipString', sprintf('State of data-loading (possible entries: missing/done).'));

Recondition(3) = uicontrol('Style','text','String',' peak selection:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos1-[0, 0.0375, 0 0]);

Recondition(4) = uicontrol('Style','text','String','missing','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontWeight','normal','FontName',sty,'Position',pos2-[0, 0.0375, 0 0],'ForegroundColor','r',...
    'TooltipString', sprintf('State of peak selection (possible entries: missing/too small/manual/automatic).'));

Recondition(7) = uicontrol('Style','text','String',' number of singular vectors:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos1-[0, 0.075, 0 0]);

Recondition(8) = uicontrol('Style','text','String','missing','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos2-[0, 1.25*0.06, 0 0],'ForegroundColor','r',...
    'TooltipString', sprintf('State of the definition of the number of right singular vectors to use\nfor the reconstruction (possible entries: missing/done).'));

Recondition(9) = uicontrol('Style','text','String',' spectrum loaded:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos1-[0, 0.1125, 0 0]);

Recondition(10) = uicontrol('Style','text','String','nonrelevant','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos2-[0, 0.1125, 0 0],...
    'TooltipString', sprintf('State of pattern-spectrum-loading (possible entries: nonrelevant/missing/done).'));

Recondition(11) = uicontrol('Style','text','String','reconstruction details','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',pos1+[0, 0.0375, 0.075 0]);


TextAOM(1) = uicontrol('Style','text','String','Current spectrum','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.48, 0.095, 0.6*basichi]);

TextAOM(2) = uicontrol('Style','text','String','All spectra','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.325, 0.095, 0.6*basichi]);

TextAOM(3) = uicontrol('Style','text','String','All concentrations','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'BackgroundColor','white',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.17, 0.095, 0.6*basichi]);


% The axes for the data, the SVD, and the solution(s)
AxesD = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.165, 0.575, 0.335, 0.355]);
plot(AxesD,1,0,'w');

AxesSVD = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.65, 0.575, 0.335, 0.355]);
plot(AxesSVD,1,0,'w');

pos = [0.53, 0.38, 0.095, 0.1];
AxesAOM(1) = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position', pos);
plot(AxesAOM(1),0,0,'w');
set(AxesAOM(1), 'XTick', [], 'YTick', []);

AxesAOM(2) = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position', pos-[0, 0.155, 0, 0]);
plot(AxesAOM(2),0,0,'w');
set(AxesAOM(2), 'XTick', [], 'YTick', []);

AxesAOM(3) = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position', pos-[0, 0.31, 0, 0]);
plot(AxesAOM(3),0,0,'w');
set(AxesAOM(3), 'XTick', [], 'YTick', []);

AxesSOL = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.65, 0.095, 0.335, 0.38]);
plot(AxesSOL,1,0,'w');


% The buttons with all UserData in emptybutton
emptybutton = uicontrol('Style','pushbutton','Position',[0.02, 0.9, 0.095, basichi],'Visible','off','Callback',{@emptybutton_CB});

data.isdata = 0;
data.isbd = 0;
data.isamp = 0;
data.issvd = 0;
data.isnovctrs = 0;
data.isautodetect = 0;
data.autodetect = [];
data.isreg = 0;
data.issol = 0;
data.isSOL = 0;
data.noc = 0;
data.SOL = [];
data.isautosol = 0;
data.iscon = 0;
data.isgivenspec = 0;
data.givenspec = [];
data.givenadaptedis = 0;
data.givenadaptedI = [];

data.isred = 0;
data.islive = 0;
data.livet = [];
data.peakhint = {'mark a frequency window by click-and-move','or','select Automatic detection','or','use channel scanning'};

data.timeSVD = 0;
data.timeFAC = 0;

set(emptybutton,'UserData',data);
Button = [];

% The Radio-buttons
Radiogroup(2) = uibuttongroup('visible','on','Position',[0.53, 0.7875, .095, .14],'BackgroundColor',bgc);

rbplotsvd(1) = uicontrol('Style','radiobutton','String',' plot left','Units','normalized','Position',[0.01, 5/6, 0.98, 1/6],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc);
rbplotsvd(2) = uicontrol('Style','radiobutton','String',' plot sing. ','Units','normalized','Position',[0.01, 1/2, 0.98, 1/6],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc);
rbplotsvd(3) = uicontrol('Style','radiobutton','String',' plot right','Units','normalized','Position',[0.01, 1/6, 0.98, 1/6],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',1,...
    'BackgroundColor',bgc);
rbplotsvd(4) = uicontrol('Style','text','String','    sing. vectors','Units','normalized','Position',[0.01, 2/3, 0.98, 1/6],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc,'HorizontalAlignment','left');
rbplotsvd(5) = uicontrol('Style','text','String','    values','Units','normalized','Position',[0.01, 1/3, 0.98, 1/6],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc,'HorizontalAlignment','left');
rbplotsvd(6) = uicontrol('Style','text','String','    sing. vectors','Units','normalized','Position',[0.01, 0, 0.98, 1/6],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'BackgroundColor',bgc,'HorizontalAlignment','left');

set(Radiogroup(2),'SelectionChangeFcn', {@plotSVDPGA, emptybutton, Button, AxesSVD, rbplotsvd, SVDText});

Radiogroup(3) = uibuttongroup('visible','on','Position',[0.41, 0.03, 0.08, 0.06],'BackgroundColor',bgc);
usmn = uicontrol('Style','radiobutton','String',' live view on','Units','normalized','Position',[0.01, 0.6, 0.98, 0.25],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate live view mode to represent the solution just in time.\nChange the values of the weights to compute a new solution.'));

usmf = uicontrol('Style','radiobutton','String',' live view off','Units','normalized','Position',[0.01, 0.15, 0.98, 0.25],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',1,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Deactivate live view mode.'));

% % % Button(19) = uicontrol('Style','pushbutton','UserData',0,'String','Save & switch to PCD','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
% % %     'Units','normalized','FontName',sty,'Position',[0.8825, 0.015, 0.115, basichi], 'Enable', 'off',...
% % %     'TooltipString', sprintf('Save all relevant variables in *.mat file and switch to Pure component decomposition.'),...
% % %     'Callback',{@buttonsavePGA, emptybutton, Button, 4, RegSlider, RegText, usmn, usmf, version});

Button(19) = uicontrol('Style','pushbutton','UserData',0,'String','Save options','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.8825, 0.015, 0.115, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Choose what variables to save'),...
    'Callback',{@buttonsaveoptions, emptybutton, Button, lcs, basichi, basicfsz, sty, calclib, version, RegSlider, RegText, usmn, usmf});

Button(18) = uicontrol('Style','pushbutton','UserData',0,'String','Automatic detection','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.615, .12, 2*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Automatic detection of peaks.'));

Button(17) = uicontrol('Style','pushbutton','UserData',0,'String','Auto PGA','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.41, 0.1075, 0.08, 0.048], 'Enable', 'off',...
    'TooltipString', sprintf('Computes the PGA for the automatically detected peaks.'));

Button(16) = uicontrol('Style','pushbutton','UserData',0,'String','change upper boundaries','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.13 0.23 0.17 basichi],'TooltipString', sprintf('Change the upper boundaries for all weighting factors.'));

Button(15) = uicontrol('Style','pushbutton','UserData',0,'String','EFA in selected window','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.72, .12, basichi], 'Enable', 'off','Visible','off',...
    'TooltipString', sprintf('Computes an evolving factor analysis for the selected channels window.'),...
    'Callback',{@buttonWFAPGA, emptybutton, Button, lcs, basichi, basicfsz, sty, RegSlider, RegText, usmn, usmf});

Button(14) = uicontrol('Style','pushbutton','UserData',0,'String','Save all results','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.765, 0.015, 0.1155, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Save all relevant variables in *.mat file.'),...
    'Callback',{@buttonsavePGA, emptybutton, Button, 3, RegSlider, RegText, usmn, usmf},'visible','off');

Button(13) = uicontrol('Style','pushbutton','UserData',0,'String','Export to library','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.6475, 0.015, 0.115, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Select and export one spectrum to the FAC-PACK library.'),...
    'Callback',{@buttonexport2libPGA, emptybutton, Button, lcs, basichi, basicfsz, sty, calclib, version, RegSlider, RegText, usmn, usmf},'visible','off');

Button(12) = uicontrol('Style','pushbutton','UserData',0,'String','Save current spectrum','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.015, 0.115, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Save current spectrum in *.mat file.'),...
    'Callback',{@buttonsavePGA, emptybutton, Button, 1, RegSlider, RegText, usmn, usmf},'visible','off');

% set(Button(19),'Position',[0.53+4*(0.0925), 0.015, 0.09, basichi])
% set(Button(14),'Position',[0.53+3*(0.0925), 0.015, 0.09, basichi])
% set(Button(13),'Position',[0.53+2*(0.0925), 0.015, 0.09, basichi])
% set(Button(12),'Position',[0.53+(0.0925), 0.015, 0.09, basichi])

Button(20) = uicontrol('Style','pushbutton','UserData',0,'String','PGA preferences','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.93+ basichi, 0.12, basichi], 'Enable', 'on',...
    'TooltipString', sprintf(''),...
    'Callback',{@buttonpreferences, emptybutton, Button, AxesD, AxesSOL, AxesAOM, RegSlider, RegText, lcs, LCS, usmn, usmf});

Button(21) = uicontrol('Style','pushbutton','UserData',0,'String','Channel scanning','HorizontalAlignment','center','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.6-2.5*basichi, .12, 2*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('A brute force approach to determine the frequency channels that lead to the lowest objective function values. Requires number of used singular vectors.'),'Visible','on',...
    'Callback',{@buttoncomputeAllAPGA, emptybutton, Button, RegSlider, RegText, AxesSOL, AxesAOM, calcs, usmn, usmf, AxesD, Recondition,lcs, AxesSVD, LCS, rbplotsvd});

Button(11) = uicontrol('Style','pushbutton','UserData',0,'String','load','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.355, 0.29, 0.045, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Load a pattern-spectrum from *.mat file or library.'));

Button(10) = uicontrol('Style','popupmenu','UserData',0,'String',{'local','global'},'HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.579, 0.042, 0.0465, 0.9*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Chose the type of concentration-fit.'),...
    'Callback',{@buttoncomputeCPGA, emptybutton, Button, [], AxesAOM, lcs, RegSlider, RegText});

Button(9) = uicontrol('Style','pushbutton','UserData',0,'String','show','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.0425, 0.0465, 0.9*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Show seleced concentration-fit.'),...
    'Callback',{@buttoncomputeCPGA, emptybutton, Button, AxesSOL, AxesAOM, lcs, RegSlider, RegText});

Button(8) = uicontrol('Style','pushbutton','UserData',0,'String','edit','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.579, 0.1975, 0.0465, 0.9*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Choose the locked spectra to keep.'));

Button(7) = uicontrol('Style','pushbutton','UserData',0,'String','show','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.1975, 0.0465, 0.9*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Show all locked spectra.'),...
    'Callback',{@buttonshowallPGA, emptybutton, Button, AxesSOL, lcs, LCS, RegSlider, RegText, usmn, usmf});

Button(6) = uicontrol('Style','pushbutton','UserData',0,'String','accept','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.579, 0.3525, 0.0465, 0.9*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Accept current spectrum and go over to the computation of the next spectrum.'));

Button(5) = uicontrol('Style','pushbutton','UserData',0,'String','show','HorizontalAlignment','left','Fontsize',1.75*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.3525, 0.0465, 0.9*basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Show current spectrum.'),...
    'Callback',{@buttonshowcurrentaPGA, emptybutton, Button, AxesSOL, RegSlider, RegText, usmn, usmf});

Button(4) = uicontrol('Style','pushbutton','UserData',0,'String','Manual PGA','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.41, 0.1575, 0.08, 0.048], 'Enable', 'off',...
    'TooltipString', sprintf('Compute local approximation of rank one.'));

Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','compute SVD','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.9, 0.095, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Compute and view the SVD.'),...
    'Callback',{@buttonsvdPGA, emptybutton, Button, AxesSVD, SVDText, rbplotsvd, RegSlider, RegText, usmn, usmf},'Visible','off');

Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Load data','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.92, 0.12, basichi],'BackgroundColor',lcs(2,:),...
    'TooltipString', sprintf('Load mat-file containing data matrix D (spectra  x channels)\nand channels-vector "x".'),...
    'Callback',{@buttonloadPGA, emptybutton, Button, AxesD, AxesSVD, AxesSOL, AxesAOM, DataText, Recondition, RegSlider, RegText, titles, usmn, usmf, SVDText, rbplotsvd});

set(Button(4), 'Callback',{@buttoncomputeAPGA, emptybutton, Button, RegSlider, RegText, AxesSOL, AxesAOM, calcs, usmn, usmf});
set(Button(6), 'Callback',{@buttonacceptcurrentaPGA, emptybutton, Button, AxesD, AxesSVD, AxesSOL, AxesAOM, lcs, LCS, rbplotsvd, Recondition, RegSlider, RegText, usmn, usmf});
set(Button(8), 'Callback',{@buttondeletespectrumPGA, emptybutton, Button, AxesSOL, AxesAOM, RegSlider, RegText, lcs, LCS});
set(Button(11),'Callback',{@buttonloadgivenspecPGA, emptybutton, Button, Recondition, basichi, basicfsz, sty, calclib, RegSlider, RegText, usmn, usmf});
set(Button(21),'Callback',{@buttoncomputeAllAPGA, emptybutton, Button, RegSlider, RegText, AxesSOL, AxesAOM, calcs, usmn, usmf, AxesD, Recondition,lcs, AxesSVD, LCS, rbplotsvd});

set(SVDText(1),'Callback',{@editusingvctrsPGA, emptybutton, Button, RegSlider, Recondition, SVDText,rbplotsvd,AxesSVD});

set(RegSlider(4),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 4, AxesSOL, AxesAOM, calcs});
set(RegSlider(5),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 5, AxesSOL, AxesAOM, calcs});
set(RegSlider(6),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 6, AxesSOL, AxesAOM, calcs});
set(RegSlider(7),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 7, AxesSOL, AxesAOM, calcs});
set(RegSlider(8),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 8, AxesSOL, AxesAOM, calcs});
set(RegSlider(9),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 9, AxesSOL, AxesAOM, calcs});
set(RegText(24),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 24, AxesSOL, AxesAOM, calcs});
set(RegText(25),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 25, AxesSOL, AxesAOM, calcs});
set(RegText(26),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 26, AxesSOL, AxesAOM, calcs});
set(RegText(27),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 27, AxesSOL, AxesAOM, calcs});
set(RegText(28),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 28, AxesSOL, AxesAOM, calcs});
set(RegText(29),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 29, AxesSOL, AxesAOM, calcs});

set(Button(16),'Callback',{@cbslitexPGA, emptybutton, Button, RegText, RegSlider, Recondition, 100, AxesSOL, AxesAOM, calcs});
set(Button(17),'Callback',{@buttonautocomputeAPGA, emptybutton, Button, RegSlider, RegText, AxesSOL, AxesAOM, calcs, usmn, usmf, lcs, AxesD, AxesSVD, LCS, rbplotsvd, Recondition, levpeakmark});
% set(Button(17),'Callback',{@buttonautocomputeAPGAtest, emptybutton, Button, RegSlider, RegText, AxesSOL, AxesAOM, calcs, usmn, usmf, lcs, AxesD, AxesSVD, LCS, rbplotsvd, Recondition});
set(Button(18),'Callback',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider, Recondition, DataText});
set(rbgautopga(1),'Callback',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider, Recondition, DataText});
set(rbgautopga(2),'Callback',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider, Recondition, DataText});
set(rbgautopga(3),'Callback',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider, Recondition, DataText});
set(rbgautopga(4),'Callback',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider, Recondition, DataText});
set(rbgautopga(5),'Callback',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider, Recondition, DataText});

set(SensSlider(1),'Callback',{@makesens, emptybutton, Button, AxesD, RegSlider, AutoPGAText, SensSlider});
set(AutoPGAText(3),'Callback',{@makemaxdet, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider});

set(WeightButton(1),'Callback',{@changeWeights, emptybutton, Button, RegSlider, RegText, Recondition, 1, AxesSOL, AxesAOM, calcs});
set(WeightButton(2),'Callback',{@changeWeights, emptybutton, Button, RegSlider, RegText, Recondition, 2, AxesSOL, AxesAOM, calcs});
set(WeightButton(3),'Callback',{@changeWeights, emptybutton, Button, RegSlider, RegText, Recondition, 3, AxesSOL, AxesAOM, calcs});
set(WeightButton(4),'Callback',{@changeWeights, emptybutton, Button, RegSlider, RegText, Recondition, 4, AxesSOL, AxesAOM, calcs});
set(WeightButton(5),'Callback',{@changeWeights, emptybutton, Button, RegSlider, RegText, Recondition, 5, AxesSOL, AxesAOM, calcs});
set(WeightButton(6),'Callback',{@changeWeights, emptybutton, Button, RegSlider, RegText, Recondition, 6, AxesSOL, AxesAOM, calcs});
set(WeightsaveButton(1),'Callback',{@saveWeights, WeightButton,  RegSlider})

set(RegText(63),'Callback',{@cbresetsolPGA, emptybutton, RegSlider, RegText, usmn, usmf});

set(Radiogroup(3),'SelectionChangeFcn', {@buttonselectlvPGA, emptybutton, Button, RegSlider, RegText, usmn, usmf});
set(Radiogroup(4),'SelectionChangeFcn',{@autodetectPGA, emptybutton, Button, rbgautopga, AxesD, RegSlider, AutoPGAText, SensSlider});

set(gcf,'WindowButtonDownFcn', {@fcnbdPGA, fig, emptybutton, Button, AxesD, AxesSVD, AxesSOL, Recondition})
set(gcf,'WindowButtonUpFcn', {@fcnbuPGA, emptybutton, Button, AxesD, DataText, RegSlider, Recondition, lcs, LCS})
set(gcf,'WindowButtonMotionFcn', {@fcnmoPGA, emptybutton, Button, AxesD, lcs, LCS})

set(fig,'Visible','on')

function emptybutton_CB(hObject, eventdata)
data.ismatrix = 0;
data.isnmf = 0;
data.isafs = 0;
set(hObject,'UserData',data);
