function subGUI4RAY(version,nr,basicfsz)
% The toolbox FACPACK, which includes the function subGUI4RAY, provides software 
% for the computation of multi-component factorizations and the area of feasible solutions.
% 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;
calcf = mfilename('fullpath');
calcf = calcf(1:end-length(fname));
calcp = [calcf, 'subfcnsRAY'];
path(path, calcf);
path(path, calcp);

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 (Computation of the AFS by the ray casting method, version ',num2str(version,'%2.2f'), '-alpha)'],...
    'NumberTitle','off','MenuBar','none','Toolbar','none','color','white','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];

% The title names
titles(1) = uicontrol('Style','text','String','Data window','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.96, 0.498, basichi]);

titles(2) = uicontrol('Style','text','String','NMF window','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.501, 0.96, 0.498, basichi]);

titles(3) = uicontrol('Style','text','String',' AFS window','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.11, 0.475, 0.298, 1.2*basichi]);

titles(4) = uicontrol('Style','text','String',' Factor window','HorizontalAlignment','center','Fontsize',3*basicfsz,'BackgroundColor','w',...
    'Units','normalized','FontName',sty,'Position',[0.675, 0.475, 0.148, 1.2*basichi]);

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


% The infomation-text-field
Footnote = uicontrol('Style','text','String','Computational-time info','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.002, 0.002, 0.458, basichi]);


% The data-information-text-fields
Datainfo(1) = uicontrol('Style','text','String','Data info','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.02, 0.81, 0.1, basichi]);

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

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


% The SVD-information-text-fields
SVDinfo(1) = uicontrol('Style','text','String','      svd-info','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.02, 0.69, 0.1, basichi]);

SVDinfo(2) = uicontrol('Style','text','String',' s(1):','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.02, 0.66, 0.1, basichi],...
    'TooltipString', sprintf('First singular value, indicates no components.'));

SVDinfo(3) = uicontrol('Style','text','String',' s(2): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.02, 0.63, 0.1, basichi],...
    'TooltipString', sprintf('Second singular value, indicates no components.'));

SVDinfo(4) = uicontrol('Style','text','String',' s(3): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.02, 0.6, 0.1, basichi],...
    'TooltipString', sprintf('Third singular value, indicates no components.'));

SVDinfo(5) = uicontrol('Style','text','String',' s(4): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.02, 0.57, 0.1, basichi],...
    'TooltipString', sprintf('Fourth singular value, indicates no components.'));

SVDinfo(6) = uicontrol('Style','text','String',' s(5): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName','symbol','Position',[0.02, 0.54, 0.1, basichi],...
    'TooltipString', sprintf('Fifth singular value, indicates no components.'));


% The NMF-parameter-field
NMFparameter(1) = uicontrol('Style','text','String',' singl vcts:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.83, 0.07, basichi]);

NMFparameter(2) = uicontrol('Style','edit','String',' 4','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[0.595, 0.83, 0.025, basichi],...
    'TooltipString', sprintf('Number of right singular vectors to\nuse for the computation of an initial NMF.\nMinimal: no components. Maximal: 5.'));

NMFparameter(3) = uicontrol('Style','text','String',' components:','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.86, 0.07, basichi]);

NMFparameter(4) = uicontrol('Style','text','String','4','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.595, 0.86, 0.025, basichi]);

NMFparameter(5) = uicontrol('Style','text','String','NMF options','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.89, 0.1, basichi]);


% The NMF-information-text-fields
NMFinfo(1) = uicontrol('Style','text','String','NMF info','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.66, 0.1, basichi]);

NMFinfo(2) = uicontrol('Style','text','String',' min(C): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.63, 0.1, basichi]);

NMFinfo(3) = uicontrol('Style','text','String',' min(S): ','HorizontalAlignment','left','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.60, 0.1, basichi]);


% The control-parameters for the polygon-inflation
x_polypar = 0.01;
y_polypar = 0.48;
l_polypar = 0.09;
Polyparameter(1) = uicontrol('Style','text','String','e-neg. entr.: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[x_polypar, y_polypar, l_polypar, basichi],...
    'TooltipString', sprintf('Acceptable relative negativeness for\nan NMF. The value has to be greater than 0.'));

Polyparameter(2) = uicontrol('Style','text','String','e-bound: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[x_polypar, y_polypar-0.03, l_polypar, basichi],...
    'TooltipString', sprintf('Precision at the boundary.'));

Polyparameter(3) = uicontrol('Style','text','String','number of rays: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[x_polypar, y_polypar-0.06, l_polypar, basichi],...
    'TooltipString', sprintf('Number of rays used for the computation. More rays result in\na finer grid but takes more computational time.'));

Polyparameter(4) = uicontrol('Style','text','String','refinement levels: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[x_polypar, y_polypar-0.09, l_polypar, basichi],...
    'TooltipString', sprintf('Number of refinement levels. The results of connected rays are\nused in order to avoid problems caused by the numerical\noptimization process.'));

Polyparameter(5) = uicontrol('Style','text','String','max fcls.: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[x_polypar, y_polypar-0.12, l_polypar, basichi],...
    'TooltipString', sprintf('Maximal number of function calls.'));

Polyparameter(6) = uicontrol('Style','text','String','red. per iter. (%): ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[x_polypar, y_polypar-0.15, l_polypar, basichi],...
    'TooltipString', sprintf('The relative reduction per ray for the computation of the inner boundary points.\nA small stepsize results in a stable computation but takes much computational effort.'));

% The control-values for the polygon-inflation
x_polyset = 0.105;
l_polyset = 0.055;
yv = get(Polyparameter(1),'Position');
Polysettings(1) = uicontrol('Style','edit','String',' 1.0e-12','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[x_polyset, yv(2), l_polyset, basichi],...
    'TooltipString', sprintf('Acceptable relative negativeness for\nan NMF. The value has to be greater than 0.'));

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

yv = get(Polyparameter(3),'Position');
Polysettings(3) = uicontrol('Style','edit','String','1000','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[x_polyset, yv(2), l_polyset, basichi],...
    'TooltipString', sprintf('Number of rays used for the computation. More rays result in\na finer grid but takes more computational time.'));

yv = get(Polyparameter(4),'Position');
Polysettings(4) = uicontrol('Style','edit','String','4','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[x_polyset, yv(2), l_polyset, basichi],...
    'TooltipString', sprintf('Number of refinement levels. The results of connected rays are\nused in order to avoid problems caused by the numerical\noptimization process.'));

yv = get(Polyparameter(5),'Position');
Polysettings(5) = uicontrol('Style','edit','String','20000','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[x_polyset, yv(2), l_polyset, basichi],...
    'TooltipString', sprintf('Maximal number of function calls.'));

yv = get(Polyparameter(6),'Position');
Polysettings(6) = uicontrol('Style','edit','String','2.5','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[x_polyset, yv(2), l_polyset, basichi],...
    'TooltipString', sprintf('The relative reduction per ray for the computation of the inner boundary points.\nA small stepsize results in a stable computation but takes much computational effort.'));

% The control-parameters for the AFS-transformation-plot
xv = 0.52;
yv = [0.01 0.43];
TextTrafo(1) = uicontrol('Style', 'text', 'String', 'plot feasible bands','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty, 'Position', [xv(1), yv(2)+0.02 0.125 0.025]);

SegTrafo = uicontrol('Style', 'popup', 'String', 'select segment','Units','normalized','Fontsize',2*basicfsz,...
    'FontWeight','bold','FontName',sty, 'Position', [xv(1), yv(2)-0.03 0.125 0.04]);

Plotparameter(1) = uicontrol('Style','text','String',' used bnd. pnts. (in %): ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[xv(1), yv(2)-0.05, .09, basichi]);

Plotparameter(2) = uicontrol('Style','text','String',' inner points per ray: ','HorizontalAlignment','right','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[xv(1), yv(2)-0.08, .09, basichi]);


% The control-values for the AFS-transformation-plot
yv = get(Plotparameter(1),'Position');
Plotsettings(1) = uicontrol('Style','edit','String',' 30','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[yv(1)+yv(3)+0.005, yv(2), .03, basichi]);

yv = get(Plotparameter(2),'Position');
Plotsettings(2) = uicontrol('Style','edit','String',' 3','HorizontalAlignment','right','Fontsize',2*basicfsz,...
    'Units','normalized','FontName',sty,'Position',[yv(1)+yv(3)+0.005, yv(2), .03, basichi]);


% The AFS-transformation-information text-fields
xv = get(Plotparameter(1),'Position');
yv = get(Plotsettings(1),'Position');

% The Radio-buttons for AFS-motion-transformation
Textlv(1) = uicontrol('Style', 'text', 'String', 'AFS plot options','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty, 'Position', [0.01, 0.255 0.15 0.025]);

Radiogroup(1) = uibuttongroup('visible','on','Position',[0.01, 0.175, 0.15, .05],'BackgroundColor',bgc);
roton = uicontrol('Style','radiobutton','String',' 2D mouse rotation on','Units','normalized','Position',[0.01, 0.6, 0.98, 0.3],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(1),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate 3D rotation mode to investigate the 3D AFS.'));

rotoff = uicontrol('Style','radiobutton','String',' 2D mouse rotation off','Units','normalized','Position',[0.01, 0.15, 0.98, 0.3],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(1),'HandleVisibility','off','Value',1,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Deactivate 3D rotationmode.'));

Radiogroup(2) = uibuttongroup('visible','on','Position',[0.01, 0.065, 0.15, .05],'BackgroundColor',bgc);
IPonoff(1) = uicontrol('Style','radiobutton','String',' add INNPOL','Units','normalized','Position',[0.01, 0.6, 0.98, 0.3],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Add INNPOL to the AFS.'));

IPonoff(2) = uicontrol('Style','radiobutton','String',' hide INNPOL','Units','normalized','Position',[0.01, 0.15, 0.98, 0.3],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(2),'HandleVisibility','off','Value',1,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Hide INNPOL from the AFS.'));

Radiogroup(3) = uibuttongroup('visible','on','Position',[0.01, 0.12, 0.15, .05],'BackgroundColor',bgc);
FPonoff(1) = uicontrol('Style','radiobutton','String',' add FIRPOL','Units','normalized','Position',[0.01, 0.6, 0.98, 0.3],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Add FIRPOL to the AFS.'));

FPonoff(2) = uicontrol('Style','radiobutton','String',' hide FIRPOL','Units','normalized','Position',[0.01, 0.15, 0.98, 0.3],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(3),'HandleVisibility','off','Value',1,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Hide FIRPOL from the AFS.'));

SegPlot = uicontrol('Style', 'popup', 'String', 'plot complete AFS','Units','normalized','Fontsize',2*basicfsz,...
    'FontWeight','bold','FontName',sty, 'Position', [0.011 0.21 0.15 0.04]);


Textsv = uicontrol('Style', 'text', 'String', 'slider for live-view','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty, 'Position', [0.52, 0.27 0.125 0.025]);

Textlv(2) = uicontrol('Style', 'text', 'String', 'live-view option','HorizontalAlignment','center','Fontsize',2.5*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty, 'Position', [0.52, 0.135 0.125 0.025]);

Radiogroup(4) = uibuttongroup('visible','on','Position',[0.52, 0.07, 0.125, .06],'BackgroundColor',bgc);
usmn = uicontrol('Style','radiobutton','String',' 3D mouse live-view on','Units','normalized','Position',[0.01, 0.6, 0.98, 0.25],...
    'Fontsize',2*basicfsz,'FontWeight','bold','FontName',sty,'parent',Radiogroup(4),'HandleVisibility','off','Value',0,'BackgroundColor',bgc,...
    'TooltipString', sprintf('Activate live-view mode to represent\nthe factors just in time. Move a 3D mouse\npointer through the AFS.'));

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

lvText(1) = uicontrol('Style','text','String','x:','HorizontalAlignment','left','Fontsize',2.5*basicfsz,...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.52, 0.236, 0.015, basichi]);

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

lvText(3) = uicontrol('Style','text','String','y:','HorizontalAlignment','left','Fontsize',2.5*basicfsz,...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.52, 0.206, 0.015, basichi]);

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

lvText(5) = uicontrol('Style','text','String','z:','HorizontalAlignment','left','Fontsize',2.5*basicfsz,...
    'BackgroundColor','w','Units','normalized','FontName',sty,'Position',[0.52, 0.176, 0.015, basichi]);

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

for i=1:3
    xv = get(lvText(2*i),'Position');
    
    lvSlider(i) = uicontrol('Style','slider','String','a','HorizontalAlignment','center','Fontsize',2*basicfsz,'BackgroundColor',bgc,...
    'Units','normalized','FontName',sty,'Position',[0.53, 0.24-(i-1)*0.03, 0.08, basichi],'Min',-2,'Max',2,'Value',0,...
    'SliderStep',[0.1 0.5],'TooltipString', sprintf('Weight for the penalty function.'));    
end


% The axes for the data, the NFM, the AFS and the transformed AFS
AxesD = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.15, 0.55, 0.35, 0.37]);
plot(AxesD,1,0,'w');

AxesNMF = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.66, 0.545, 0.3, 0.38]);
plot(AxesNMF,1,0,'w');

AxesAFS = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.18, 0.07, 0.3, 0.4]);
plot(AxesAFS,0,0,'w');

AxesSOL = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.66, 0.07, 0.3, 0.4]);
plot(AxesSOL,1,0,'w');


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

data.ismatrix = 0;
data.isnmf = 0;
data.isafs = 0;
data.calcp = calcp;
data.isExpert1 = 0;
data.isExpert2 = 0;
data.isLastClickLockMode = 0;
data.isimport = 0;
data.import = [];
data.islv = 0;
data.lvactx = [0 0 0];

data.plotIP = 0;
data.plotFP = 0;

data.isplane = 0;
data.plane.x = 0;
data.plane.y = 0;
data.plane.z = 1;
data.plane.d = 0;

data.issliced = 0;
data.isRib = [0 0 0];
set(emptybutton,'UserData',data);

xv = get(Plotparameter(1),'Position');
yv = get(Plotsettings(1),'Position');
yv2 = get(Polyparameter(5),'Position');

% ALT 13
Button(11) = uicontrol('Style','pushbutton','UserData',0,'String','View logfile ray computation','HorizontalAlignment','center','Fontsize',1.5*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.035, 0.15, basichi],'Enable','off',...
    'TooltipString', 'View logfile for computation details.',...
    'Callback', {@buttonviewlogfileRAY, fig, emptybutton, basichi, basicfsz, sty, 1});

Button(10) = uicontrol('Style','pushbutton','UserData',0,'String','Save all','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[xv(1)+0.225, 0.01, xv(3)+0.125, basichi],'Enable','on',...
    'TooltipString', 'Save all results in .mat-file.',...
    'Callback', {@buttonsaveallRAY, emptybutton, Footnote, AxesAFS, AxesSOL, Plotsettings});

Button(9) = uicontrol('Style','pushbutton','UserData',0,'String','Save AFS','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[xv(1), 0.01, xv(3)+0.125, basichi],'Enable','on',...
    'Tooltip', 'Save AFS-results (initial NMF + AFS) in .mat-file.',...
    'Callback', {@buttonsaveafsRAY, emptybutton, Button, Footnote, AxesAFS, AxesSOL, Plotsettings});

Button(8) = uicontrol('Style','pushbutton','UserData',1,'String','Plot feasible bands','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[xv(1), xv(2)-0.06, xv(3)+yv(3)+0.005, basichi],'Enable','on',...
    'Tooltip', 'Show the factors for segment 1 of the AFS (blue or black).',...
    'Callback', {@buttontransformRAY, fig, emptybutton, Button, Footnote, AxesAFS, AxesSOL, Plotsettings, lcs, usmn, usmf, SegTrafo});

yv = get(Polyparameter(5),'Position');
Button(7) = uicontrol('Style','pushbutton','UserData',0,'String','Compute AFS','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.01, 0.3 0.15 basichi],'Enable','on',...
    'Tooltip', 'Compute the AFS.',...
    'Callback', {@buttonafsRAY, fig, emptybutton, Button, Footnote, Polysettings, AxesAFS, AxesSOL, SegPlot, SegTrafo, rotoff, IPonoff, FPonoff, lcs, usmn, usmf, lvText, lvSlider});

Button(6) = uicontrol('Style','pushbutton','UserData',1,'String','plot S','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.71, 0.1, basichi],'Enable','on',...
    'Tooltip', 'Show initial factor S.',...
    'Callback', {@buttonplotnmfRAY, emptybutton, Button, Footnote, AxesNMF, NMFinfo, lcs});

Button(5) = uicontrol('Style','pushbutton','UserData',0,'String','plot C','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.74, 0.1, basichi],'Enable','on',...
    'Tooltip', 'Show initial factor C.',...
    'Callback', {@buttonplotnmfRAY, emptybutton, Button, Footnote, AxesNMF, NMFinfo, lcs});

Button(4) = uicontrol('Style','pushbutton','UserData',2,'String','plot C and S','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.77, 0.1, basichi],'Enable','on',...
    'Tooltip', 'Show initial factor C and A.',...
    'Callback', {@buttonplotnmfRAY, emptybutton, Button, Footnote, AxesNMF, NMFinfo, lcs});

Button(3) = uicontrol('Style','pushbutton','UserData',0,'String','Initial NMF','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.52, 0.8, 0.1, basichi],'Enable','on',...
    'Tooltip', 'Compute an initial NMF.',...
    'Callback', {@buttoninitialnmfRAY, emptybutton, Button, Footnote, AxesNMF, AxesAFS, AxesSOL, NMFparameter, NMFinfo, Polysettings, lcs, usmn, usmf, IPonoff});

Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Transpose','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.02, 0.87, 0.1, basichi],'Enable','on',...
    'TooltipString', 'Transpose the data matrix.',...
    'Callback', {@buttontransposeRAY, emptybutton, Button, Footnote, AxesD, AxesNMF, AxesAFS, AxesSOL, NMFparameter, NMFinfo, Datainfo, SVDinfo, Polysettings, lcs, usmn, usmf, IPonoff});

Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Load','HorizontalAlignment','center','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 channels-vector "x".'),...
    'Callback',{@buttonloadRAY, emptybutton, Button, Footnote, AxesD, AxesNMF, AxesAFS, AxesSOL, Datainfo, SVDinfo, Polysettings, usmn, usmf, IPonoff, FPonoff, titles, NMFparameter, NMFinfo, lcs});

set(Radiogroup(1),'SelectionChangeFcn', {@buttonselectrotRAY, emptybutton, AxesAFS, roton, rotoff});
set(Radiogroup(2),'SelectionChangeFcn', {@buttonselectIPRAY, fig, emptybutton, AxesAFS, AxesSOL, lcs, roton, rotoff, IPonoff, SegPlot, 1});
set(Radiogroup(3),'SelectionChangeFcn', {@buttonselectIPRAY, fig, emptybutton, AxesAFS, AxesSOL, lcs, roton, rotoff, FPonoff, SegPlot, 2});
set(Radiogroup(4),'SelectionChangeFcn', {@buttonselectlvRAY, fig, emptybutton, Button, AxesAFS, AxesSOL, SegPlot, rotoff, IPonoff, FPonoff, lvText, lvSlider, lcs, usmn, usmf});

set(SegPlot,'Callback', {@buttonPlotSegRAY, fig, emptybutton, Button, AxesAFS, AxesSOL, SegPlot, rotoff, IPonoff, FPonoff, lvText, lvSlider, usmn, usmf, 1, -1, lcs, [0 0 0]});

for i=1:3
    set(lvSlider(i),'Callback', {@buttonlvRAY, fig, emptybutton, Button, AxesAFS, AxesSOL, SegPlot, rotoff, IPonoff, FPonoff, lvText, lvSlider, usmn, usmf, i, lcs});
    set(lvText(2*i),'Callback', {@buttonlvRAY, fig, emptybutton, Button, AxesAFS, AxesSOL, SegPlot, rotoff, IPonoff, FPonoff, lvText, lvSlider, usmn, usmf, 3+i, lcs});
end

onoffButton(Button,1,2:11);

set(gcf,'WindowButtonMotionFcn', {@liveviewRAY, emptybutton, Button, AxesD, AxesNMF, AxesAFS, AxesSOL, roton, rotoff, Radiogroup, usmn, lcs, basichi})

set(gcf,'WindowButtonDownFcn', {@extractaxesRAY, fig, emptybutton, Button, AxesD, AxesNMF, AxesAFS, AxesSOL, lcs, usmn, usmf})
% set(gcf,'WindowButtonUpFcn', {@fcnrotoffRAY, fig, emptybutton, AxesD, AxesNMF, AxesAFS, AxesSOL, roton, rotoff, lcs, usmn, usmf})

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

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