function buttoncomputeAllAPGA(hObject, eventdata, Empty_Button, Buttons, RegSlider, RegText, AxesSOL, AxesAOM, calcp, usmn, usmf, AxesD, Recondition, lcs, AxesSVD, LCS, rbplotsvd)
data = get(Empty_Button,'UserData');

data.isred = 0;
data.issol = 0;
data.islive = 0;
data.livet = [];
set(usmn,'Value',0);
set(usmf,'Value',1);
SliderOnOffPGA(RegSlider, RegText, data, 0);
set(Empty_Button,'UserData',data);

if (isfield(data,'isdata')*isfield(data,'issvd')*isfield(data,'isnovctrs') == 1) && (data.isdata*data.issvd*data.isnovctrs == 1)
    [k,n] = size(data.D);
    ifir = -1;
    ilas = 0;                %ilas + 1 = windowsize
    isgs = data.isgivenspec;
    
    givenadaptedis = data.givenadaptedis;
    
    if isfield(data,'noc') == 1
        noc = data.noc;
        A = [];
        for i=1:data.noc
            A = [A; data.SOL(i).a];
        end
    else
        noc = 0;
        A = 0;
    end
    
    z   = data.novctrs;
    L   = data.U*data.S(:,1:z);
    S   = diag(data.S(1:z,1:z));
    R   = data.V(:,1:z)';
    
    amin = -getsetvar(RegText(63), 0, 0.1, 0, 2);
    
    nw = 6;
    for i=1:nw
        W(i) = get(RegSlider(3+i), 'Value');
        if (i>1) && (abs(W(i)-get(RegSlider(3+i), 'Min')) < 1.E-14)
            W(i) = -1;
        end
    end
    
    isred = 0;
    for i=2:z
        mi = min(data.V(:,i));
        if (mi > 0) || (-mi < 1.E-16*max(data.V(:,i)))
            isred = 1;
            break;
        end
    end
    
    if isred == 0
        inot = setdiff(1:n, ifir:ilas);
        t0 = -(R(2:z,inot)')\(R(1,inot)');
    else
        t0 = 0.1*ones(z,1);
    end
    
    actpwd = pwd;
    cd(calcp);

    dlmwrite('wrap/allg.txt',[k; n; z; nw; ifir; ilas; isgs; isred; noc; givenadaptedis],'precision','%d');
    dlmwrite('wrap/allg.txt',amin,'-append','precision','%e');
    
    dlmwrite('wrap/L.txt',L,'precision','%15.15e','delimiter',' ');
    dlmwrite('wrap/R.txt',R,'precision','%15.15e','delimiter',' ');
    dlmwrite('wrap/S.txt',S,'precision','%15.15e','delimiter',' ');
    dlmwrite('wrap/W.txt',W,'precision','%15.15e','delimiter',' ');
    dlmwrite('wrap/t0.txt',t0,'precision','%15.15e','delimiter',' ');
    dlmwrite('wrap/A.txt',A,'precision','%15.15e','delimiter',' ');
    dlmwrite('wrap/tim.txt',0,'precision','%d');
    
    if isgs
        if givenadaptedis == 1
            dlmwrite('wrap/givena.txt',data.givenadaptedI','precision','%d');
            dlmwrite('wrap/givena.txt',data.givena,'-append','precision','%e');
        else
            givena = data.givena;
            dlmwrite('wrap/givena.txt',givena','precision','%15.15e','delimiter',' ');
        end 
    end

    arch = computer('arch');
    
    fprintf(' C routine (PeakGroupAnalysis) in progress ... (press CTRL + C to cancel) ... ');
    set(hObject, 'Enable','off');
    
    set(gcf,'Pointer','Watch');
    pause(0.5);
    opt = 4;
    
    if (strcmp(arch,'maci64') == 1) || (strcmp(arch,'maca64') == 1)
        % system(['./PeakGroupAnalysisM64.exe ',num2str(opt),' 0']);
        system(['./PeakGroupAnalysisFCSM64.exe ',num2str(opt),' 0']);
    elseif (strcmp(arch,'win64') == 1) || (strcmp(arch,'win32') == 1)
        % system(['PeakGroupAnalysisW32.exe ',num2str(opt),' 0']);
        system(['./PeakGroupAnalysisFCS_W64.exe ',num2str(opt),' 0']);
    elseif strcmp(arch,'glnx86') == 1
        system(['./PeakGroupAnalysisU32.exe ',num2str(opt),' 0']);
    elseif strcmp(arch,'glnxa64') == 1
        % system(['./PeakGroupAnalysisU64.exe ',num2str(opt),' 0']);
        system(['./PeakGroupAnalysisFCS_U64.exe ',num2str(opt),' 0']);
    else
        fprintf(2,'No executable version for this type of system.\n');
        cd(actpwd);
        return;
    end
    
    set(gcf,'Pointer','arrow');
    set(hObject, 'Enable','on');
    
    tim = [];
    tim = load('wrap/tim.txt');
    
    if tim(1) < 1
        fprintf('computation canceled.\n');
        return;
    else
        tim = tim(2);
    end
    
    data.timeFAC = data.timeFAC+tim;

    fprintf('ready, time: %2.2f s.\n',tim);
    
    results = load('wrap/results.txt');
    nor = length(results)/(z);   %number of results
    ERR = zeros(nor,1);
    T = zeros(nor,z-1);
    for i=1:nor
        T(i,:) = results((i-1)*(z)+1:(i-1)*(z)+z-1);
        ERR(i) = results(i*z);
    end
    a = [ones(nor,1) T]*R;

    mine = islocalmin(ERR);
    mine = find(mine);
    [~,mini] = sort(ERR(mine));
    

    thr = ERR(mine(mini(min(z,length(mini)))))*10;
    
    ME = islocalmin(ERR);
    ME(1) = 0;
    ME(end) = 0;
    ME = find(ME);
    ME1 = sort(ERR(ME));
    if length(ME1)>z-1
        thr = 10*ME1(z);
    else
        thr = ME1(end);
    end


    ME = islocalmin(min(thr,ERR));
    ME(1) = 0;
    ME(end) = 0;
    ME = find(ME);
    data.ainter = a(ME,:)./max(a(ME,:),[],2);
    data.tinter = T(ME,:);
    data.yinter = zeros(length(ME),6);S
    data.W = kron(ones(length(ME),1),W);
    data.final = ME;
    % % save('Err.mat','ERR','ME','a')
    for ijk=1:length(ME)
        % autodetect{ijk} = detectallpeaks(data.x,a,0,ifir,ilas);
        % autodetect{ijk} = ME(ijk);
        autodetect{ijk} = [];
    end
%% calculate number of returned peaks

h = finalcheckfcs(hObject, eventdata, Empty_Button, Buttons, data, lcs, autodetect,a,ERR);
    uiwait(h);

    data = get(Empty_Button,'UserData');
    if data.isautosol == 0
        return
    end
    
    mid = min(0,min(min(data.D)));
    mad = max(max(data.D))*1.1;
    nc = size(lcs,1);
    lgntxt = {};
    final = data.final;
    for i=1:length(data.final)
        plot(AxesSOL, data.x(final(i))*[1 1], [mid mad], 'color',lcs(mod(i-1,nc)+1,:),'Linewidth',1.5);
        hold(AxesSOL,'on');
        lgntxt{i} = num2str(round(10*data.x(data.final(i)))/10);
    end
    for i=1:length(data.final)
        plot(AxesSOL, data.x, data.ainter(i,:), 'color',lcs(mod(i-1,nc)+1,:), 'Linewidth',2);
    end
    hold(AxesSOL,'off');
    axis(AxesSOL,'tight');
    set(AxesSOL,'ylim',[mid mad],'ytick',[]);
    xlabel(AxesSOL,'channel');
    lgn = legend(lgntxt);
    set(lgn,'fontsize',12);
    
    if size(data.ainter,1)>0
        plot(AxesAOM(1), data.x, data.ainter, 'k', 'Linewidth',2);
        axis(AxesAOM(1),'tight');
        yl = get(AxesAOM(1),'ylim');
        yl = [min(0,yl(1)), yl(2)*1.1];
        set(AxesAOM(1),'ylim',yl, 'XTick', [], 'YTick', []);
    end
    onoffButton(Buttons,[12 13:14 16],[5 6 17]);
    set(Buttons(6),'BackgroundColor',0.94*[1 1 1]);
    set(Buttons(17),'BackgroundColor',0.94*[1 1 1]);

    data.new = length(data.final);
    data.isautosol = 1;
    
    data.isautodetect = 0;
    set(Empty_Button,'UserData',data);
    
    buttonacceptcurrentaPGA(hObject, eventdata, Empty_Button, Buttons, AxesD, AxesSVD, AxesSOL, AxesAOM, lcs, LCS, rbplotsvd, Recondition, RegSlider, RegText, usmn, usmf);

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