function cv=getcvtab(n,cvtab,alpha)
%                GET CRITICAL VALUES FROM THE TABLE
% =======================================================================
% function cv=getcvtab(n,cvtab,alpha)
% INPUT:
% n     ... vector of data lengths
% cvtab ... name of file .mat containing: cvval (1 x c) and cvtab (N+1 x c)
%           cvalpha(i) = risk alpha [%] for the i-th column in the table
%           cvtab(m,i) = critical value for value m at risk cvval(i), 1<=m<=N
%                      = NaN if value not availble or m=N+1
% alpha ... percentual risk value (optional: default=[]=5%)
%
% OUTPUT:
% cv... cv(j) = critical value at level alpha % [(1-lpha)% percentile]
%               for m=n(j)
%             = NaN if value not available in the table of percentiles
%

% (C) 1997, V. Vesely, Masaryk University of Brno (Czech Republic)
%

error(nargchk(2,3,nargin));
if nargin<3, alpha= []; end
if isempty(alpha), alpha = 5; end

% Load critical values from the table 'cvtab':
feval('load',cvtab);
Nrows = size(cvtab,1);
cvcol = find(alpha==cvalpha);

if isempty(cvcol)
   cv = NaN*ones(length(n),1);
else
   cv = cvtab(min(n,Nrows),cvcol);
end
