function buttoncomputeAPGA(hObject, eventdata, Empty_Button, Buttons, RegSlider, RegText, AxesSOL, AxesAOM, calcp, usmn, usmf)
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')*isfield(data,'isbd') == 1) && (data.isdata*data.issvd*data.isnovctrs*data.isbd == 1)
    
    [k,n] = size(data.D);
    ifir = data.ifir;
    ilas = data.ilas;
    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);
    
    % ifir = -1
    % ilas = 10

    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 = 2;
    
    if (strcmp(arch,'maci64') == 1) || (strcmp(arch,'maca64') == 1)
        system(['./PeakGroupAnalysisM64.exe ',num2str(opt),' 0']);
    elseif (strcmp(arch,'win64') == 1) || (strcmp(arch,'win32') == 1)
        system(['PeakGroupAnalysisW32.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(['./PeakGroupAnalysisFCSU64.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');
    t = results(1:z)';
    y = results(z+1:z+nw);
    a = t*R;
    vs = R(:,ifir:ilas)*a(ifir:ilas)'/(a(ifir:ilas)*a(ifir:ilas)');
    
    cd(actpwd);
    
    for i=1:nw
        set(RegText(43+i), 'String', [num2str(100*y(i),3) '%']);
    end
    
    data.W = W;
    data.y = 100*y;
    
    data.t = t;
    data.a = a;
    data.c = L*vs;
    data.isred = isred;
    
    
    autodetect = detectallpeaks(data.x,data.a,1,ifir,ilas);
    if data.isamp
        plot(AxesSOL, data.x, data.a/max(data.a), 'r--', 'Linewidth',1);
        hold(AxesSOL, 'on');
        
        data.a = data.a*diag(1./data.ampl);
        data.a = data.a/max(data.a);
        
        plot(AxesSOL, data.x, data.a, 'k', 'Linewidth',2);
        plot(AxesSOL, data.x(ifir:ilas), data.a(ifir:ilas), 'k','Linewidth',5,'markersize',12);
        
        legend(AxesSOL, 'amplified data', 'regular data');
        
    elseif isgs && get(RegSlider(8),'Value') > 0
        if givenadaptedis == 1
            plot(AxesSOL, data.x(data.givenadaptedI(1):data.givenadaptedI(2)), data.givena/max(data.givena), 'g--', 'Linewidth',1);
        else
            plot(AxesSOL, data.x, data.givena/max(data.givena), 'g--', 'Linewidth',1);
        end
        hold(AxesSOL, 'on');
        
        data.a = data.a/max(data.a);
        plot(AxesSOL, data.x, data.a, 'k', 'Linewidth',2);
        plot(AxesSOL, data.x(ifir:ilas), data.a(ifir:ilas), 'k','Linewidth',5,'markersize',12);
        
        legend(AxesSOL, 'given spectrum', 'regular data');
        
    else
        data.a = data.a/max(data.a);
        plot(AxesSOL, data.x, data.a, 'k', 'Linewidth',2);
        hold (AxesSOL,'on')
        plot(AxesSOL, data.x(ifir:ilas), data.a(ifir:ilas), 'k','Linewidth',5,'markersize',12);
        
    end
    for l=1:length(autodetect)
        text(AxesSOL,data.x(autodetect(l)),data.a(autodetect(l)),num2str(round(data.x(autodetect(l)))));
    end
    [tey,idmax] = max(data.a(ifir:ilas));
    tex = data.x(ifir+idmax)+(max(data.x)-min(data.x))/100;
    text(AxesSOL,tex,tey,num2str(round(tex)));
    hold(AxesSOL, 'off');

    axis(AxesSOL,'tight');
    yl = get(AxesSOL,'ylim');
    yl = [min(0,yl(1)), yl(2)*1.1];
    set(AxesSOL,'ylim',yl);
    xlabel(AxesSOL,'channel');
    
    plot(AxesAOM(1), data.x, data.a, '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', []);
    
    onoffButton(Buttons,[5:6 12 13:14 16 19],[]);
    
    set(hObject,'BackgroundColor',0.94*[1 1 1]);
    set(Buttons(6),'BackgroundColor',[0.8500 0.3250 0.0980]);
    
    data.issol = 1;
end
set(Empty_Button,'UserData',data);
