% rep=input('enter directory to save files \n','s'); 

% h=359;
% h=360-359;
hurricane='isabel';
rep='';
files=dir(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\modified\',rep,'*dat']); 

for fil=1:2%length(files)
    ws=[];
    wd=[];
    sweepfile=files(fil).name;
    radar_data=load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\modified\',rep,sweepfile]);
    [li,col]=size(radar_data);
    vel=radar_data(1:li-1,:);
    az=radar_data(li,:);
    el=str2num(sweepfile(30:32))
    az=az';
    temp_vel=vel;
    [vel_row,vel_col]=size(vel);
    
    %  az_N=az-h;
    
    
    for rg=1:250%length(vel)
        [ws_mean,wd_mean]=vad(az,temp_vel(rg,:),el);
         ws=[ws;ws_mean];
        wd=[wd;wd_mean];
         
         if isnan(wd_mean)==1
            mean_radial_vel_tower1(rg,1:vel_col)=NaN*ones(1,1:vel_col);
            meanless(rg,1:vel_col)=NaN*ones(1,1:vel_col);
        else
            beta=abs(az-wd_mean);
            
            u_toward=find(beta < 90  | beta >= 270);
            toward=-ws_mean*cos(deg2rad(beta(u_toward)));
            
            
            u_away=find(beta >= 90  & beta <270);
            beta(u_away)=abs(beta(u_away)-180);
            away=ws_mean*cos(deg2rad(beta(u_away)));
            
            
            mean_radial_vel_tower1(rg,u_away)=away';
            mean_radial_vel_tower1(rg,u_toward)=toward';
            
            
            meanless(rg,:)=vel(rg,:)-mean_radial_vel_tower1(rg,:);
         end
     end
     total=[ws wd];
     
     az=az';
     save(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\modified\meanless\',sweepfile],'meanless','az','-ascii')
     sweepfile=sweepfile(1:length(sweepfile)-4);
     %save(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\',hurricane,'\data\total_wind\fourier\',sweepfile,'_wind.dat'],'total','-ascii')

    clear mean_radial_vel_tower1
    clear meanless
    clear total
    clear u_360
end
