function computeAFS(Empty_Button,D,U,S,V,epsA,epsC,arc_step,step,stopp,borg,polygon,Button,calcp,Footnote,EPSinfo)
data = get(Empty_Button,'UserData');
set(gcf,'Pointer','Watch');

actpwd = pwd;
cd(calcp);


if data.polygon==0 || data.isafs==0

    Fbnd=[];
    Tbnd=[];
    numb_seg=0;




%compute transformation matrix T of the initial factorization
    if borg==1
        IP=INNPOL_BKP(data.D_scal,data.V_scal(:,1)',data.V_scal(:,2)',data.V_scal(:,3)',borg,epsA,data.D0);
        [FP,IP,onFP]=FIRPOL2_BKP(data.V_scal(:,1),data.V_scal(:,2),data.V_scal(:,3),epsA,borg,IP);
    else
        IP=INNPOL_BKP(data.Dtrunc,V(:,1)',V(:,2)',V(:,3)',borg,epsA,data.D0);
        [FP,IP,onFP]=FIRPOL2_BKP(V(:,1),V(:,2),V(:,3),epsA,borg,IP);
    end
  

    data.on=size(onFP,1);

    
    data.on=size(onFP,1);
   if data.on==0
       data.onFP=[0 0];
       data.on=1;
   end
    
   
    if data.Borgen==1
        data.FP_B=FP;
        data.IP_B=IP;
    else
        data.FP_SV=FP;
        data.IP_SV=IP;
    end
    [im,in]=size(IP);
    [fm,fn]=size(FP);
    if fm==0
        cd(actpwd);

        set(Empty_Button,'UserData',data);
        return;
    end
        
    
    
    data.epsC=epsC;
    data.arc_step=arc_step;
    data.step=step;
    data.stopp=stopp;
   
    allg=[fm; im;data.on; epsC; arc_step;stopp;0;0;0];
    T0=[0 0; 0 0; 0 0];
    
    
    dlmwrite('subfcnsBKP/wrap/IP.txt',IP,'precision','%15.15e','delimiter',' ');
    dlmwrite('subfcnsBKP/wrap/FP.txt',FP,'precision','%15.15e','delimiter',' ');
    dlmwrite('subfcnsBKP/wrap/onFP.txt',onFP,'delimiter',' ');
    dlmwrite('subfcnsBKP/wrap/allg.txt',allg,'delimiter',' ');
    dlmwrite('subfcnsBKP/wrap/T0.txt',T0,'delimiter',' ');
    Lock=[0 0;0 0];
    dlmwrite('subfcnsBKP/wrap/LockMode.txt', Lock,'delimiter',' ');
    data.polygon=1;
end

arch = computer('arch');

pause(0.5);
if (strcmp(arch,'maci64') == 1) || (strcmp(arch,'maca64') == 1)
    system('./subfcnsBKP/Borgen_mac64.exe ');
elseif strcmp(arch,'win32') == 1
    system('./subfcnsBKP/Borgen_WINDOWS32.exe ');
elseif strcmp(arch,'win64') == 1
    system('./subfcnsBKP/Borgen_WINDOWS32.exe ');
elseif strcmp(arch,'glnx86') == 1
    system('./subfcnsBKP/Borgen_L32.exe ');
elseif strcmp(arch,'glnxa64') == 1
    system('./subfcnsBKP/Borgen_L64.exe ');
else
    fprintf(2,'No executable version for this type of system.\n');
    GenInfo = -2;
    AFS = [];
    totalpoin = 0;
    calls = 0;
    bisec = 0;
    parts = 0;
    dimP = 0;
    lenP = 0;
    LENP = 0;
    valid = [];
    lines = [];
    tim = 0;
    data.mima = 0;
    cd(actpwd);
    
    set(Empty_Button,'UserData',data);
    return;
end

AFScomp=dlmread('subfcnsBKP/wrap/AFScomp.txt');

if AFScomp(1,1)~=0 && AFScomp(1,2)~=0

    if data.Borgen==1
        data.AFS_B=dlmread('subfcnsBKP/wrap/AFS.txt');
    else
        data.AFS_SV=dlmread('subfcnsBKP/wrap/AFS.txt');
    end
    Tbnd=dlmread('subfcnsBKP/wrap/AFS.txt');
    [data.count,h]=size(Tbnd);


    Fbnd=dlmread('subfcnsBKP/wrap/AFSout.txt');
    [data.out,h]=size(Fbnd);
else
    set(Footnote,'String',' No feasible factorization found.','ForegroundColor','red');
    data.AFS_B=[];
    data.AFS_SV=[];
    Tbnd=[];
    Fbnd=[];
    cd(actpwd);
    
    set(Empty_Button,'UserData',data);
    return;
end


[numb_seg,h]=size(AFScomp);
if numb_seg==1 && AFScomp(1,1)==0
    Tbnd=[];
    Fbnd=[];
    segments=[];
    numb_seg=0;
else
    
    segments=[];
    if numb_seg>1
        AFScomp(2:numb_seg+1,:)=AFScomp(1:numb_seg,:);
        AFScomp(1,1)=0;
        AFScomp(1,2)=0;
        for i=1:numb_seg
            n=AFScomp(i+1,1)-AFScomp(i,1);
            segments{i}(1:n,:)=Tbnd(AFScomp(i,1)+1:AFScomp(i+1,1),:);
            m=AFScomp(i+1,2)-AFScomp(i,2);
            segments{i}(n+1:n+m,1:2)=Fbnd(AFScomp(i+1,2):-1:AFScomp(i,2)+1,1:2);
            
        end
    elseif numb_seg==1
        segments{1}=Tbnd;
        
    end
end
data.numb_seg=numb_seg;

if numb_seg>0
    onoffButton_BKP(Button,4:8,[]);
end



data.mima = zeros(3,6);
data.sum_v1=ones(1,size(data.V_scal,1))*data.V_scal(:,1);
data.sum_v2=ones(1,size(data.V_scal,1))*data.V_scal(:,2);
data.sum_v3=ones(1,size(data.V_scal,1))*data.V_scal(:,3);


 if numb_seg>1
%      
            for i=1:numb_seg
                    if borg==0
                        data.mima(i,:) = [min(segments{i}(:,1)), max(segments{i}(:,1)), min(segments{i}(:,2)), max(segments{i}(:,2)),...
                        min(min([ones(size(segments{i},1),1) segments{i}]*V(:,1:3)')), max(max([ones(size(segments{i},1),1) segments{i}]*V(:,1:3)'))];
                    else
                        a=zeros(size(segments{i},1),1);
                        for j=1:size(segments{i},1);
                            a(j)=(1-data.sum_v2*segments{i}(j,1)-data.sum_v3*segments{i}(j,2))/data.sum_v1;
                        end
                        
                        data.mima(i,:) = [min(segments{i}(:,1)), max(segments{i}(:,1)), min(segments{i}(:,2)), max(segments{i}(:,2)),...
                        min(min([a segments{i}]*data.V_scal(:,1:3)')), max(max([a segments{i}]*data.V_scal(:,1:3)'))];

                    end
            end
 end
 
 if numb_seg==1
     if borg==0
         data.mima(1,:) = [min(segments{1}(:,1)), max(segments{1}(:,1)), min(segments{1}(:,2)), max(segments{1}(:,2)),...
             min(min([ones(size(segments{1},1),1) segments{1}]*V(:,1:3)')), max(max([ones(size(segments{1},1),1) segments{1}]*V(:,1:3)'))];
     else
         a=zeros(size(segments{1},1),1);
         for j=1:size(segments{1},1);
             a(j)=(1-data.sum_v2*segments{1}(j,1)-data.sum_v3*segments{1}(j,2))/data.sum_v1;
         end
         
         data.mima(1,:) = [min(segments{1}(:,1)), max(segments{1}(:,1)), min(segments{1}(:,2)), max(segments{1}(:,2)),...
             min(min([a segments{1}]*data.V_scal(:,1:3)')), max(max([a segments{1}]*data.V_scal(:,1:3)'))];     
     end
     
     if borg==0
         data.mima(1,:) = [min(FP(:,1)), max(FP(:,1)), min(FP(:,2)), max(FP(:,2)),...
             min(min([ones(size(FP,1),1) FP]*V(:,1:3)')), max(max([ones(size(FP,1),1) FP]*V(:,1:3)'))];
     else
         a=zeros(size(FP,1),1);
         for j=1:size(FP,1);
             a(j)=(1-data.sum_v2*FP(j,1)-data.sum_v3*FP(j,2))/data.sum_v1;
         end
         
         data.mima(1,:) = [min(FP(:,1)), max(FP(:,1)), min(FP(:,2)), max(FP(:,2)),...
             min(min([a FP]*data.V_scal(:,1:3)')), max(max([a FP]*data.V_scal(:,1:3)'))];     
     end
     
 end
 
 if data.Borgen==1
     data.mima_B=data.mima;
 else
     data.mima_SV=data.mima;
 end
     
     
if data.Borgen==1
    data.Fbnd_B=Fbnd(:,1:2);
    data.Tbnd_B=Tbnd;
    data.segments_B=segments;
    data.mima_B=data.mima;
else
    data.Fbnd_SV=Fbnd(:,1:2);
    data.Tbnd_SV=Tbnd;
    data.segments_SV=segments;
    data.mima_SV=data.mima;
end

data.numb_seg=numb_seg;
data.Polygon=polygon;
cd(actpwd);

set(Empty_Button,'UserData',data);


