function [cvL,cvH]= findcv(a,x,T);

% x is significance level
% a is the matrix of cv



level=[.01 .025 .05 .10 .90 .95 .975 .99];
pp=abs(level-x);
[p1,p2]=min(pp);
p3=cols(level)-p2+1;


TT=[50 100 150 200 250 300 400 500 1000]';
dum=T-TT;

% if T=TT, we use the simulated for TT
% otherwise, we use the critival value that is interpolated from the
% two TT's closest to T

[minv1,mini1]=min(abs(dum));
t1=TT(mini1); d1=mini1;


dum(mini1)=9999;
[minv2,mini2]=min(abs(dum));
t2=TT(mini2); d2=mini2;



cv1=a(d1,p2);
cv2=a(d2,p2);
if minv1 ~=0;
cvL=(cv1+cv2)/2;
else;
  cvL=cv1;
end;  


cv1=a(d1,p3);
cv2=a(d2,p3);
if minv1 ~=0;
cvH=(cv1+cv2)/2;
else;
  cvH=cv1;
end;  
