function buttonAFS(hObject, eventdata, parentfig, Empty_Button, Buttons, Footnote, upol, uinv, Polysettings, AxesAFS, AxesSOL, AFSinfo, lcs, LCS, usmn, usmf)
set(usmn,'Value',0);
set(usmf,'Value',1);
plot(AxesSOL,1,0,'w');
data = get(Empty_Button,'UserData');
if (isfield(data,'ismatrix')*isfield(data,'isnmf') == 0) || (data.ismatrix*data.isnmf == 0)
    if data.ismatrix == 0 set(Footnote,'String',' Warning, no data has been loaded.','ForegroundColor','red');return;end
    if data.isnmf == 0 set(Footnote,'String',' Warning, no NMF has been computed.','ForegroundColor','red');return;end
end

data.isExpert1 = 0;
data.isExpert2 = 0;
data.isLastClickLockMode = 0;
data.isimport = 0;
data.import = [];
onoffButton(Buttons,[], [17:19]);

MaxLang = getsetvar(Polysettings(5), 3, 20000, 1, 0);
MaxFunC = getsetvar(Polysettings(4), 30, 100000, 1, 0);
epsFun = 1.e-10;
epsKante = getsetvar(Polysettings(3), 1.E-8, 1.E-1, 0, 1);
epsRand = getsetvar(Polysettings(2), 1.E-8, 1.E-1, 0, 1);
if data.s == 2
    mini = min(-min(data.V(:,2))/max(data.V(:,2)), -min(data.U(:,2))/max(data.U(:,2)));
    noiseC = -getsetvar(Polysettings(1), data.miminmf, mini*0.99, 0, 0);
else
    mimi = max(3E-2, 2*data.miminmf);
    noiseC = -getsetvar(Polysettings(1), data.miminmf, mimi, 0, 0);
end
noiseA = noiseC;

singv = diag(data.S);
if singv(2)/singv(1)-1 > -1.E-15
    str = ['No NMF computed: matrix D^TD reducible, ',char(963),'(1)/',char(963),'(2)-1 = ', num2str(singv(2)/singv(1)-1,'%3.3e'),'.'];
    set(Footnote,'String',str,'ForegroundColor','red');
    
    plot(AxesAFS,0,0,'w');
    plot(AxesSOL,1,0,'w');
    
    onoffButton(Buttons,[],8:16);
    return;
end
posSV = [];
for i=2:data.s
    mi = min(data.V(:,i));
    if (mi > 0) || (-mi < 1.E-16*max(data.V(:,i)))
        posSV = [posSV, i];
    end
end

if isempty(posSV) == 0
    str = 'Warning: matrix D^TD reducable, positiv singular vectors: 1';
    for i=1:length(posSV)
        str = [str, ', ', num2str(posSV(i))];
    end
    set(Footnote,'String',[str, '.'],'ForegroundColor','red');
    
    plot(AxesAFS,0,0,'w');
    plot(AxesSOL,1,0,'w');
    
    onoffButton(Buttons,[],8:16);
    return;
end

set(Footnote,'String',' C routine in progress ... (press CTRL + C in the command window to cancel) ...','ForegroundColor','black');
fprintf(' C routine (AFS) in progress ... (press CTRL + C to cancel) ... ');
set(hObject,'Enable','off');
[AFS,totalpoin,calls,bisec,tim,parts,dimP,lenP,LENP,valid,lines, mima,GenInfo,switchpolinv] = computeAFS(MaxLang, MaxFunC, epsFun, epsKante, epsRand, noiseC,...
    noiseA, data.s, data.U, data.S, data.V, data.InitT, 3+get(upol,'Value'), data.calcp, uinv);
set(hObject,'Enable','on');

if GenInfo == -3
    fprintf('computation canceled.\n');
    set(Footnote,'String','AFS computation canceled.','ForegroundColor','red');
    return;
end

fprintf('ready, time: %2.2f s.\n',tim);

if data.s == 3 && GenInfo(1,1) == -2
    set(Footnote,'String',['Warning: Maximal number of funcalls (',num2str(calls) ,') reached.'],'ForegroundColor','red');
    return;
end

if(data.s == 2 && GenInfo(1,1) <= 0)
    set(Footnote,'String',['Warning: AFS not computed.'],'ForegroundColor','red');
    return;
end

data.AFS = AFS;
data.parts = parts;
data.lines = lines;
data.dimP = dimP;
data.lenP = lenP;
data.LENP = LENP;
data.valid = valid;
data.mima = mima;
data.GenInfo = GenInfo;
data.isafs = 1;

plotAFS(parentfig, data, AxesAFS, AxesSOL, lcs, LCS);

if data.s == 2
    set(Footnote,'String',['AFS computation-time:  ',num2str(tim),' s.'],'ForegroundColor','black');
    set(AFSinfo(1),'String',[' edges:  ',num2str(totalpoin)]);
    set(AFSinfo(2),'String',[' funcalls:  ',num2str(calls)]);
    set(AFSinfo(3),'String',[' biseccalls:  ',num2str(bisec)]);
    
    onoffButton(Buttons,[8 9 11 12 19], [10 13:16]);
    
else
    if GenInfo(1,2) == -2
        set(Footnote,'String',['AFS computation-time:  ',num2str(tim),' s. Warning: Maximal number of funcalls (',num2str(calls) ,') reached.'],...
            'ForegroundColor','red');
    elseif switchpolinv == 0
        set(Footnote,'String',['AFS computation-time:  ',num2str(tim),' s.'],'ForegroundColor','black');
    else
        set(Footnote,'String',['WARNING: switched to Inverse polygon inflation. AFS computation-time:  ',num2str(tim),' s.'],'ForegroundColor','black');
    end

    set(AFSinfo(1),'String',[' edges:  ',num2str(totalpoin)]);
    set(AFSinfo(2),'String',[' funcalls:  ',num2str(calls)]);
    set(AFSinfo(3),'String',[' biseccalls:  ',num2str(bisec)]);

    if parts == -1
        onoffButton(Buttons,[],[8 9 10 13:17 19],18);
    elseif parts == 1
        onoffButton(Buttons,[8 11 12 17 19],[9 10 13:16 18]);
    elseif parts >= 3
        off = [];
        for i=1:3
            if valid(i) == 0
                off = [off, i+7];
            end
        end
        onoffButton(Buttons,setdiff([8 9 10 11 12 17 19],off), [off 13:16 18]);
    end

    if get(upol,'Value') == 1
        nval = [];
        for i=1:3
            if valid(i) == 0
                nval = [nval i];
            end
        end
        if length(nval) > 0
            nstr = num2str(nval(1));
            for i=2:length(nval)
                nstr = [nstr, ', ' num2str(nval(i))];
            end;
            set(Footnote,'String',['AFS computation-time:  ',num2str(tim),' s, no valid startpt. for comp. ',nstr,'.'],'ForegroundColor','red');
        end
    else
        if parts == 0
            set(Footnote,'String',['AFS computation-time:  ',num2str(tim),' s, empty AFS ... in process.'],'ForegroundColor','red');
        elseif parts == -1
            set(Footnote,'String',['AFS computation failed: less than 6 intersections. Used time:  ',num2str(tim),' s'],'ForegroundColor','red');
            data.isafs = 0;
        elseif parts == -3
            set(Footnote,'String',['AFS computation failed: less than 6 intersections. Used time:  ',num2str(tim),' s'],'ForegroundColor','red');
            data.isafs = 0;
        end
    end
end

set(Empty_Button,'UserData',data);
