function subGUI4CA4(version,nr,basicfsz)
% The toolbox FACPACK, which includes the function subGUI4CA4, provides software 
% to apply complementarity and coupling arguments to analyse feasible solutions for
% four components systems.
% Copyright (c) 2016 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. Furthermore the user has to
% respect the license for the file Mouse3D.m from the Mathworks File
% Exchange, see http://www.mathworks.com/matlabcentral/fileexchange/view_license?file_info_id=18266

fname = mfilename;
calcp = mfilename('fullpath');
calcp = calcp(1:end-length(fname));
calcs = [calcp, 'subfcnsCA4'];
calcr = [calcp, 'subfcnsRAY'];
calclib = [calcp, 'subfcnsLIB'];
path(path, calcp);
path(path, calcs);
path(path, calcr);
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 and AFS for 4-component systems, version ',num2str(version,'%2.2f'), '-alpha)'],...
    'NumberTitle','off','MenuBar','none','Toolbar','none','color','w','Visible','off');

if ispc
%     basicfsz = 4.5;
    basichi = 0.025;
else
%     basicfsz = 5.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 1;0 0.5 0;1 0 0;0 0.5 0.5;0.5 0 0.5;0.5 0.5 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','Factor 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','Factor 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.0775, 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.0775, 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.0775, basichi]);

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

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

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



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

AFSinfo(2) = uicontrol('Style','text','String','factor C','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor',bgc,'Units','normalized','FontName',sty,'Position',[0.415, 0.305, 0.075, .85*basichi]);

AFSinfo(3) = uicontrol('Style','text','String','factor S','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor',bgc,'Units','normalized','FontName',sty,'Position',[0.5, 0.305, 0.075, .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.66, 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.63, 0.1, basichi]);

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

Polyparameter(3) = uicontrol('Style','text','String','refinements: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.415, 0.57, 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.54, 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.63, 0.055, basichi],...
    'TooltipString', sprintf('Acceptable relative negativeness for\nan NMF.\nValue greater than 0.'));

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

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

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

% 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(4,1);
data.choosenC = zeros(4,1);
data.fixA = [];
data.fixC = [];

data.actx = [];
data.lv.lastStart = [];
data.lvC.lastStart = [];

data.islv = 0;
data.is3dmouse = 0;

data.isAFSC = 0;
data.isAFSA = 0;
data.afsC = [];
data.afsA = [];

data.isFP = 0;
data.isIP = 0;

data.FIRPOLA = [];
data.FIRPOLC = [];
data.INNPOLA = [];
data.INNPOLC = [];

