function subGUI4CAA(version,nr,basicfsz)
% The toolbox FACPACK, which includes the function subGUI4CAA, provides software 
% to apply complementarity and coupling arguments to analyse feasible solutions for
% three components systems.
% Copyright (c) 2013 Mathias Sawall, 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, 'subfcnsCAA'];
calclib = [calcp, 'subfcnsLIB'];
path(path, calcp);
path(path, calcs);
path(path, calclib);

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 (Duality/complementarity and AFS, version ',num2str(version,'%2.2f'), ')'],'NumberTitle','off',...
    'MenuBar','none','Toolbar','none','color','w','Visible','off');

if ispc
%     basicfsz = 5;
    basichi = 0.025;
else
%     basicfsz = 6.5;
    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);

lcs = [0 0.4470 0.7410; 0.8500 0.3250 0.0980; 0.9290 0.6940 0.1250; 0 0.4470 0.7410; 0.8500 0.3250 0.0980; 0.9290 0.6940 0.1250];
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','Profiles C','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.1, 0.927, 0.2, 1.5*basichi]);

titles(2) = uicontrol('Style','text','String','Profiles S','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.6, 0.927, 0.3, 1.5*basichi]);

titles(3) = uicontrol('Style','text','String','U-space','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.03, 0.477, 0.3, 1.5*basichi]);

titles(4) = uicontrol('Style','text','String','V-space','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.62, 0.477, 0.3, 1.5*basichi]);

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


% The infomation-text-field
Footnote = uicontrol('Style','text','String','Computational-time info','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.002, 0.002, 0.996, basichi]);
% The data-info text-field
Datainfo(1) = uicontrol('Style','text','String','Data info','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.9, 0.16, .85*basichi]);

Datainfo(2) = uicontrol('Style','text','String',' spectra:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.87, 0.16, basichi]);

Datainfo(3) = uicontrol('Style','text','String',' channels:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.84, 0.16, basichi]);

Datainfo(4) = uicontrol('Style','text','String','SVD info','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.8, 0.16, .85*basichi]);

Datainfo(5) = uicontrol('Style','text','String',' s(1): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.415, 0.77, 0.16, basichi]);

Datainfo(6) = uicontrol('Style','text','String',' s(2): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.415, 0.74, 0.16, basichi]);

Datainfo(7) = uicontrol('Style','text','String',' s(3): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.415, 0.71, 0.16, basichi]);

Datainfo(8) = uicontrol('Style','text','String',' s(4): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.415, 0.68, 0.16, basichi]);


AFSinfo(1) = uicontrol('Style','text','String','AFS live view','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.365, 0.16, .85*basichi]);

AFSinfo(2) = uicontrol('Style','text','String','live-view C','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.34, 0.075, .85*basichi]);

AFSinfo(3) = uicontrol('Style','text','String','live-view S','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.5, 0.34, 0.075, .85*basichi]);


AFStype(1) = uicontrol('Style','text','String','Type of AFS','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.48, 0.105, .85*basichi]);

AFStype(2) = uicontrol('Style','text','String','Option','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.525, 0.48, 0.05, .85*basichi]);


% The control-parameters for the polygon inflation
Polyparameter(1) = uicontrol('Style','text','String','AFS control parameter','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.64, 0.16, .85*basichi]);

Polyparameter(1) = uicontrol('Style','text','String','e-neg. entr.: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.61, 0.1, basichi]);

Polyparameter(2) = uicontrol('Style','text','String','e-bound: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.58, 0.1, basichi]);

Polyparameter(3) = uicontrol('Style','text','String','d-stopping: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.55, 0.1, basichi]);

Polyparameter(4) = uicontrol('Style','text','String','no sing. vctrs.: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.52, 0.1, basichi]);


% The control-values for the polygon inflation
Polysettings(1) = uicontrol('Style','edit','String',' 1.0e-12','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.61, 0.055, basichi],...
    'TooltipString', sprintf('Acceptable relative negativeness for\nan NMF.\nValue greater than 0.'));

Polysettings(2) = uicontrol('Style','edit','String',' 1.0e-03','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.58, 0.055, basichi],...
    'TooltipString', sprintf('Precision at the boundary.'));

Polysettings(3) = uicontrol('Style','edit','String',' 1.0e-03','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.55, 0.055, basichi],...
    'TooltipString', sprintf('Stopping precision.'));

Polysettings(4) = uicontrol('Style','edit','String',' 3','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.52, 0.055, basichi],...
    'TooltipString', sprintf('Stopping precision.'));


% The contour information on the AFS
Contourinfo(1) = uicontrol('Style','text','String','Add contour functions','HorizontalAlignment','center','Fontsize',1.7*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.17, 0.16, .85*basichi]);


% The axes
AxesC = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.03, 0.1, 0.37, 0.37]);
plot(AxesC,1,0,'w');

AxesA = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.6, 0.1, 0.37, 0.37]);
plot(AxesA,1,0,'w');

AxesSOLC = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.03, 0.55, 0.37, 0.37]);
plot(AxesSOLC,1,0,'w');

AxesSOLA = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.6, 0.55, 0.37, 0.37]);
plot(AxesSOLA,1,0,'w');


% The buttons with all UserData in emptybutton
emptybutton = uicontrol('Style','pushbutton','Position',[0.415, 0.93, 0.16, basichi],'Visible','off');


data.isdata = 0;

data.xlc = [];
data.ylc = [];
data.xla = [];
data.yla = [];

data.Draw = [];
data.Uraw = [];
data.Sraw = [];
data.Vraw = [];
data.maxz = 0;

data.D = [];
data.L = [];
data.R = [];
data.motion = 0;
data.motionC = 0;
data.choosen = zeros(3,1);
data.choosenC = zeros(3,1);
data.fixA = [];
data.fixC = [];

data.isAFSC = 0;
data.isAFSA = 0;
data.AFSC = [];
data.AFSA = [];
data.istrace = 0;

data.regcon = 0;
data.regconC = 0;

data.isregcon = zeros(1,3);
data.isregconC = zeros(1,3);

data.isnmf = 0;
data.afscomputed = [0; 0];
data.selectplot = [0; 0];

data.givenc.s = 0;
data.givenc.is = 0;
data.givenc.line = [];
data.givenc.afs = [];

data.givena.s = 0;
data.givena.is = 0;
data.givena.line = [];
data.givena.afs = [];

data.maxnoise = 2.E-1;

data.full.isA    = 0;
data.full.AFSA   = [];
data.full.linesA = [];
data.full.validA = [];
data.full.dimA   = [];

data.full.isC    = 0;
data.full.AFSC   = [];
data.full.linesC = [];
data.full.validC = [];
data.full.dimC   = [];

data.isclosure = 0;
data.isshift = 1;
data.ispeakposition = 1;

data.calca = [calcp, 'subfcnsAFS'];

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

Radiogroup(1) = uibuttongroup('visible','on','Position',[0.5, 0.205, .075, .13],'BackgroundColor',bgc);
Radiogroup(2) = uibuttongroup('visible','on','Position',[0.415, 0.205, .075, .13],'BackgroundColor',bgc);
Radiogroup(3) = uibuttongroup('visible','on','Position',[0.5, 0.065, .075, .1],'BackgroundColor',bgc);
Radiogroup(4) = uibuttongroup('visible','on','Position',[0.415, 0.065, .075, .1],'BackgroundColor',bgc);
Radiogroup(5) = uibuttongroup('visible','on','Position',[0.415, 0.4525, .105, basichi],'BackgroundColor',bgc);
Radiogroup(6) = uibuttongroup('visible','on','Position',[0.525, 0.4525, .05, basichi],'BackgroundColor',bgc);
Radiogroup(7) = uibuttongroup('visible','on','Position',[0.415, 0.425, .16, basichi],'BackgroundColor',bgc);

uonoff(1) = uicontrol('Style','radiobutton','String',' off ','Units','normalized','Position',[0.01, 0.76, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(1),'HandleVisibility','off','Value',1,'BackgroundColor',bgc);

uonoff(2) = uicontrol('Style','radiobutton','String',' first ','Units','normalized','Position',[0.01, 0.52, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(1),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Move the mouse courser throught the AFS for A and lock the first point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(1,:));

uonoff(3) = uicontrol('Style','radiobutton','String',' second ','Units','normalized','Position',[0.01, 0.28, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(1),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Move the mouse courser throught the AFS for A and lock the second point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(2,:));

uonoff(4) = uicontrol('Style','radiobutton','String',' third ','Units','normalized','Position',[0.01, 0.04, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(1),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Move the mouse courser throught the AFS for A and lock the third point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(3,:));

uonoffC(1) = uicontrol('Style','radiobutton','String',' off ','Units','normalized','Position',[0.01, 0.76, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',1,'BackgroundColor',bgc);

uonoffC(2) = uicontrol('Style','radiobutton','String',' first ','Units','normalized','Position',[0.01, 0.52, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Move the mouse courser throught the AFS for C and lock the first point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(4,:));

uonoffC(3) = uicontrol('Style','radiobutton','String',' second ','Units','normalized','Position',[0.01, 0.28, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Move the mouse courser throught the AFS for C and lock the second point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(5,:));

uonoffC(4) = uicontrol('Style','radiobutton','String',' third ','Units','normalized','Position',[0.01, 0.04, 0.98, 0.2],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Move the mouse courser throught the AFS for C and lock the third point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(6,:));

specialfsz = 1.6*basicfsz;
regcont(1) = uicontrol('Style','radiobutton','String',' off ','Units','normalized','Position',[0.01, 0.76, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',1,'BackgroundColor',bgc);

regcont(2) = uicontrol('Style','radiobutton','String',' smooth','Units','normalized','Position',[0.01, 0.52, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Add contour plot of the Euclidean norm of the discrete second derivative for the spectra.'),'BackgroundColor',bgc);

regcont(3) = uicontrol('Style','radiobutton','String',' norm','Units','normalized','Position',[0.01, 0.28, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Add contour plot of the Euclidean norm of the spectra.'),'BackgroundColor',bgc);

regcontC(1) = uicontrol('Style','radiobutton','String',' off ','Units','normalized','Position',[0.01, 0.76, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',1,'BackgroundColor',bgc);

regcontC(2) = uicontrol('Style','radiobutton','String',' monotone','Units','normalized','Position',[0.01, 0.52, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Add contour function evaluating the degree of monotonicity.'),'BackgroundColor',bgc);

regcontC(3) = uicontrol('Style','radiobutton','String',' smooth','Units','normalized','Position',[0.01, 0.28, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Add contour plot of the Euclidean norm of the discrete second derivative for the concentrations profiles.'),'BackgroundColor',bgc);

regcontC(4) = uicontrol('Style','radiobutton','String',' exponential','Units','normalized','Position',[0.01, 0.04, 0.98, 0.2],...
    'Fontsize', specialfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Add contour plot evaluating the closeness to an exponentially decaying function.'),'BackgroundColor',bgc);

typeAFS(1) = uicontrol('Style','checkbox','String','outer polygon','Units','normalized','Position',[0.01, 0.04, 0.58, 0.92],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(5),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Show FIRPOL for both factors.'),'BackgroundColor',bgc);

typeAFS(2) = uicontrol('Style','checkbox','String','AFS','Units','normalized','Position',[0.6, 0.04, 0.39, 0.92],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(5),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Show AFS for both factors.'),'BackgroundColor',bgc);

typeAFS(3) = uicontrol('Style','checkbox','String','data points','Units','normalized','Position',[0.01, 0.04, 0.98, 0.92],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(6),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Show traces of D in AFS for C and A.'),'BackgroundColor',bgc);

ipia(1) = uicontrol('Style','radiobutton','String',' use pol. infl. alg.','Units','normalized','Position',[0.01, 0.04, 0.45, 0.92],...
    'Fontsize',1.7*basicfsz,'FontName',sty,'parent',Radiogroup(7),'HandleVisibility','off','Value',1,...
    'TooltipString', sprintf('Use the polygon inflation algorithm in order to compute the AFS-sets.'),'BackgroundColor',bgc);

ipia(2) = uicontrol('Style','radiobutton','String',' use inv. pol. infl. alg.','Units','normalized','Position',[0.451, 0.04, 0.54, 0.92],...
    'Fontsize',1.7*basicfsz,'FontName',sty,'parent',Radiogroup(7),'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Use the inverse polygon inflation algorithm in order to compute the AFS-sets.'),'BackgroundColor',bgc);

plotoptions(1) = uicontrol('Style','checkbox','String','Apply closure','Units','normalized','Position',[0.015, 0.03, .08, basichi],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Plot both factors scaled by closure.'),'BackgroundColor',bgc);

plotoptions(2) = uicontrol('Style','checkbox','String','Shift spectra','Units','normalized','Position',[0.103, 0.03, .08, basichi],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'HandleVisibility','off','Value',1,...
    'TooltipString', sprintf('Plot the spectra using a shift.'),'BackgroundColor',bgc);

plotoptions(3) = uicontrol('Style','checkbox','String','Peak positions','Units','normalized','Position',[0.19, 0.03, .08, basichi],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'HandleVisibility','off','Value',1,...
    'TooltipString', sprintf('Add peak positions to the spectra.'),'BackgroundColor',bgc);

plotoptions(4) = uicontrol('Style','checkbox','String','Raman data','Units','normalized','Position',[0.277, 0.03, .08, basichi],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'HandleVisibility','off','Value',0,...
    'TooltipString', sprintf('Flip the direction of the x-axis for Raman data.'),'BackgroundColor',bgc);

set(Radiogroup(1),'SelectionChangeFcn', {@buttonselect0123CAA, emptybutton, AxesC, AxesA, uonoff, uonoffC, 1});
set(Radiogroup(2),'SelectionChangeFcn', {@buttonselect0123CAA, emptybutton, AxesC, AxesA, uonoff, uonoffC, 0});
set(Radiogroup(3),'SelectionChangeFcn', {@buttonselectcontourCAA, emptybutton, AxesC, AxesA, AxesSOLA, AxesSOLC, uonoff, uonoffC, regcont, regcontC, 1, lcs});
set(Radiogroup(4),'SelectionChangeFcn', {@buttonselectcontourCAA, emptybutton, AxesC, AxesA, AxesSOLA, AxesSOLC, uonoff, uonoffC, regcont, regcontC, 0, lcs});

Button(6) = uicontrol('Style','pushbutton','UserData',0,'String','Export spectrum to library','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.825, 0.03, .15, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Export a single spectrum to the library.'),...
    'Callback',{@buttonexport2libCAA, emptybutton, lcs, basichi, basicfsz, sty, calclib, version});

Button(5) = uicontrol('Style','pushbutton','UserData',0,'String','Import conc. profiles','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.36, 0.03, .15, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Import concentration profiles as vector or matrix "c" from a mat-file, profiles are listed columnswise in "c".\nPoints in the AFS are denoted by "*".'),...
    'Callback',{@buttonloadconcentrationsCAA, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, uonoff, uonoffC, regcont, regcontC, lcs});

Button(4) = uicontrol('Style','pushbutton','UserData',0,'String','Import spectra','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.67, 0.03, .15, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Import spectra as vector or matrix "a" from a mat-file, spectra are listed rowwise in "a".\nPoints in the AFS are denoted by "*".'),...
    'Callback',{@buttonloadspectraCAA, fig, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, uonoff, uonoffC, regcont, regcontC, basicfsz, basichi, calclib, lcs, sty});

Button(3) = uicontrol('Style','pushbutton','UserData',0,'String','Save results','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.515, 0.03, .15, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Save the AFS and the constructed solution.'),...
    'Callback',{@buttonsaveCAA, emptybutton});

Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Reset all computations','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.395, 0.16, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Reset the computations of the AFS and the selected points.'),...
    'Callback',{@buttonresetCAA, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, titles, uonoff, uonoffC, regcont, regcontC, typeAFS});

Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Load','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',get(emptybutton,'Position'),...
    'TooltipString', sprintf('Load mat-file containing data matrix D (spectra  x channels)\nand optional channels-vector "x" and time-vector "t".'),...
    'Callback',{@buttonloadCAA, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Datainfo, Polysettings, titles, uonoff, uonoffC, regcont, regcontC, typeAFS, plotoptions});

set(typeAFS(1), 'Callback',{@typeafsCAA, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, regcont, regcontC, typeAFS, ipia, 0, lcs});
set(typeAFS(2), 'Callback',{@typeafsCAA, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, regcont, regcontC, typeAFS, ipia, 1, lcs});
set(typeAFS(3), 'Callback',{@selecttraceCAA, emptybutton, Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, regcont, regcontC, 1, lcs});
set(plotoptions(1), 'Callback',{@selectclosureCAA, emptybutton, Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, regcont, regcontC, 1, lcs, 1});
set(plotoptions(2), 'Callback',{@selectclosureCAA, emptybutton, Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, regcont, regcontC, 1, lcs, 2});
set(plotoptions(3), 'Callback',{@selectclosureCAA, emptybutton, Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, regcont, regcontC, 1, lcs, 3});
set(plotoptions(4), 'Callback',{@selectclosureCAA, emptybutton, Button, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, regcont, regcontC, 1, lcs, 4});

set(gcf,'WindowButtonMotionFcn', {@liveviewCAA, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, lcs, plotoptions});
set(gcf,'WindowButtonDownFcn', {@lockpointCAA, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC});

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