function [rlimit, outlier_ind] = rlim(x,alpha)
% calculate the 95 percentile of X
% outlying points, i.e. deviating for more than 1.5 times the interquartile range
% are excluded from limit computation
%
%% x is assume dto be made of only positive values

% rlimit=rlim(x,alpha)
%%% to fix bug disocvered May 2010
%% n=size(x,1); has been substituted by
n=length(x);
ind=ones(n,1);
p=100*(1-alpha);
iqrange=iqr(x);
outlier_ind=find(x > iqrange*1.5+prctile(x,75));
ind(outlier_ind)=0;
xok_ind=find(ind);
rlimit=prctile(x(xok_ind),p);