function fig = buttonevaluatePGA(hobject, eventdata, Empty_Button, Buttons, AxesD, AxesSOL, AxesAOM, RegSlider, RegText, lcs, LCS)

data = get(Empty_Button,'UserData');

if data.isdata
    redrawAxesD(hobject,eventdata,Empty_Button,AxesD,lcs,LCS)
end


fig = figure(104);
set(fig,'Name','Evaluation','NumberTitle','off','MenuBar','none','Toolbar','figure','color','white');
pause(.1);
set(0,'DefaultAxesTitleFontWeight','normal');
scrsz = get(0,'ScreenSize');

set(fig,'Position',[1/10*scrsz(3:4) 2/3*scrsz(3:4)]);

if ispc
    basicfsz = 4.5;
    basichi = 0.025;
else
    basicfsz = 5.5;
    basichi = 0.025;
end

Styles = {'bitstream charter';'clean';'Courier';'courier 10 pitch';'frank ruehl';'Helvetica';'Helvetica-Narrow';'itc bookman';'urw bookman l'};
sty = Styles{6};
bgc = 0.95*ones(3,1);
bgw = [1, 1, 1];

% Axes1 = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.1, 0.675, 0.55, 0.275]);
% plot(Axes1,1,0,'w');
% 
% Axes2 = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.1, 0.375, 0.55, 0.275]);
% plot(Axes2,1,0,'w');
% 
% Axes3 = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.1, 0.075, 0.55, 0.275]);
% plot(Axes3,1,0,'w');

Axes1 = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.1, 0.575, 0.55, 0.375]);
plot(Axes1,1,0,'w');

Axes2 = axes('Fontsize',2*basicfsz,'Units','normalized','FontName',sty,'Position',[0.1, 0.075, 0.55, 0.375]);
plot(Axes2,1,0,'w');

data.SOL;

subploPGA(hobject, eventdata, Axes1, Axes2, data, lcs);

% Button(1) = uicontrol('Style','pushbutton','UserData',0,'String','Apply','HorizontalAlignment','left','Fontsize',2*basicfsz,'FontWeight','bold',...
%     'Units','normalized','FontName',sty,'Position',[0.7, 0.125, 0.13, 1.5*basichi],...
%     'TooltipString', sprintf('Accept the results and delete marked ones.'),...
%     'Callback',{@subbuttonacceptPGA, Empty_Button, Buttons, Axes1, Axes2, RegSlider, RegText, data, box, fig, lcs, LCS});

Button(2) = uicontrol('Style','pushbutton','UserData',0,'String','Cancel','HorizontalAlignment','center','Fontsize',2*basicfsz,'FontWeight','bold',...
    'Units','normalized','FontName',sty,'Position',[0.85, 0.125, 0.13, 1.5*basichi],...
    'Callback',{@innerbuttoncancel, fig});

function subploPGA(hObject, eventdata, Axes1, Axes2, data, lcs)

% hold(Axes1,'off');
% hold(Axes2,'off');
% if length(lgnSOL) > 0
%     lgnSOL = legend(Axes1,lgnSOL);
%     set(lgnSOL,'fontsize',10);
% else
%     plot(Axes1,1,0,'w');
% end
% 
% if length(lgnREJ) > 0
%     lgnREJ = legend(Axes2,lgnREJ);
%     set(lgnREJ,'fontsize',10);
% else
%     plot(Axes2,1,0,'w');
% end

% if isfield(data,'C')
%     size(data.C)
%     for i = 1:size(data.C,2)
%         plot(Axes1,data.C(:,i))
%     end
% end
% 
% if isfield(data,'SOL')
% size(data.SOL,2)
%     for i = 1:size(data.SOL,2)
%         plot(Axes2,data.SOL(i).a)
%     end
% end

colors = [[0.1 0.8 0.1];[0.8 0.1 0.1];[0.1 0.1 0.8];[0.8 0.8 0.1]];
plot(Axes1,data.x,data.D','k')
hold(Axes1,'on');
% plot(Axes2,data.D','k')
if isfield(data,'C') && isfield(data,'SOL')
    if size(data.C,2) == size(data.SOL,2)
        dsum = zeros(size(data.D))';
        for i = 1:size(data.C,2)
            c = data.C(:,i);
            a = data.SOL(i).a;
            d = (c*a)';
            dsum = dsum + d;
            plot(Axes1,data.x,d ,'Color',colors(i,:))
        end
    end
%     plot(Axes1,dsum,'Color',colors(2,:))
end

% M = [max(dsum,[],2)';min(dsum,[],2)'];
M = dsum';
for i = 1:size(M,2)
    for j = 1:size(M,1)
        M(j,i) = min(abs(M(j,i)-data.D(:,i)));
    end
end
M = data.D-dsum';
plot(Axes2,data.x,M','Color',[0.5 0 0.5])
hold(Axes2,'on');

title(Axes1,'data');
xlabel(Axes1,'channel');
set(Axes1,'Fontsize',12);
axis(Axes1,'tight');
yl1 = ylim(Axes1);

title(Axes2,'resid');
xlabel(Axes2,'channel');
set(Axes2,'Fontsize',12);
axis(Axes2,'tight');
yl2 = ylim(Axes2);
yl = yl1;
yl(1) = min(yl1(1),yl2(1));
yl(2) = max(yl1(2),yl2(2));

ylim(Axes2,yl);

function innerbuttoncancel(hobject, eventdata, parentfig)
close(parentfig);
