rate=input('enter acquisition rate \n');
aver_time=input('enter averaging time in seconds \n');


ws=data(:,9);
Time=data(:,1:5);
temp=Time(:,4)/100;
heure=fix(temp);
minut=(temp-heure)*100;
Time=[Time(:,1:3) heure minut Time(:,5)];
mean_aver=[];
mean_time_av=[];
L=length(ws);
n=aver_time*rate;
milieu=fix(n/2);

for k=1:fix(L/n);
    A=mean(ws(n*(k-1)+1:n*k));
    mean_aver=[mean_aver;A];
    B=Time(n*(k-1)+1+milieu,1:6);
    mean_time_av=[mean_time_av;B];
end
    
reste=L-n*fix(L/n);
reste_time=fix(reste/2);
if reste >0
   reste=ws(n*(fix(L/n))+1:L); 
   reste_time=Time(n*fix(L/n)+1+reste_time,1:6);
   mean_aver=[mean_aver;mean(reste)];
   mean_time_av=[mean_time_av;reste_time];
end

ws=mean_aver;


wd=data(:,10);

for lg=1:length(wd)
    wd(lg)=wd(lg)-72;
    if wd(lg) < 0
       wd(lg)=wd(lg)+360;
    end
end

wd_mean=[];
for j=1:fix(L/n);
        temp=wd(n*(j-1)+1:n*j);
        for i=1:length(temp)
                ang(i)=(temp(i)*pi)/180;
                if ang(i)<=pi/2
                   u(i)=-sin(ang(i));
                   v(i)=-cos(ang(i));
                end
    
               if ang(i) > pi/2 & ang(i) <= pi
                  ang(i)=ang(i)-pi/2;
                  u(i)=-cos(ang(i));
                  v(i)=sin(ang(i));
               end
               if ang(i) > pi & ang(i) <= 3*pi/2
                  ang(i)=ang(i)-pi;
                  u(i)=sin(ang(i));
                  v(i)=cos(ang(i));
               end
               if ang(i) > 3*pi/2 & ang(i) <=2* pi
                  ang(i)=ang(i)-3*pi/2;
                  u(i)=cos(ang(i));
                  v(i)=-sin(ang(i));
               end

          end
     U=mean(u);
     V=mean(v);

     if U >0 & V >0
        alpha=atan(U/V);
        alpha=pi+alpha;
     end
    if U >0 & V <0
       alpha=-atan((V/U));
       alpha=3*pi/2+alpha;
    end
    if U <0 & V >0
       alpha=-atan((V/U));
       alpha=pi/2+alpha;
    end
    if U <0 & V <0
       alpha=atan(U/V);
    end
    if U==0 & V >0
        alpha=pi;
    end
     if U==0 & V <0
        alpha=0;
    end
     if U<0 & V ==0
        alpha=pi/2;
    end
     if U>0 & V ==0
        alpha=3*pi/2;
    end
       alpha=rad2deg(alpha);
       wd_mean=[wd_mean;alpha];
       
       
   end
   reste=L-n*fix(L/n);
   if reste >0
      reste=wd(n*(j)+1:L); 
      wd_mean=[wd_mean;mean(reste)];
  end