data.isnmf = 0;
data.afscomputed = [0; 0; 0];
data.selectplot = [0; 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.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.calca = [calcp, 'subfcnsAFS'];
data.calcr = [calcp, 'subfcnsRAY'];

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

lvText(1) = uicontrol('Style','text','String','x:','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.41, 0.125, 0.015, 0.9*basichi]);

lvText(2) = uicontrol('Style','text','String','y:','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.41, 0.095, 0.015, 0.9*basichi]);

lvText(3) = uicontrol('Style','text','String','z:','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.41, 0.065, 0.015, 0.9*basichi]);

lvText(4) = uicontrol('Style','edit','String','0.0','HorizontalAlignment','right','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.55, 0.125, 0.035, basichi]);

lvText(5) = uicontrol('Style','edit','String','0.0','HorizontalAlignment','right','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.55, 0.095, 0.035, basichi]);

lvText(6) = uicontrol('Style','edit','String','0.0','HorizontalAlignment','right','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.55, 0.065, 0.035, basichi]);

lvText(7) = uicontrol('Style','text','String','live-view control with sliders','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.41, 0.16, 0.175, 0.7*basichi]);

for i=1:3
    lvSlider(i) = uicontrol('Style','slider','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.425, 0.125-(i-1)*0.03, 0.12, 0.9*basichi],'Min',-2,'Max',2,'Value',0,...
    'SliderStep',[0.1 0.5],'TooltipString', sprintf('live-view slider for points in the AFS of C or the AFS of A.'));
    
end

Radiogroup(1) = uibuttongroup('visible','on','Position',[0.5, 0.19, .075, .11],'BackgroundColor',bgc);
Radiogroup(2) = uibuttongroup('visible','on','Position',[0.415, 0.19, .075, .11],'BackgroundColor',bgc);
Radiogroup(3) = uibuttongroup('visible','on','Position',[0.415, 0.49, .16, basichi],'BackgroundColor',bgc);
Radiogroup(6) = uibuttongroup('visible','on','Position',[0.415, 0.46, .16, basichi],'BackgroundColor',bgc);

uonoff(1) = uicontrol('Style','radiobutton','String',' off ','Units','normalized','Position',[0.01, 0.78, 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.59, 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.4, 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.21, 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,:));

uonoff(5) = uicontrol('Style','radiobutton','String',' fourth ','Units','normalized','Position',[0.01, 0.02, 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 fourth point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(4,:));


uonoffC(1) = uicontrol('Style','radiobutton','String',' off ','Units','normalized','Position',[0.01, 0.78, 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.59, 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(1,:));

uonoffC(3) = uicontrol('Style','radiobutton','String',' second ','Units','normalized','Position',[0.01, 0.4, 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(2,:));

uonoffC(4) = uicontrol('Style','radiobutton','String',' third ','Units','normalized','Position',[0.01, 0.21, 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(3,:));

uonoffC(5) = uicontrol('Style','radiobutton','String',' fourth ','Units','normalized','Position',[0.01, 0.02, 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 fourth point.'),'BackgroundColor',bgc,...
    'ForegroundColor',lcs(4,:));


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

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

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


plotopt(1) = uicontrol('Style','checkbox','String','plot planes','Units','normalized','Position',[0.05, 0.04, 0.4, 0.92],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(6),'HandleVisibility','off','Value',1,...
    'TooltipString', sprintf('Show FIRPOL for both factors.'),'BackgroundColor',bgc);

plotopt(2) = uicontrol('Style','checkbox','String','plot lines','Units','normalized','Position',[0.55, 0.04, 0.4, 0.92],...
    'Fontsize',1.6*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(6),'HandleVisibility','off','Value',1,...
    'TooltipString', sprintf('Show AFS for both factors.'),'BackgroundColor',bgc);


Radiogroup(4) = uibuttongroup('visible','on','Position',[0.415, 0.37, 0.075, .055],'BackgroundColor',bgc);
Radiogroup(5) = uibuttongroup('visible','on','Position',[0.5, 0.37, 0.075, .055],'BackgroundColor',bgc);
rotonoff(1,1) = uicontrol('Style','radiobutton','String','2D rot. on','Units','normalized','Position',[0.01, 0.55, 0.98, 0.45],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate 3D rotation mode to investigate the 3D AFS.'));

rotonoff(1,2) = uicontrol('Style','radiobutton','String','2D rot. off','Units','normalized','Position',[0.01, 0.05, 0.98, 0.45],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',1,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate 3D rotation mode to investigate the 3D AFS.'));

rotonoff(2,1) = uicontrol('Style','radiobutton','String','3D rot. on','Units','normalized','Position',[0.01, 0.55, 0.98, 0.45],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(5),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate 3D rotation mode to investigate the 3D AFS.'));

rotonoff(2,2) = uicontrol('Style','radiobutton','String','3D rot. off','Units','normalized','Position',[0.01, 0.05, 0.98, 0.45],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(5),'HandleVisibility','off','Value',1,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate 3D rotation mode to investigate the 3D AFS.'));


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

Button(6) = uicontrol('Style','pushbutton','UserData',0,'String','Import conc. profiles','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.05, 0.035, .175, 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',{@buttonloadconcentrationsCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, uonoff, uonoffC, plotopt, lvText, lvSlider, lcs});

Button(5) = uicontrol('Style','pushbutton','UserData',0,'String','Import spectra','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.23, 0.035, .175, 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',{@buttonloadspectraCA4, fig, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, uonoff, uonoffC, plotopt, lvText, lvSlider, basicfsz, basichi, calclib, lcs, sty});

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

Button(3) = uicontrol('Style','pushbutton','UserData',0,'String','Lock current live-view profile','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.41, 0.035, 0.175, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Locks the activated profile at the current position.'),...
    'Callback',{@buttonlockCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, 1});

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.43, 0.16, basichi], 'Enable', 'off',...
    'TooltipString', sprintf('Reset the computations of the AFS and the selected points.'),...
    'Callback',{@buttonresetCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, titles, uonoff, uonoffC, typeAFS, plotopt, lvText, lvSlider, lcs});

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',{@buttonloadCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Datainfo, Polysettings, titles, uonoff, uonoffC, typeAFS});

set(Radiogroup(1),'SelectionChangeFcn', {@buttonselect0123CA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvSlider, lvText, 1, lcs});
set(Radiogroup(2),'SelectionChangeFcn', {@buttonselect0123CA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvSlider, lvText, 0, lcs});

set(Radiogroup(4),'SelectionChangeFcn', {@buttonselectrotCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, lcs, rotonoff(1,:), 1});
set(Radiogroup(5),'SelectionChangeFcn', {@buttonselectrotCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, lcs, rotonoff(2,:), 2});

set(plotopt(1), 'Callback',{@plotoptCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, lcs});
set(plotopt(2), 'Callback',{@plotoptCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, lcs});

set(typeAFS(1), 'Callback',{@typeafsCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, typeAFS, plotopt, lvText, lvSlider, 0, lcs});
set(typeAFS(2), 'Callback',{@typeafsCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, typeAFS, plotopt, lvText, lvSlider, 1, lcs});
set(typeAFS(3), 'Callback',{@typeafsCA4, emptybutton, Button, Footnote, AxesC, AxesA, AxesSOLC, AxesSOLA, Polysettings, titles, uonoff, uonoffC, typeAFS, plotopt, lvText, lvSlider, 2, lcs});

for i=1:3
    set(lvText(3+i), 'Callback',{@liveviewCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, i, lcs, [0 0 0]});
    set(lvSlider(i), 'Callback',{@liveviewCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, plotopt, lvText, lvSlider, 3+i, lcs, [0 0 0]});
end

% set(gcf,'WindowButtonMotionFcn', {@liveviewCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, lvText, lvSlider, 0, lcs});
set(gcf,'WindowButtonDownFcn', {@exportaxesCA4, emptybutton, AxesC, AxesA, AxesSOLC, AxesSOLA, uonoff, uonoffC, lvText, lvSlider});

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