function [bar_lev, acer_hat, CI ] = uniACER( x, k_mem, N, flagACER )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
% x = Wsp;
if  size(x,1)> size(x,2)
    x = transpose(x);
end
Dim = size(x);
ML = zeros(Dim(1),1);
for jj=1:Dim(1)
    ML(jj) = sum(isfinite(x(jj,:)));
end
clear jj
h = waitbar(0,'Calculating ACER functions, please wait');
for kk=1:length(k_mem)
    
%     [bar_lev{kk}, acer_hat{kk}, CI{kk}] = ...
%         ACER(x, length(x)*ones(size(x, 1),1), k_memory(kk), N_barrier, conf_level, flag);
        [bar_lev{kk}, acer_hat{kk}, CI{kk}, ~, ~] = ...
            ACER(x, ML, k_mem(kk), N, 0.95, flagACER, 1);
        waitbar(kk/length(k_mem));
end
close(h);
clear kk h;

MrKr = {'o','>','-.',':','s','-','+','d','p','x','v','^','h','s'};
if length(k_mem)>length(MrKr)
[MK{1:length(k_mem)-length(MrKr)}] = deal('-');
MrKr = [MrKr MK];
end
clear MK

MrkSz = [3 3 3 3 2.5 3 3 3 3 3 3 3 3 3];
if length(k_mem)>length(MrkSz)
    [MS(1:length(k_mem)-length(MrkSz))] = deal(3);
    MrkSz = [MrkSz MS];
end
clear MS

line = [0.5 0.5 1 1.5 0.5 1 1 1 1 1 1 1 1 1];
if length(k_mem)>length(line)
    [ln(1:length(k_mem)-length(line))] = deal(1);
    line = [line ln];
end
clear ln

figure
clf
for ii=1:length(k_mem)
    
    %     condition = bar_lev{ii}>bar_lev{ii}(15);
    %     CI{ii} = CI{ii}(condition);
    
    semilogy(bar_lev{ii}(bar_lev{ii}>bar_lev{ii}(20)),...
        acer_hat{ii}(bar_lev{ii}>bar_lev{ii}(20)),...
        MrKr{ii},'Color','k','MarkerSize',MrkSz(ii),'Linewidth',line(ii))
    hold on
    leg{ii} = ['k=' num2str(k_mem(ii))];
    
    eps_menu_options{ii} = ['ACER(k=' num2str(k_mem(ii)) ')'];
    
end
axis tight
xlabel('\eta')
ylabel('ACER_k(\eta)')
legend(leg)
editplot2;
% ax = axes('Units', 'Normalized', 'Position', [0.13 0.13 0.25 0.25], ...
%     'XTick', [], 'YTick', [], 'Box', 'on');
% hold on;
% for ii=1:length(k_mem)
%     
%     %     condition = bar_lev{ii}>bar_lev{ii}(15);
%     %     CI{ii} = CI{ii}(condition);
%     
%     semilogy(bar_lev{ii}(bar_lev{ii}>bar_lev{ii}(20)),...
%         log10(acer_hat{ii}(bar_lev{ii}>bar_lev{ii}(20))),...
%         MrKr{ii},'Color','k','MarkerSize',MrkSz(ii),'Linewidth',line(ii))
%     hold on
%     
% end


end

