;
;+
;NAME:
;	plot_sls
;PURPOSE:
;	To plot the SXT Scattered Light engineering data 
;CALLING SEQUENCE:
;	.run plot_sls
;METHOD:
;	Dark frame images are taken with the narrow band analysis filters.
;	Since the leak after 17-Nov-92 entrance filter was intense enough
;	to show signal at the CCD even with the CCD closed, we use this
;	data to monitor the size of the aperature in the entrance filter.
;	The values plotted are the average signal for the whole FFI image.
;	The HR images are converted to the equivalent signal for a QR image.
;	The 70 DN "fat zero/dark current" of the QR images is still in the
;	values which are plotted.
;	There are two sets of values because of the difference in the 
;	stopped position of the shutter blade.  Two of the four positions 
;	allow more light to leak around the blade.
;		NaBan/Open  Half Dark C   2     1.0  512x512
;		NaBan/Open  Qrtr Dark C   2     1.0  256x256
;HISTORY:
;	Written Winter, 1992 by M.Morrison
;	22-May-93 (MDM) - Added document header
;	28-May-93 (MDM) - Modified header
;V2.0	30-Sep-93 (MDM) - Changed to plot in units of QR DN
;V2.1	25-Oct-93 (MDM) - Added option to display in image form
;V2.2	15-Dec-93 (MDM) - Added code to remove the 4-NOV-93  08:21:32'
;			  datapoint
;V2.3   25-Nov-95  (MW) - Added code so image form goes past 2nd
;			  entrance filter failure (marked by ***)
;V2.4   09-Mar-98  (MW) - Even more code so image form goes past the
;                         Jan-98 filter failure (marked by ***). Note
;                         that the grayscale image of the data between
;                         the 1st and 2nd failures is arbitrarily
;                         multiplied by 2 to show up better.
;-
;
if (n_elements(sls) eq 0) then begin
    rd_sls, '1-oct-92', !stime, index_s, sls
;    rd_sls, '23-mar-93', !stime, index_s, sls ; Use this if sls93_12 is bad
    ;for i=0,n_elements(index_s)-1 do if (gt_res(index_s(i)) eq 2) then sls(i).avg_arr = (sls(i).avg_arr-69.1)/4 *2 + 30.7 - 15
											;*2 because the different integration
											;time because of readout time
											;-15 fudge factor
    print, 'PLOT_SLS: Converting from HR to QR DN where necessary'
    for i=0,n_elements(index_s)-1 do if (gt_res(index_s(i)) eq 1) then sls(i).avg_arr = (sls(i).avg_arr-30.7+15)*4/2 + 69.1
    print, 'PLOT_SLS: Removing datapoints where CCD is not cooled'
    ss = where(gt_temp_ccd(index_s) lt -20)
    index_s = index_s(ss)
    sls = sls(ss)
    ;
    print, 'PLOT_SLS: Removing bad datapoint on 4-NOV-93  08:21:32'
    ok = bytarr(n_elements(index_s))+1
    ok( tim2dset(index_s, '4-NOV-93  08:21:32')) = 0	;remove this point
    ss = where(ok)
    index_s = index_s(ss)
    sls = sls(ss)
end
;
;
tot_avg = fltarr(n_elements(index_s))
for i=0,n_elements(index_s)-1 do tot_avg(i) = total(sls(i).avg_arr)/51
;
utplot, index_s, tot_avg, psym=2, /ynozero, ytit = '"Raw" QR DN'
plottime, 0, 0, 'PLOT_SLS  Ver 2.2' & plottime
;
print, 'Last plot point:', fmt_tim(index_s(n_elements(index_s)-1)); ***
;

;
skip:
yesnox, 'Display the lower curve data in image form?', ans, 'Yes'
if (ans) then begin
    ss_failure2 = 3399                                ; ***
    ss_failure3 = 6760				      ; ***
    ss_sls1 = where(tot_avg(0:ss_failure2-1) lt 330)  ; ***
    ss_sls2 = where(tot_avg(ss_failure2:ss_failure3-1) lt 1000)   ; ***
    ss_sls2 = ss_sls2+ss_failure2                     ; ***
    ss_sls3 = where(tot_avg(ss_failure3:*) lt 1500)   ; ***
    ss_sls3 = ss_sls3+ss_failure3
    ss_sls = [ss_sls1, ss_sls2, ss_sls3]              ; ***
    dd = sls.avg_arr*.209                             ; ***
    dd(*,ss_sls1) = dd(*,ss_sls1)*2.0                 ; ***
    dd = dd(*,ss_sls)                                 ; ***
    ii = index_s(ss_sls)
    nn = 800
    dd = congrid(dd, 51, nn)			;force to be 800 line high
    sfact = n_elements(ii)/float(nn)	;scaling factor
    ;;wdef, 0, 51*10+200, nn+20
    wdef, 0, nn+20, nn+30
    tvscl, rebin(dd, 510, nn), 200, 20
    for i=0,nn-100,100 do xyouts, 10, i+20, /dev,    $
                          gt_day(ii(i*sfact), /str), size=2
    xyouts, 10, nn+20-25, /dev, gt_day(ii((nn-1)*sfact), /str), size=2
    xyouts, 200, 4, /dev, 'Left Edge of CCD', size=1.6
    xyouts, 51*10+200, 4, /dev, 'Right Edge of CCD', size=1.6, align=1
    plots, [200,51*10+200], [20,20], /dev
    plots, [1,1]*200,         [20,20+nn], /dev
    plots, [1,1]*(200+10*51), [20,20+nn], /dev
end ;if-ans loop

end
