function buttonAFS(hObject, eventdata, parentfig, Empty_Button,Button, Footnote,AFS,LockMode,  AxesAFS, AxesSOL, AFSinfo,SVDinfo,EPSinfo,Polysettings,Plotsettings,usmn, usmf,calcp)
set(usmn,'Value',0);
set(usmf,'Value',1);
set(gcf,'Pointer','Watch');
drawnow;
set(Plotsettings(1),'String',num2str(20));
set(Plotsettings(2),'String',num2str(0.1));
set(Plotsettings(3),'String',num2str(0.1));


hold(AxesSOL,'off');
plot(AxesSOL,1,0,'w');
data = get(Empty_Button,'UserData');

data.FixPoint1_B=[];
data.FixPoint2_B=[];
data.FixPoint3_B=[];
data.FixPoint1_SV=[];
data.FixPoint2_SV=[];
data.FixPoint3_SV=[];

if data.ismatrix == 0 set(Footnote,'String',' Warning, no data has been loaded.','ForegroundColor','red');  set(gcf,'Pointer','arrow');

    return;
end

if data.Sraw(3,3)<10^(-10)
    set(Footnote,'String',' Warning, only two components in this system.','ForegroundColor','red'); set(gcf,'Pointer','arrow');
    return;
end


if data.isafs == 1
    EPSc1=data.EPSc;
    EPSa1=data.EPSa;
    data.EPSc = getsetvar_BKP(EPSinfo(2),0, 1, 0, 0);
    if data.EPSd>=0
        data.EPSa = getsetvar_BKP(EPSinfo(3),0,1,0,0);
    else
            
        data.EPSa = getsetvar_BKP(EPSinfo(3),max(0.000001, -data.EPSd),max(0.2,-10*data.EPSd),0,0);
    end
    if(EPSc1==data.EPSc && EPSa1==data.EPSa)
         set(gcf,'Pointer','arrow');

        return
    else
        data.polygon=0;
    end
end



U=data.Uraw;
S=data.Sraw;
V=data.Vraw;

data.FP_B=[];
data.IP_B=[];
data.segments_B=[];
data.Fbnd_B=[];
data.Tbnd_B=[];

data.FP_SV=[];
data.IP_SV=[];
data.segments_SV=[];
data.Fbnd_SV=[];
data.Tbnd_SV=[];
data.numb_seg=0;

    data.EPSc = getsetvar_BKP(EPSinfo(2),0, 1, 0, 0);
    if data.EPSd>=0
        data.EPSa = getsetvar_BKP(EPSinfo(3),0,1,0,0);
    else
    str2num(get(EPSinfo(3),'String'));    
            
        data.EPSa = getsetvar_BKP(EPSinfo(3),max(0.000001, -data.EPSd),max(0.2,-10*data.EPSd),0,0);
    end
 

set(Empty_Button,'UserData',data);

arc = getsetvar_BKP(Polysettings(1),0.01,1,0.0,0);
stopp = getsetvar_BKP(Polysettings(2), 1.0e-5,1,0,1);
step=50;

if data.Borgen==0
    data.scalBorg=0;
    set(Button(8),'String','swap to RS scal.','TooltipString', sprintf('transform the AFS into the FSV scaling'));
    singv = diag(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');
         set(gcf,'Pointer','arrow');

        return;
    end
    posSV = [];
    for i=2:3
        mi = min(V(:,i));
        if (mi > 0) || (-mi < 1.E-16*max(V(:,i)))
            posSV = [posSV, i];
        end
    end
    
    if isempty(posSV) == 0
        str = 'Warning: matrix D^TD is reducible, positive singular vectors: 1';
        for i=1:length(posSV)
            str = [str, ', ', num2str(posSV(i))];
        end
        set(Footnote,'String',[str, '.'],'ForegroundColor','red');
        
        plot(AxesNMF,1,0,'w');
        plot(AxesAFS,0,0,'w');
        plot(AxesSOL,1,0,'w');
        
        %         onoffButton(Buttons,[],4:16);
         set(gcf,'Pointer','arrow');

        return;
    end
else
    data.scalBorg=1;
    set(Button(8),'String','swap to FSV scal.');
end


posSV = [];
for i=2:3
    mi = min(V(:,i));
    if (mi > 0) || (-mi < 1.E-16*max(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);
     set(gcf,'Pointer','arrow');

    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');
set(Empty_Button,'UserData',data);


tic; 
computeAFS_BKP(Empty_Button,data.Dtrunc,U,S,V,data.EPSa,data.EPSc,arc,step,stopp,data.Borgen,data.polygon,Button,calcp,Footnote,EPSinfo);
toc
set(Footnote,'String',['AFS-computation-time: ' ,num2str(toc), ' seconds'],'ForegroundColor','black');



data = get(Empty_Button,'UserData');
if (size(data.FP_SV,1)==0 && size(data.FP_B,1)==0)
    set(Footnote,'String','FIRPOL does not exist','ForegroundColor','red');
    set(gcf,'Pointer','arrow');
    set(Empty_Button,'UserData',data);
    return;
end

 

if data.numb_seg==0
    data.isafs=0;
    
    hold(AxesAFS,'off');
    plot(AxesAFS,0,0,'w');
    hold(AxesAFS,'on');
    axes(AxesAFS);
    if data.scalBorg==1
        plot(data.FP_B([1:end 1],1),data.FP_B([1:end 1],2),'Color',[1 1 1]*0.8);
        plot(data.IP_B([1:end 1],1),data.IP_B([1:end 1],2),'Color',[1 1 1]*0.8);
    else
        
        plot(data.FP_SV([1:end 1],1),data.FP_SV([1:end 1],2),'Color',[1 1 1]*0.8);
        plot(data.IP_SV([1:end 1],1),data.IP_SV([1:end 1],2),'Color',[1 1 1]*0.8);
    end
    str = ['No AFS computed.'];
    set(Footnote,'String',str,'ForegroundColor','red');
    set(gcf,'Pointer','arrow');
    set(hObject,'Enable','on');
     set(Empty_Button,'UserData',data);
   return; 
end
data.isafs=1;
    

set(hObject,'Enable','on');



data.isExpert1=0;
    data.isExpert2=0;

        data.AFSL_B=[];
        data.AFSL2_B=[];

        data.AFSL_SV=[];
        data.AFSL2_SV=[];

    data.numb_segmentsL2=[];
    data.numb_segmentsL2=0;
    data.numb_segmentsL=[];
    data.numb_segmentsL=0;
    
    set(Empty_Button,'UserData',data);
    
changenorm_BKP(Empty_Button, AxesAFS,AxesSOL);
plotAFS_BKP(Empty_Button,AxesAFS);



if data.numb_seg==1
    onoffButton_BKP(AFS,[1],[2:3]);
    onoffButton_BKP(LockMode,[2],[3:5]);
elseif data.numb_seg==3
    onoffButton_BKP(AFS,[1:3],[]);
    onoffButton_BKP(LockMode,[2],[3:5]);
else
    onoffButton_BKP(AFS,[],[1:3]);
    onoffButton_BKP(LockMode,[],[2:5]);
end

set(AFSinfo(3),'String',['pts. inner bnd.: ',num2str(size(data.Tbnd_B,1))]);
if data.numb_seg>1
    set(AFSinfo(2),'String',['pts. outer bnd. : ',num2str(size(data.Fbnd_B,1))]);
else
    set(AFSinfo(2),'String',['pts. outer bnd.: ',num2str(0)]);
end

 set(gcf,'Pointer','arrow');


