function yf = filterhan(x,n)

% hanning filtering, by W. Huang, 6/99
% x = input data series, n = number of points in hannging filter
% n= 1,3,5,7 ...;
% no filter action for missing data ' NaN' or '99.99'
% cutoff frequency = (n-1)/2; eg, 12 hour filtering need 25 hourly points
lend = length (x);
x0=x;
ist = (n-1)/2; iend = length(x)-(ist);

ilog=1;

for i= ist+1:iend;
   for k=i-ist:i+ist
      
   %temp=x0(k);
   if x0(k)== NaN or x0(k)==99.99
      ilog =0;
   end
   end

if ilog==1;
   x(i)= sum(x0(i-ist:i+ist).*hanning(n))/sum(hanning(n)); 
end;
    ilog = 1;
    yf=x;
    
end
    
    
    
    
    
    
   
   

