function buttonsavePGA(hObject, eventdata, Empty_Button, Buttons, kind, RegSlider, RegText, usmn, usmf, version)
data = get(Empty_Button,'UserData');

data.islive = 0;

set(usmn,'Value',0);
set(usmf,'Value',1);
SliderOnOffPGA(RegSlider, RegText, data, 0);
set(Empty_Button,'UserData',data);

if kind == 1
    if (isfield(data,'issol') == 1) && (data.issol == 1)
        x = data.x;
        currenta = data.a;
        currentc = data.c;
        currentxbd = data.xbd;
        currentIbd = [data.ifir, data.ilas];
        currentgamma = max(0, data.W);
        currentexposure = data.y;
        currentnoz = data.novctrs;
        uisave({'x','currenta','currentc','currentxbd','currentIbd','currentgamma','currentexposure','currentnoz'},[data.PathName,'results_facpack_PGA_',data.FileName]);
    end
elseif kind ==2
    if (isfield(data,'isSOL') == 1) && (data.isSOL == 1)
        x = data.x;
        for i=1:data.noc
            a(i,:) = data.SOL(i).a;
            Clocal(:,i) = data.SOL(i).c;
            xbd(i,:) = data.SOL(i).xbd;
            Ibd(i,:) = [data.SOL(i).ifir, data.SOL(i).ilas];
            gamma(i,:) = max(0, data.SOL(i).W);
            exposure(i,:) = data.SOL(i).y;
            noz(i) = data.SOL(i).novctrs;
        end
        uisave({'x','a','Clocal','xbd','Ibd','gamma','exposure','noz'},[data.PathName,'results_facpack_PGA_',data.FileName]);
    end
elseif kind >= 3
    ok = [0 0 0];
    if (isfield(data,'issol') == 1) && (data.issol == 1)
        currenta = data.a;
        currentc = data.c;
        currentxbd = data.xbd;
        currentIbd = [data.ifir, data.ilas];
        currentgamma = max(0, data.W);
        currentexposure = data.y;
        currentnoz = data.novctrs;
        ok(1) = 1;
    end
    if (isfield(data,'isSOL') == 1) && (data.isSOL == 1)
        for i=1:data.noc
            a(i,:) = data.SOL(i).a;
            Clocal(:,i) = data.SOL(i).c;
            xbd(i,:) = data.SOL(i).xbd;
            Ibd(i,:) = [data.SOL(i).ifir, data.SOL(i).ilas];
            gamma(i,:) = max(0, data.SOL(i).W);
            exposure(i,:) = data.SOL(i).y;
            noz(i) = data.SOL(i).novctrs;
        end
        ok(2) = 1;
    end
    okC = 0;
    if (isfield(data,'iscon') == 1) && (data.iscon == 1)
        if data.congloballocal == 1
            Clocal = data.C;
            ok(3) = 1;
        elseif data.congloballocal == 2
            Cglobal = data.C;
            ok(3) = 2;
        end
    end
    
    if max(ok(1:2)) == 1
        x = data.x;
        D = data.D;
        U = data.U0;
        S = data.S0;
        V = data.V0;
        
        issaved = 0;
        
        if kind == 4 && ok(1)
            goon = questdlg('The last calculated profile has not yet been accepted. Is this correct?', ...
            'Last profile not accepted', ...
            'Yes, discard the profile and continue.','No, stop and accept it.','No, stop and accept it.');
            switch goon
            case 'Yes, discard the profile and continue.'
            case 'No, stop and accept it.'
                return
            end
        end
        
        if ok == [1 0 0]
            uisave({'x','D','U','S','V','currenta','currentc','currentxbd','currentIbd','currentgamma','currentexposure','currentnoz'},[data.PathName,'results_facpack_PGA_',data.FileName]);
        elseif ok == [1 1 0]
            uisave({'x','D','U','S','V','currenta','currentc','currentxbd','currentIbd','currentgamma','currentexposure','currentnoz','a','xbd','Ibd','gamma'},[data.PathName,'results_facpack_PGA_',data.FileName]);
        elseif ok == [1 1 1]
            uisave({'x','D','U','S','V','currenta','currentc','currentxbd','currentIbd','currentgamma','currentexposure','currentnoz','a','xbd','Ibd','gamma','Clocal'},[data.PathName,'results_facpack_PGA_',data.FileName]);
        elseif ok == [1 1 2]
            uisave({'x','D','U','S','V','currenta','currentc','currentxbd','currentIbd','currentgamma','currentexposure','currentnoz','a','xbd','Ibd','gamma','Cglobal'},[data.PathName,'results_facpack_PGA_',data.FileName]);
        elseif ok == [0 1 0]
            [filename, filepath] = uiputfile([data.PathName,'results_facpack_PGA_',data.FileName]);
            if ~islogical(filename) || ~filename == 0
                save([filepath, filename],'x','D','U','S','V','a','Clocal','xbd','Ibd','gamma','exposure','noz');
                issaved = 1;
            end
        elseif ok == [0 1 0]
            [filename, filepath] = uiputfile([data.PathName,'results_facpack_PGA_',data.FileName]);
            if ~islogical(filename) || ~filename == 0
                save([filepath, filename],'x','D','U','S','V','a','Clocal','xbd','Ibd','gamma','exposure','noz');
                issaved = 1;
            end
        elseif ok == [0 1 1]
            [filename, filepath] = uiputfile([data.PathName,'results_facpack_PGA_',data.FileName]);
            if ~islogical(filename) || ~filename == 0
                save([filepath, filename],'x','D','U','S','V','a','Clocal','xbd','Ibd','gamma','exposure','noz','Clocal');
                issaved = 1;
            end
        elseif ok == [0 1 2]
            [filename, filepath] = uiputfile([data.PathName,'results_facpack_PGA_',data.FileName]);
            if ~islogical(filename) || ~filename == 0
                save([filepath, filename],'x','D','U','S','V','a','Clocal','xbd','Ibd','gamma','exposure','noz','Cglobal');
                issaved = 1;
            end
        end
    end
    
    if kind == 4 && issaved
        closereq();
        subGUI4PCD(version, 203, filepath, filename);
    end
end