av_window=1;
 range=input('enter the range \n');
    
%az=input('enter the azimuth \n');
azimuth=input('enter the azimuth \n');
 ref_el=input('enter the reference elevation \n');
rep=input('enter directory to work on \n','s'); 
files=dir(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\isabel\data\modified\',rep,'\*dat']); 
% for az=213:222
% heading=num2str(az);
data08=[];
data22=[];
data38=[];
data52=[];
data68=[];
data82=[];
% n=9;
for fil=1:length(files);
  sweepfile=files(fil).name;
el=str2num(sweepfile(30:32));
mod_data=load(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\isabel\data\modified\',rep,'\',sweepfile]);
mod_az=mod_data(length(mod_data),:);
mod_az=mod_az';
mod_data=mod_data(1:length(mod_data)-1,:);
HR=range*67*cos(deg2rad(ref_el)); %1170
% dif=abs(az-mod_az);
% azimuth=find(dif==min(dif));
if length(azimuth) >1
    break
end
if el==0.8
    range08=(HR/cos(deg2rad(0.75)))/67;
    range08=round(range08);
    temp=mod_data(range08,azimuth);
%     temp=abs(mod_data(range08-1:range08+1,azimuth-1:azimuth+1));
%     temp=sum(sum(temp))/n;
    data08=[data08;temp];
elseif el==2.2
        range22=(HR/cos(deg2rad(2.25)))/67;
        range22=round(range22);
        temp=mod_data(range22,azimuth);
%     temp=abs(mod_data(range22-1:range22+1,azimuth-1:azimuth+1));
%     temp=sum(sum(temp))/n;
    data22=[data22;temp];
elseif el==3.8
        range38=(HR/cos(deg2rad(3.75)))/67;
        range38=round(range38);
        temp=mod_data(range38,azimuth);
%     temp=abs(mod_data(range38-1:range38+1,azimuth-1:azimuth+1));
%     temp=sum(sum(temp))/n;
    data38=[data38;temp];
elseif el==5.2
    range52=(HR/cos(deg2rad(5.25)))/67;
    range52=round(range52);
    temp=mod_data(range52,azimuth);
%     temp=abs(mod_data(range52-1:range52+1,azimuth-1:azimuth+1));
%     temp=sum(sum(temp))/n;
    data52=[data52;temp];
 elseif el==6.8
         range68=(HR/cos(deg2rad(6.75)))/67;
         range68=round(range68);
         temp=mod_data(range68,azimuth);
%      temp=abs(mod_data(range68-1:range68+1,azimuth-1:azimuth+1));
%     temp=sum(sum(temp))/n;
    data68=[data68;temp];
 elseif el==8.2
         range82=(HR/cos(deg2rad(8.25)))/67;
         range82=round(range82);
         temp=mod_data(range82,azimuth);
%      temp=abs(mod_data(range82-1:range82+1,azimuth-1:azimuth+1));
%     temp=sum(sum(temp))/n;
    data82=[data82;temp];
end
end
alpha=[0.75;2.25;3.75;5.25;6.75;8.25];
range=[range08;range22;range38;range52;range68;range82];
height=67*range.*sin(deg2rad(alpha));
data_el=[data08 data22 data38 data52 data68 data82];   
 save(['C:\Documents and Settings\sylvie lorsolo\My Documents\research\isabel\data\timeseries2.dat'],'data_el','-ascii')
% end
% [li,col]=size(data_el);
% L=fix(li/av_window);% in this case av_window is in # of points
% for j_col=1:6
%     for i_li=1:L
%     temp=data_el(av_window*(i_li-1)+1:av_window*i_li,j_col);
%     NaN_search=isnan(temp);
%     u_NaN=find(NaN_search==1);
%     temp(u_NaN)=0;
%     data_el_mean(i_li,j_col)=sum(temp)/(length(temp)-length(u_NaN));
% end
% end
% reste=li-av_window*L;
%    if reste >0
%        for j_col=1:6
%      temp=data_el(av_window*(i_li)+1:L,j_col); 
%    NaN_search=isnan(temp);
%     u_NaN=find(NaN_search==1);
%     temp(u_NaN)=0;
%     data_el_mean(i_li,j_col)=sum(temp)/(length(temp)-length(u_NaN));
%   end
% end