;
;+
;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
;-
;
if (n_elements(sls) eq 0) then begin
    rd_sls, '1-oct-92', !stime, index_s, sls
    ;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
;
skip:
yesnox, 'Display the lower curve data in image form?', ans, 'Yes'
if (ans) then begin
    ss_sls = where(tot_avg lt 330)
    dd = sls(ss_sls).avg_arr
    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+20
    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

end
