hurricane='frances';
rep='modified\rhi';
files=dir(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\swp.104090503*.dat']);

for fil=1:20%:length(files)
    filename=files(fil).name;
    rhi=load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\',rep,'\',filename]);
    az=str2num(filename(30:32));
    ele_rhi=rhi(length(rhi),:);
     u_el=find(ele_rhi<=12);
     ele_rhi=ele_rhi(u_el);
    L=length(ele_rhi);
    L2=300;
    rhi=rhi(1:L2,1:L);
    %Modify the data for hrd compression
    mod_rhi=rhi;
    u_bad_vel=find(rhi < -100);
    mod_rhi(u_bad_vel)=NaN;
    wd_rhi=[];
    ws_rhi=[];
    [h_mean,ws_mean,wd_mean,u_mean,v_mean]=mean_profile(hurricane);
    range=33.35:66.7:299*66.7+33.35;
    for j=1:L
        wd_col=[];
        alt=(range*sin(deg2rad(ele_rhi(j))))'; 
        ws_col=interp1(h_mean,ws_mean,alt,'linear','extrap');
        u_col=interp1(h_mean,u_mean,alt,'linear','extrap');
        v_col=interp1(h_mean,v_mean,alt,'linear','extrap');
        for i=1:L2
            if u_col(i) >0 & v_col(i) >0
                alpha=atan(u_col(i)/v_col(i));
                alpha=pi+alpha;
                
            elseif u_col(i) >0 & v_col(i) <0
                alpha=-atan((v_col(i)/u_col(i)));
                alpha=3*pi/2+alpha;
                
            elseif u_col(i) <0 & v_col(i) >0
                alpha=-atan((v_col(i)/u_col(i)));
                alpha=pi/2+alpha;
                
            elseif u_col(i) <0 & v_col(i) <0
                alpha=atan(u_col(i)/v_col(i));
            else
                alpha=NaN;
            end
            alpha=rad2deg(alpha);
            wd_col=[wd_col;alpha];
        end
        wd_rhi=[wd_rhi wd_col];
        ws_rhi=[ws_rhi ws_col];
    end
    beta=abs(az-wd_rhi);
u_bad_angle=find(beta <0 | beta >=360);
beta(u_bad_angle)=NaN;

u_NaN=find(isnan(beta));



u_toward=find(beta < 90  | beta >= 270);
toward=-ws_rhi(u_toward).*cos(deg2rad(beta(u_toward)));


u_away=find(beta >= 90  & beta <270);
beta(u_away)=abs(beta(u_away)-180);
away=ws_rhi(u_away).*cos(deg2rad(beta(u_away)));

rhi_radial=ones(L2,L);
rhi_radial(u_away)=away;
rhi_radial(u_toward)=toward;
rhi_radial(u_NaN)=NaN;
meanless_rhi=mod_rhi-rhi_radial;
 clear('rhi_radial');
 save(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\modified\meanless\rhi\23\check\',filename],'meanless_rhi','ele_rhi','-ascii')

end