function METwout=QC_METw(METw,filename)
%QC METw:

% (1) Time-series plot
% This is used to manually NaN data, for example, if the MET wind
%  sensor started reporting bad data.

dn = datenum([1970 1 1]);

 figMETw = figure('Name','METw','Units','inches','Position',[0 0 11 8.5],...
     'CloseRequestFcn', @(h,e) fprintf(1, 'Not allowed, use "close METw force"\n.'));
 ha = tight_subplot(2,1,0.075,0.2,0.1);
 g = get(ha,'Position');
 set(ha,'Box','on','NextPlot','add');
 
 axes(ha(1));
   plot(METw(:,1),METw(:,2),'.');
   ylabel(['[' char(181) 'True]']);
   title('Wind Direction');
   fUnNaN=@qcWG_UnNaNcb;
   fNaN=@qcWG_NaNcb;
   ha(1).UserData=zeros(length(METw(:,2)),1); 
   
   uicontrol('Units','normalized','Style','pushbutton','String','NaN',...
     'Position',[g{1}(1)+g{1}(3)-0.08 g{1}(2)+g{1}(4)+0.003 .08 .03],...
     'Callback',{fNaN,METw(:,1),METw(:,2),ha(1)});
   uicontrol('Units','normalized','Style','pushbutton','String','Un-NaN',...
     'Position',[g{1}(1)+g{1}(3)-0.16 g{1}(2)+g{1}(4)+0.003 .08 .03],...
     'Callback',{fUnNaN,METw(:,1),METw(:,2),ha(1)});
 
 axes(ha(2));
   plot(METw(:,1),METw(:,3),'.-');
   ylabel(['[m s^-^1]']);
   title('Wind Speed');
   ha(2).UserData=zeros(length(METw(:,2)),1);
   
   uicontrol('Units','normalized','Style','pushbutton','String','NaN',...
     'Position',[g{2}(1)+g{2}(3)-0.08 g{2}(2)+g{2}(4)+0.003 .08 .03],...
     'Callback',{fNaN,METw(:,1),METw(:,3),ha(2)});
   uicontrol('Units','normalized','Style','pushbutton','String','Un-NaN',...
     'Position',[g{2}(1)+g{2}(3)-0.16 g{2}(2)+g{2}(4)+0.003 .08 .03],...
     'Callback',{fUnNaN,METw(:,1),METw(:,3),ha(2)});
 
 set(ha,'XLim',[min(METw(:,1)) max(METw(:,1))] + [-1 1]*0.1);
 linkaxes(ha,'x');

 sprintf('Paused, Hit any key to save data and continue')
 pause;
 for n1=1:2
     bool=zeros(size(METw,1),1);
     for n=1:size(METw,1)
         samp=ha(n1).UserData(n,:);
         f=samp>0;
         if sum(f)==0
             bool(n)=0;
             continue
         end
         samp=samp(f);
         if samp(end)==2
             bool(n)=0;
         else
             bool(n)=1;
         end
     end
     filtered=METw(:,n1+1);
     filtered(bool==1)=NaN;
     METw(:,n1+1)=filtered;
 end

 close METw force
 
 METwout=METw;
 
%save QC'd .csv file
 time = (METw(:,1) - dn) * 86400*1000;
 fid = fopen(filename,'w');
 fprintf(fid, ['Time[GMT/Unix*1000],windDir[True],windSpeed[m/s]']);
 for n=1:size(METw,1)
   fprintf(fid, '\n%.0f,%.1f,%.1f', [time(n) METw(n,2:3)]);
 end
 fclose(fid);
 clear time fid n;

clear ha figMETw g;

end