;
;+
;NAME:
;	plot_sld
;PURPOSE:
;	To plot the SXT dark current signal after the Nov-92 entrance filter
;	failure.  
;CALLING SEQUENCE:
;	.run plot_sld
;METHOD:
;	Dark frame images are taken with the Be x-ray analysis filter.
;	After 17-Nov-92 entrance filter failure, it was noticed that the dark
;	current signal increase dramatically.  This routine monitors that
;	increase (which decreased after a few months).
;
;	A full frame image is taken and broken up into 51 vertical strips
;	(20 columns per strip for FR, 10 for HR, and 5 for QR).  The values
;	plotted in the first plot are strip 5 and strip 0.  Strip 5 is the area
;	where the increase in the dark signal was seen.  Strip 0 is off the 
;	area where the sun hits the CCD and is a reference area.
;       The HR images are converted to the equivalent signal for a QR image.
;		Open /Al.1  Half Dark C  13    78.0  512x512
;		Open /AlMg  Qrtr Dark C  13    78.0  256x256
;HISTORY:
;	Written Winter, 1992 by M.Morrison
;	22-May-93 (MDM) - Added header information
;V1.2	 3-Sep-93 (MDM) - Added a new plot - plot each vertical strip offset
;V1.3	30-Sep-93 (MDM) - Sped up the plotting steps
;V2.0	30-Sep-93 (MDM) - Changed to plot in units of QR DN
;V2.1	12-Oct-93 (MDM) - Modified to always make the image 800 line display
;V2.2	18-Feb-94 (MDM) - Corrected labeling of the temperature plot
;			  (it was labeled as TEC hot end and was really the
;			  center of the metering tube).
;-
progver = 'PLOT_SLD  Ver 2.2'
;
if (n_elements(sld) eq 0) then begin
    rd_sld, '1-oct-92', !stime, index_d, sld
    ;for i=0,n_elements(index_d)-1 do if (gt_res(index_d(i)) eq 2) then sld(i).avg_arr = (sld(i).avg_arr-69.1)/4 + 30.7
    print, 'PLOT_SLS: Converting from HR to QR DN where necessary'
    for i=0,n_elements(index_d)-1 do if (gt_res(index_d(i)) eq 1) then sld(i).avg_arr = (sld(i).avg_arr-30.7)*4 + 69.1
    print, 'PLOT_SLD: Removing datapoints where CCD is not cooled'
    ss = where(gt_temp_ccd(index_d) lt -20)
    index_d = index_d(ss)
    sld = sld(ss)
    ;
    good = bytarr(n_elements(sld)) + 1b
    ss = sel_timrange(index_d, '8-may-93 23:54', '12-may-93 19:10')	;bad DPE=13 dark frames
    print, 'PLOT_SLD: Removing datapoints between 8-may-93 23:54 and 12-may-93 19:10'
    if (ss(0) ne -1) then good(ss) = 0b
    sld = sld(where(good))
    index_d = index_d(where(good))
end
;
;

if (keyword_set(qsld_skip)) then goto, skip

ref_time = index_d(0)
tarr = int2secarr(index_d, ref_time)

utplot, tarr, sld.avg_arr(5), ref_time, psym=-2, /ynozero, ytit='SLD Average for V.Strip 5 and 0 (QR DN)'
outplot, tarr, sld.avg_arr(0), ref_time, psym=-1
plottime, 0, 0, progver & plottime & pause
;
utplot, tarr, sld.avg_arr(0), ref_time, yrange=[min(sld.avg_arr),max(sld.avg_arr)], /ynozero, ytit='SLD Average for all V.Strips (QR DN)'
for i=1,50 do outplot, tarr, sld.avg_arr(i), ref_time
plottime, 0, 0, progver & plottime & pause
;
utplot, tarr, sld.avg_arr(0), ref_time, yrange=[60,200], /ynozero, ytit='SLD Average for all V.Strips (QR DN)'
for i=1,50 do outplot, tarr, sld.avg_arr(i)+i*1.5, ref_time
xyouts, .6, .20, 'Vertical Strip on Left Side of CCD', /norm
xyouts, .6, .92, 'Vertical Strip on Right Side of CCD', /norm
plottime, 0, 0, progver & plottime & pause
;
ss = where(index_d.sxt.temp_hk(0) ne 0)
x = index_d(ss)
;;y = index_d(ss).sxt.temp_hk(0)
;;y = ahk_conv(y, 64+18+0)
y = gt_temp_hk(index_d(ss), 0, tit=ytit)
xrange = !x.crange
!p.multi=[0,1,2]
utplot, tarr, sld.avg_arr(5), ref_time, xrange=xrange, psym=-2, /ynozero, ytit='SLD Average for V.Strip 5 (QR DN)'
utplot, x, y, ref_time, xrange=xrange, psym=-2, /ynozero, ytit=ytit + ' Temp (C)'
plottime, 0, 0, progver & plottime & pause
!p.multi = 0

skip:
yesnox, 'Display these data in image form?', ans, 'Yes'
if (ans) then begin
    dd = sld.avg_arr
    ;;nn = n_elements(dd(0,*))
    nn = 800
    dd = congrid(dd, 51, nn)			;force to be 800 line high
    sfact = n_elements(index_d)/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(index_d(i*sfact), /str), size=2
    xyouts, 10, nn+20-25, /dev, gt_day(index_d((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
