hurricane='isabel';
rep='meanless\temp\filtered\2000\gridded_data\corre\';
orientation=5.6;%frances 53.4 isabel 5.6;
edges=0.0014:0.002:0.014;%isabel 0.0014:0.002:0.014;frances edges=0.0048:0.002:0.02;
x_axis=0.0014+(0.002/2):0.002:0.014+(0.002/2);%isabel 0.0014+(0.002/2):0.002:0.014+(0.002/2); frances x_axis=0.0048+(0.002/2):0.002:0.02+(0.002/2);

colonnes=18;
u=[];
v=[];
dt=[];
r=[];
times=[];
v_cross=[];
for boxe=1:3
    load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\modified\',rep,'corre',num2str(boxe),'.mat']);
    for i=1:length(corre)
        for j=i+1:i+2 % for isabel i+1:i+2, for frances i+2:i+3
            u=[u;corre(i).v_x(j)];
            v=[v;corre(i).v_y(j)];   
            dt=[dt;corre(i).delta_t(j)];
            r=[r;corre(i).r(j)];
            times=[times;corre(i).time(j,:)];
        end
    end
end
t=datenum(times);
[temp1,temp2]=sort(t);
u=u(temp2);
v=v(temp2);
dt=dt(temp2);
r=r(temp2);
t=temp1;
ws=sqrt((u.^2)+(v.^2))./dt;

wd=atan(u./v);

u_wd=find(v>0 & u >0);
alpha=atan(u(u_wd)./v(u_wd));
alpha=pi+alpha;
wd(u_wd)=alpha;

u_wd=find(v>0 & u <0);
alpha=-atan(v(u_wd)./u(u_wd));
alpha=pi/2+alpha;
wd(u_wd)=alpha;

u_wd=find(v<0 & u >0);
alpha=-atan(v(u_wd)./u(u_wd));
alpha=3*pi/2+alpha;
wd(u_wd)=alpha;

u_wd=find(v<0 & u <0);
alpha=atan(u(u_wd)./v(u_wd));
wd(u_wd)=alpha;

u_wd=find(v>0 & u ==0);
alpha=pi;
wd(u_wd)=alpha;

u_wd=find(v<0 & u ==0);
alpha=0;
wd(u_wd)=alpha;

u_wd=find(v==0 & u >0);
alpha=3*pi/2;
wd(u_wd)=alpha;

u_wd=find(v==0 & u <0);
alpha=pi/2;
wd(u_wd)=alpha;


u_corre=find(r>0.5);
u=u(u_corre);
v=v(u_corre);
ws=ws(u_corre);
wd=wd(u_corre);
t=t(u_corre);
wd=rad2deg(wd);
dt=dt(u_corre);

mu_1=mean(u);
mu_2=mean(v);
sigma1=std(u);
sigma2=std(v);
outliers = abs(u - mu_1) > 1.5*sigma1;
u_out=find(outliers==1);
u(u_out)=NaN;
v(u_out)=NaN;
ws(u_out)=NaN;
t(u_out)=NaN;
dt(u_out)=NaN;
wd(u_out)=NaN;
outliers = abs(v - mu_2) > 1.5*sigma2;
u_out=find(outliers==1);
u(u_out)=NaN;
v(u_out)=NaN;
ws(u_out)=NaN;
t(u_out)=NaN;
dt(u_out)=NaN;
wd(u_out)=NaN;
u_NaN=find(isnan(t));
u(u_NaN)=[];
v(u_NaN)=[];
ws(u_NaN)=[];
t(u_NaN)=[];
dt(u_NaN)=[];
wd(u_NaN)=[];
mu=mean(ws);
sigma=std(ws);
outliers = abs(ws - mu) > 1.5*sigma;
u_out=find(outliers==1);
u(u_out)=[];
v(u_out)=[];
ws(u_out)=[];
t(u_out)=[];
wd(u_out)=[];
dt(u_out)=[];

for i=1:length(ws)
    d_trans=sqrt((u(i).^2)+(v(i).^2));
    %for j=1:length(orientation)
    beta=deg2rad(orientation)-deg2rad(wd(i));
    v_cross=[v_cross;(d_trans*((sin(beta))))/dt(i)];
    %end
end
[n_hist,edges1,total]=disp_extrem_4_cross_speed(hurricane);
freq_el=[];

for i=1:colonnes
    
    f=[];
    
    maxi=max(n_hist);
    u_lim=find(n_hist(:,i)>=0.15);
    if length(u_lim)>0
        uu=find(total(:,i)>=edges1(u_lim(1)) & total(:,i)<edges1(u_lim(length(u_lim))+1));
        %temp=lambda_middle(u_lim);
        temp=nanmean(total(uu,i));
    else
        uu=find(total(:,i)>=300 & total(:,i)<500);
        temp=nanmean(total(uu,i));
    end
    for j=1:length(v_cross)
        f=[f;v_cross(j)./temp];
        %          n1=histc(f,edges);
        %          n(:,i)=n(:,i)+n1;
        
    end
    freq_el=[freq_el f];
end
z=0:25:25*(colonnes-1);
n=histc(freq_el,edges);
n1=n;
for i=1:colonnes
    u_nzeros=find(n1(:,i) ~=0);
    somme=sum(n1(u_nzeros,i));
    n1(u_nzeros,i)=n1(u_nzeros,i)./somme;
end
contourf(x_axis,z,100*n1',25)
shading flat
colorbar