function buttontransformAFS(hObject, eventdata, parentfig, Empty_Button, Footnote, AxesAFS,AxesSOL, Plotsettings,part, usmn, usmf)

set(usmn,'Value',0);
set(usmf,'Value',1);
data = get(Empty_Button,'UserData');


if (isfield(data,'ismatrix')*isfield(data,'isafs') == 0) || (data.ismatrix*data.isafs == 0)
    if data.ismatrix == 0 set(Footnote,'String',' Warning, no data has been loaded.','ForegroundColor','red');return;end
    if data.isafs == 0 set(Footnote,'String',' Warning, no AFS has been computed.','ForegroundColor','red');return;end
end



bndpts = getsetvar_BKP(Plotsettings(1), 1, 200, 1, 1);

dx=1.0e-6;
dy=1.0e-6;


if data.Borgen==1
    FP=data.FP_B;
    seg=data.segments_B;
else
    FP=data.FP_SV;
    seg=data.segments_SV;
end

if data.numb_seg==1
    mi=min(FP(:,1));
    ma=max(FP(:,1));
    if (ma-mi)/dx>bndpts/2
        dx=(ma-mi)*2/bndpts;
    end
    mi=min(FP(:,2));
    ma=max(FP(:,2));
    if (ma-mi)/dy>bndpts/2
        dy=(ma-mi)*2/bndpts;
    end
else

    for i=1:data.numb_seg
        mi=min(seg{i}(:,1));
        ma=max(seg{i}(:,1));
        if (ma-mi)/dx>bndpts/2
            dx=(ma-mi)*2/bndpts;
        end
        mi=min(seg{i}(:,2));
        ma=max(seg{i}(:,2));
        if (ma-mi)/dy>bndpts/2
            dy=(ma-mi)*2/bndpts;
        end
    end
end

dx=ceil(dx*1000)/1000;
dy=ceil(dy*1000)/1000;


hx     = getsetvar_BKP(Plotsettings(2), 5.E-5, dx, 0, 1);
hy     = getsetvar_BKP(Plotsettings(3), 5.E-5, dy, 0, 1);



Sol = transformAFS_BKP(data,part,data.numb_seg,bndpts,hx,hy);
plotAFS_BKP(Empty_Button,AxesAFS)

 axes(AxesAFS);


if data.Borgen==data.scalBorg
    if data.numb_seg==1
        plot(Sol.T(:,1),Sol.T(:,2),'+k');
    elseif part==1
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[0 0 1]);
    elseif part==2
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[0 0.5 0]);
    else
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[1 0 0]);
    end
elseif data.Borgen==1
    V1=data.V_scal;
    VTV = V1'*data.Vraw;
    s1=data.sum_v1;
    s2=data.sum_v2;
    s3=data.sum_v3;
    
    [m,n] = size(Sol.T);
    for i=1:m
        t(2:3)=Sol.T(i,1:2);
        t(1)=(1-t(2)*s2-t(3)*s3)/s1;
        s=t*VTV;
        s=s/s(1);
        Sol.T(i,1:2)=s(2:3);
    end

    if data.numb_seg==1
        plot(Sol.T(:,1),Sol.T(:,2),'+k');
    elseif part==1
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[0 0 1]);
    elseif part==2
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[0 0.5 0]);
    else
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[1 0 0]);
    end
    
    
else
    [m,n]=size(Sol.T);
    [h,n]=size(data.Vraw);
    e=ones(h,1);
    V1=data.V_scal;
    for i=1:m
        t1=[1,Sol.T(i,1),Sol.T(i,2)];
       
        h=t1*data.Vraw(:,1:3)';
        s=h*e;
 
        t2=h*V1/s;
        Sol.T(i,1:2)=t2(2:3);
    end

    if data.numb_seg==1
        plot(Sol.T(:,1),Sol.T(:,2),'+k');
    elseif part==1
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[0 0 1]);
    elseif part==2
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[0 0.5 0]);
    else
        plot(Sol.T(:,1),Sol.T(:,2),'+', 'Color',[1 0 0]);
    end
    
end

    
    xlabel(AxesSOL,'channel / time');
        
        xli = [min(data.x), max(data.x)];
        if data.Borgen==1
            yli = 1.1*[min([0, data.mima_B(1,3), data.mima_B(2,3)]), max(data.mima_B(1,4), data.mima_B(2,4))];
        else
             yli = 1.1*[min([0, data.mima_SV(1,3), data.mima_SV(2,3)]), max(data.mima_SV(1,4), data.mima_SV(2,4))];
        end
        
        posX = xli(1)+0.65*(xli(2)-xli(1));
        posY = yli(1)+0.9*(yli(2)-yli(1));
        
        set(AxesSOL,'ylim',yli,'xlim',xli,'YTick',[0]);

if data.numb_seg==1
    plot(AxesSOL,data.x,Sol.A,'Color',[1 1 1]*0.75);
elseif part==1
    plot(AxesSOL,data.x,Sol.A,'Color',[0 0 1]);
elseif part==2
    plot(AxesSOL,data.x,Sol.A,'Color',[0 0.5 0]);
else
    plot(AxesSOL,data.x,Sol.A,'Color',[1 0 0]);
end





