function buttonselectcontourCAA(hObject, eventdata, Empty_Button, AxesC, AxesA, AxesSOLA, AxesSOLC, uonoff, uonoffC, regcont, regcontC, vers, lcs)
data = get(Empty_Button,'UserData');

if (data.isAFSC*data.isAFSA == 0) && (data.full.isC*data.full.isA == 0)
    set(regcont(1), 'Value', 1);
    set(regcontC(1), 'Value', 1);
    return;
end

sz1 = 40;
sz2 = 41;

set(uonoff(1), 'Value', 1);
set(uonoffC(1), 'Value', 1);

set(gcf,'Pointer','Watch');
pause(0.5);

if vers == 1
    if get(regcont(1), 'Value')
        data.regcon = 0;
    elseif get(regcont(2), 'Value')
        data.regcon = 1;
        
        if data.isregcon(1) == 0
            data.REGCON{1}.xl = linspace(data.xla(1), data.xla(2), sz1);
            data.REGCON{1}.yl = linspace(data.yla(1), data.yla(2), sz2);
            for i=1:sz1
                for j=1:sz2
                    a = [1 data.REGCON{1}.xl(i) data.REGCON{1}.yl(j)]*data.V';
                    a = a/max(a);
                    secder = 0;
                    h0 = data.x(2)-data.x(1);
                    for l=1:length(data.x)-2
                        h1 = data.x(l+2)-data.x(l+1);
                        secder = secder+(2/h0/(h0+h1)*(a(l)-(1+h0/h1)*a(l+1)+h0/h1*a(l+2)))^2;
                        h0 = h1;
                    end
                    data.REGCON{1}.cl(i,j) = log(secder);
                end
            end
            data.isregcon(1) = 1;
        end
    elseif get(regcont(3), 'Value')
        data.regcon = 2;
        
        if data.isregcon(2) == 0
            data.REGCON{2}.xl = linspace(data.xla(1), data.xla(2), sz1);
            data.REGCON{2}.yl = linspace(data.yla(1), data.yla(2), sz2);
            for i=1:sz1
                for j=1:sz2
                    a = [1 data.REGCON{2}.xl(i) data.REGCON{2}.yl(j)]*data.V';
                    a = a/max(a);
                    data.REGCON{2}.cl(i,j) = norm(a);
                end
            end
            data.isregcon(2) = 1;
        end
    end
else
    if get(regcontC(1), 'Value')
        data.regconC = 0;
    elseif get(regcontC(2), 'Value')
        data.regconC = 1;
        
        if data.isregconC(1) == 0
            k = length(data.t);
            data.REGCONC{1}.xl = linspace(data.xlc(1), data.xlc(2), sz1);
            data.REGCONC{1}.yl = linspace(data.ylc(1), data.ylc(2), sz2);
            for i=1:sz1
                for j=1:sz2
                    c = data.U*data.S*[1 data.REGCONC{1}.xl(i) data.REGCONC{1}.yl(j)]';
                    c = c/max(c);
                    dc = zeros(k-1,1);
                    for l=1:k-1
                        dc(l,1) = (c(l+1)-c(l))/(data.t(l+1)-data.t(l));
                    end
                    dcm = min(dc,0);
                    dcp = max(dc,0);
                    data.REGCONC{1}.cl(i,j) = min(dcp'*dcp, dcm'*dcm);
                end
            end
            data.isregconC(1) = 1;
        end
    elseif get(regcontC(3), 'Value')
        data.regconC = 2;
        
        if data.isregconC(2) == 0
            k = length(data.t);
            data.REGCONC{2}.xl = linspace(data.xlc(1), data.xlc(2), sz1);
            data.REGCONC{2}.yl = linspace(data.ylc(1), data.ylc(2), sz2);
            for i=1:sz1
                for j=1:sz2
                    c = data.U*data.S*[1 data.REGCONC{2}.xl(i) data.REGCONC{2}.yl(j)]';
                    c = c/max(c);
                    ddc = zeros(k-1,1);
                    h0 = data.t(2)-data.t(1);
                    for l=1:k-2
                        h1 = data.t(l+2)-data.t(l+1);
                        ddc(l,1) = (2/h0/(h0+h1)*(c(l)-(1+h0/h1)*c(l+1)+h0/h1*c(l+2)));
                        h0 = h1;
                    end
                    
                    data.REGCONC{2}.cl(i,j) = log(ddc'*ddc);
                end
            end
            data.isregconC(2) = 1;
        end
    else
        data.regconC = 3;
        
        if data.isregconC(3) == 0
            f = @(c,t,x) norm(c-x(1)*exp(-x(2)*t),2)^2;
            k = length(data.t);
            data.REGCONC{3}.xl = linspace(data.xlc(1), data.xlc(2), sz1);
            data.REGCONC{3}.yl = linspace(data.ylc(1), data.ylc(2), sz2);
            xopt = ones(2, sz1, sz2);
            
            for i=1:sz1
                for j=1:sz2
                    c = data.U*data.S*[1 data.REGCONC{3}.xl(i) data.REGCONC{3}.yl(j)]';
                    [x, res] = fminsearch(@(x) f(c,data.t,x), xopt(:,i,j),optimset('Display','off'));
                    xopt(:,i,j) = x;
                    if j<sz2
                        xopt(:,i,j+1) = xopt(:,i,j);
                    elseif i<sz1
                        xopt(:,i+1,1) = xopt(:,i,1);
                    end
                    data.REGCONC{3}.cl(i,j) = log(res);
                end
            end
            
            data.U(1,:)*data.S*[1 7 -8]'
            
            fall = @(cx,t) norm(data.U*data.S*[1 cx(3) cx(4)]'-cx(1)*exp(-cx(2)*t),2)^2;
            [x, res] = fminsearch(@(cx) fall(cx,data.t), [54, 0.75, 7 ,-8],optimset('Display','Iter'))
            
            
            data.isregconC(3) = 1;
        end   
    end
end

set(gcf,'Pointer','arrow');

isregcon = [0 0];   REGCON = [];
if (data.regcon > 0) && (data.isregcon(data.regcon) == 1)
    isregcon(1) = data.regcon;
    REGCON{1} = data.REGCON{isregcon(1)};
end
if (data.regconC > 0) && (data.isregconC(data.regconC) == 1)
    isregcon(2) = data.regconC;
    REGCON{2} = data.REGCONC{isregcon(2)};
end

plotafsCAA(AxesA, AxesC, AxesSOLA, AxesSOLC, data.xla, data.xlc, data.yla, data.ylc, data.x, data.t, data.AFSA, data.AFSC,...
           data.U*data.S, data.V', data.fixA, data.fixC, data.choosen, data.choosenC, isregcon, REGCON, data.full, data.selectplot, data.givena, data.givenc, data.tall, data.tcll, data.istrace, lcs, [data.isclosure data.isshift data.ispeakposition data.isxreverse]);

set(Empty_Button,'UserData',data);
