; Program to screen SBUV Version 8 data for outliers
; by using a nearest neighbor test.
;
; Use read_compv8_sg.pro to read in a day of data.
;
; resqc Residual quality quantity for measurements
; eflag Profile error flags for measurements
; gmt Universal time of measurement in seconds
; lat Latitude of measurements
; lon Longitude of measurements
; ppmv 15 profile mixing ratios for each measurement
; Determine which profiles are good.
w=where(eflag mod 10 eq 0 and resqc lt 0.15,nw)
; Determine which good profiles have good nearby profiles.
ws=where(abs(gmt(w(1:*))-gmt(w(0:*))-48) le 16 and $
abs(gmt(w(2:*))-gmt(w(1:*))-48) le 16 and $
abs(lat(w(0:*))-lat(w(2:*))) lt 10. and $
abs(lon(w(0:*))-lon(w(2:*))) lt 8.,nws)
; Compute the product of the differences of the profiles
; with the adjacent two for the 0.7 mbar mixing ratio
PD1=(ppmv(1,w(ws+1))-ppmv(1,w(ws)))*$
(ppmv(1,w(ws+1))-ppmv(1,w(ws+2)))
; Compute the product of the differences of the profiles
; with the adjacent two for the 2 mbar mixing ratio
PD4=(ppmv(4,w(ws+1))-ppmv(4,w(ws)))*$
(ppmv(4,w(ws+1))-ppmv(4,w(ws+2)))
; Determine which profiles have large differences with
; adjacent profiles
wd=where(PD1 gt 0.12 or $
(PD1 gt 0.08 and PD4 gt .15 and $
resqc(w(ws+1)) gt .08),nwd)
; Plot the 0.7 mbar mixing ratios
plot, lat(w),ppmv(1,w),psym=1
; If the screen tags any profiles
if nwd gt 0 then begin
; Calculate the indices of the screened profiles
wbad=w(ws(wd)+1)
; Overplot the screened 0.7 mbar mixing ratios
oplot, lat(wbad),ppmv(1,wbad),psym=2,symsize=2,color=222
endif
END