function BogLine=QC_BogLine(Position,filename)
%------------%
load('CaCoast.mat')
dn = datenum([1970 1 1]);

%QC BogLine:

% (1) Lat-Lon Scatter plot
% This is used to manually identify BOG Line data

 BogLine = zeros(size(Position(:,1)));
 figPos = figure('Name','BL','Units','inches','Position',[0 0 11 8.5],...
     'CloseRequestFcn', @(h,e) fprintf(1, 'Not allowed, use "close BL force"\n.'));
 ha = tight_subplot(1,1,0.075,0.2,0.1);
 g = get(ha,'Position');
 set(ha,'Box','on','NextPlot','add');
 axes(ha(1));
   scatter(Position(:,2),Position(:,3),7,'filled');
   plot(CaCoast.lon,CaCoast.lat,'k','LineWidth',2);
   plot(-122.02203,36.75060,'k.','MarkerSize',10); %M1
   plot(-122.378,36.697,'k.','MarkerSize',10); %M2
   plot(-121.847,36.797,'k.','MarkerSize',10); %C1
   axis([min(Position(:,2))-0.2,max(Position(:,2))+0.2,...
     min(Position(:,3))-0.2,max(Position(:,3))+0.2])
   ylabel(['[' char(186) 'E]']);
   title('Position');
   fUnNaN=@qcWG_UnBogLineCB;
   fNaN=@qcWG_BogLineCB;
   ha(1).UserData=zeros(length(Position(:,2)),1); 
   
   uicontrol('Units','normalized','Style','pushbutton','String','Bog Line',...
     'Position',[g(1)+g(3)-0.08 g(2)+g(4)+0.003 .08 .03],...
     'Callback',{fNaN,Position(:,2),Position(:,3),ha(1)});
   uicontrol('Units','normalized','Style','pushbutton','String','Un-BOG Line',...
     'Position',[g(1)+g(3)-0.2 g(2)+g(4)+0.003 .08 .03],...
     'Callback',{fUnNaN,Position(:,2),Position(:,3),ha(1)});
 
 sprintf('Paused, Hit any key to save data and continue')
 pause;
 
 bool=zeros(size(Position,1),1);
 for n=1:size(Position,1)
     samp=ha.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
 
 close BL force
 
 BogLine=bool;

 %BOG Line
  time = (Position(:,1) - dn) * 86400*1000;
  fid = fopen(filename,'w');
  fprintf(fid, ['Time[GMT/Unix*1000],BogLine[N=0,Y=1]']);
  for n=1:size(Position,1)
    fprintf(fid, '\n%.0f,%.0f', [time(n) BogLine(n)]);
  end
  fclose(fid);
  clear time fid n ha g;

end