function bad_id = File_Cleaner_Vad(snr, rws,azimuth,firstgate,Max_Velocity,SNR_CutOff)
% ==================================================================
%
%	MATLAB m-file for Filtering Lidar Data (Radial Velocity, BackScatter)
%				
%				Jason Porter
%				ASU
%			    Dec 2002
%
%	INPUT:	 Data, Header, Sweep ID
%
%	OUTPUT:	 Filtered Data
%
% ========================================================

[na,nr]=size(rws);
bad_id=zeros(na,nr);
bad_id(:,1:firstgate-1)=1;
% Determine data that approximate ~A*cos(azimuth+B) over fixed elevations

for j=firstgate:nr
    [estimates, model] = fitvad(azimuth(:,j),rws(:,j));
    [sse, FittedCurve] = model(estimates);
    if sse>10
       bad_id(:,j)=1;
    end
end

%hard target
for j=1:na
    meanSNR=mean(snr(j,:));
    [locs pks]=peakseek(snr(j,:),5,5*meanSNR);
    if ~isempty(locs)
    hard=locs(1);
        bad_id(j,hard:end)=1;
    end
end
uu=find(snr < SNR_CutOff | abs(rws) > Max_Velocity);
bad_id(uu)=1;
return





