% Code for extract radar radial o vector current data from original wera 
%files given the grid coordinates.


% Julian day
year=2005; stryear=num2str(year);
first_day=091;
last_day=120;
jd=first_day:last_day; jd=jd(:);
%strjd=num2str(jd); 

for ij=jd(1):jd(end)
if length(num2str(ij))==1
    strjd(ij,:)=['00' num2str(ij)];
elseif length(num2str(ij))==2
    strjd(ij,:)=['0' num2str(ij)];
else
    strjd(ij,:)=num2str(ij);
end
end

% Time in day
%hour=0:23;
%for ji=1:length(hour)
%    if length(num2str(ji))==1
%    strhour(ji,:)=['0' num2str(ji)];
%    else
%        strhour(ji,:)=num2str(hour(ji));
%    end
%end

hour=0:1:23; hour=hour(:);
strhour=num2str(hour);
indzero=find(hour==0)
induno=find(hour==1);
inddos=find(hour==2);
indtr=find(hour==3);
indcua=find(hour==4);
indcinc=find(hour==5);
indsei=find(hour==6);
indsiet=find(hour==7);
indoch=find(hour==8);
indnue=find(hour==9);
 strhour(indzero,:)=['00'];
 strhour(induno,:)=['01'];
 strhour(inddos,:)=['02'];
 strhour(indtr,:)=['03'];
 strhour(indcua,:)=['04'];
 strhour(indcinc,:)=['05'];
 strhour(indsei,:)=['06'];
 strhour(indsiet,:)=['07'];
 strhour(indoch,:)=['08'];
 strhour(indnue,:)=['09'];

min=0:20:40; min=min(:);
strmin=num2str(min);
indzero=find(min==0)
    strmin(indzero,:)=['00'];
    
%load XI.dat 
%load YI.dat

%l=(999.9*ones([1813,2]));



%tmp=[];

%for ji=numero de archivos;
 for ii=091:120            % Julian Day
     for jj=1:length(hour)          % Hours
         for kk=1:length(min)    % Minutes
         
 wera_crandon_rad = ['/home/martinez/codar/kl/keylnewcomp/wercranrad'];

 filename = [wera_crandon_rad '/' stryear strjd(ii,:) strhour(jj,:) strmin(kk,:) '_cdn.RAD']; 
 eval(['!./List_Radial ' filename]);

%load temp.dat
%eval(['!rm ',wera_crandon_rad,'/',stryear,strjd(ii,:),strhour(jj,:),strmin(kk,:),'_cdn.RAD']);
end
end
 end

