;+
; NAME:
;     QUICKSTRAY
; PURPOSE:
;     look at last few days of SLS data for new leaks
; CATEGORY:
; CALLING SEQUENCE:
;     quickstray, index, data, days=-28 
; INPUTS:
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;     side, output image size
;     qstop, stops for debugging
;     days, lookback time in days (negative!)
;       (default is 14)
; OUTPUTS:
;     index, the index variable for WDBAN images
;     data, the total counts for the same (note - we don't get
;       these during bakeouts, apparently)
; COMMON BLOCKS:
; SIDE EFFECTS:
;     makes a plot in the current window
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     5-mar-98, written (HSH)
;    18-jul-98, converted to procedure (HSH)
;    13-aug-98, changed hard paths to environment paths (DA)
;    22-aug-98, revised same (HSH)
;    17-apr-1999 - S.L.Freeland - subselect recent 14 days
;     9-may-1999, incorporated new WDBAN monitor images, along
;                 with an empirical factor to match (HSH)
;     6-aug-1999, fixed bug in xrange (HSH)
;    21-oct-1999, hack to include both channels of bifurcation in NaBan,
;                 top two channels in WdBan trifurcation.  Also adjusted
;                 empirical scaling factors.  (DMcK)
;    19-apr-2000, rehacked the "other" image plotting (HSH, sorry it's ugly)
;    28-sep-2000, added output and "days" keyword (HSH, AT)
;     7-nov-2001, moved Y range and added dotted lines so we don't miss any
;                 odd points (HSH)
;-
pro quickstray, index_out, data_out, side = side, qstop = qstop, days=days
if n_elements(days) eq 0 then days = -14
if days gt 0 then days = -days
if n_elements(side) eq 0 then side = 512 
wdef,0,side
sfrs=newfiles(/sfr)
infil=sel_filetimes(reltime(days=days),reltime(/now),sfrs)
rd_roadmap,infil,rm
rm1 = rm
ss = where((gt_filta(rm1) eq 2 or gt_filta(rm1) eq 5) $
  and gt_filtb(rm1) eq 1 and $
  gt_percentd(rm1) eq 100 and gt_expmode(rm1) eq 1 and gt_res(rm1) eq 2)
rd_xda,infil,ss,index,data
naban = where(gt_filta(index) eq 2, n_naban)
wdban = where(gt_filta(index) eq 5, n_wdban)
tots = reform(total(total(sxt_decomp(data),1),1))

if n_naban ne 0 then begin
  nagood = where(tots(naban) gt 1e8)
  naother= where(tots(naban) gt 5e7 and tots(naban) lt 1e8, nanumb) ;DMcK 99oct21
endif

if n_wdban ne 0 then begin
  wdgood = where(tots(wdban) gt 3.5e7)
  wdother= where(tots(wdban) gt 2.0e7 and tots(wdban) lt 3.5e7, wdnumb) ;DMcK 99oct21
endif

if n_naban ne 0 then begin
  utplot,index(naban(nagood)),tots(naban(nagood)),index(0),psym=2,$
    yr=[1e8,2e8],tit='Stray light monitor (NABAN)',$
    xr=int2secarr(index)
endif else begin
  utplot,index(wdban(wdgood)),tots(wdban(wdgood)),index(0),psym=-1,$
    yr=[4.5e7,5.5e7],tit='Stray light monitor (WDBAN)',$
    xr=int2secarr(index),lines=1
endelse

index_out = index(wdban(wdgood))
data_out = tots(wdban(wdgood))

;if nanumb ne 0 then $
;  outplot,index(naban(naother)),tots(naban(naother))*1.84,psym=2

;factor = 1.29e8/4.29e7*1.015 ; empirical factor to plot WdBan and NaBan
                             ; on same scale
factor = 3.098  ; updated factor, DMcK 99oct21

;outplot,index(wdban(wdgood)),tots(wdban(wdgood))*factor,psym=1

;if wdnumb ne 0 then $
  outplot,index(wdban(wdother)),tots(wdban(wdother))*1.717*factor,psym=1
; 1.717 is empirical factor to bring two channels of the
; WdBan trifurcation onto the same plotting scale...DMcK 99oct21

timestamp
if n_elements(qstop) ne 0 then stop
end

