pro plot_ssl, code, all=all, year=year, big=big
;+
;NAME:
;	plot_ssl
;PURPOSE:
;	To plot the SSL results.
;		0. Plots of measured exposure levels
;		1. Plots of SXT temperatures
;		2. Plots of #/duration of exposures through different filters
;		3. Plots of percentage of data received
;		4. Plots of average/Max SXS1,SXS2,HXT-Low,RBM counting rates
;SAMPLE CALLING SEQUENCE:
;	plot_ssl
;	plot_ssl, [0,1]		;only display the temperature plots
;	plot_ssl, /big
;	plot_ssl, /all
;OPTIONAL INPUT:
;	code	- A boolean array saying which plots to make. 
;			code(0) = 1 says make plots of measured exposure levels
;			code(1) = 1 says make plots of SXT temperatures
;			code(2) = 1 says make plots of #/duration of exposures 
;			            through different filters
;			code(3) = 1 says make plots of percentage of data 
;				    received
;			code(4) = 1 says make plots of average SXS1,SXS2,
;				    HXT-Low,RBM counting rates
;OPTIONAL KEYWORD INPUT:
;	all	- If set, then make plots of everything
;	big	- If set, then plot "Temperatures", "percent data received"
;		  and "wbs/hxt counting rates" on one plot per page instead
;		  of 4 plots per page.
;	year	- If set, then put the year on the x labels
;HISTORY:
;	Written May-92 by M.Morrison
;V1.2	 1-May-93 (MDM) 
;V2.0	25-Oct-93 (MDM) - Made into a procedure
;			- Added header information
;	13-Dec-94 (MDM) - Modified header information (described "code")
;-
;
progver = 'PLOT_SSL.PRO  Ver 2.0  25-Oct-93'
;
common plot_ssl_blk1, data
;
if (n_elements(data) eq 0) then rd_ssl, '15-sep-91', !stime, data
x = int2secarr(data)
ref_tim = data(0)
xrange = [0, max(x)]
;
qbig = keyword_set(big)
if (keyword_set(all)) then code = intarr(10)+1
if (n_elements(code) eq 0) then begin
    code = intarr(10)
    print, 'All plots are made as a function of the date over the mission'
    yesnox, 'Make plots of measured exposure levels?                        ', ans, 'Yes'	& code(0) = ans
    yesnox, 'Make plots of SXT temperatures?                                ', ans, 'Yes'	& code(1) = ans
    yesnox, 'Make plots of #/duration of exposures through different filters', ans, 'Yes'	& code(2) = ans
    yesnox, 'Make plots of percentage of data received                      ', ans, 'Yes'	& code(3) = ans
    yesnox, 'Make plots of average SXS1,SXS2,HXT-Low,RBM counting rates?    ', ans, 'Yes'	& code(4) = ans
end
if (n_elements(code) lt 5) then code = [code, intarr(10)]	;make it long enough
;
;-------------------- Exposure duration plots
;
if (code(0)) then for i=0,31 do begin
    ss = where(data.n_expdur(i) ne 0, count)
    if (count gt 1) then begin
	x = data(ss)
	y = data(ss)
	!p.multi = [0,1,3]
	!p.charsize = 1.5
	exp_expdur = gt_mbe(i,/conv)
	tit = 'MBE = ' + strtrim(i,2) + ' (' + gt_mbe(i,/conv,/str) + 'millisec)'
	for iloop=0,1 do begin
	     case iloop of
		0: begin & yrange = [min(y.min_expdur(i)/1000.), max(y.max_expdur(i)/1000.)] & ytit='Expdur (msec) Full Range' & end
		1: begin & yrange = [exp_expdur*0.9, exp_expdur*1.1]                         & ytit='Expdur (msec) +/- 10%' & end
	     endcase
	    utplot, x, y.avg_expdur(i)/1000., ref_tim, xrange=xrange, yrange=yrange, psym=-2, title = tit, ytit=ytit, year=year
	    outplot, x, y.min_expdur(i)/1000., ref_tim, linestyle=2
	    outplot, x, y.max_expdur(i)/1000., ref_tim, linestyle=2
	end
	;
	utplot, data, data.n_expdur(i), ref_tim, xrange=xrange, ytit='# of expos/24 hrs', year=year
	plottime, 0, 0, progver & plottime & pprint & pause
    end
end
;
;-------------------- Temperature plots
;
if (code(1)) then begin
    !p.charsize = 1.2
    if (qbig) then !p.multi = 0 else !p.multi = [0,2,2]
    for i=0,13 do begin
	x = data
	y = data.avg_temp_hk(i)
	ss = where((y ne 0) and (y ne 255), count)
	y1 = gt_temp_hk(data.avg_temp_hk, i, tit=tit)
	y2 = gt_temp_hk(data.min_temp_hk, i)
	y3 = gt_temp_hk(data.max_temp_hk, i)
	;;yrange = [min(y2(ss)), max(y3(ss))]
	yrange = [min(y1(ss))-5, max(y1(ss))+5]
	utplot, x, y1, ref_tim, xrange=xrange, yrange=yrange, psym=-2, title = tit, year=year
	outplot, x, y2, ref_tim, linestyle=2
	outplot, x, y3, ref_tim, linestyle=2
	if (((i mod 4) eq 3) or qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    end

    y1 = gt_temp_ccd(data.avg_temp_ccd)
    y2 = gt_temp_ccd(data.min_temp_ccd)
    y3 = gt_temp_ccd(data.max_temp_ccd)
    tit = 'CCD Temperature (mailbox)
    for iloop=0,1 do begin
	case iloop of
	    0: yrange = [min(y2(ss)), max(y3(ss))]
	    1: yrange = [-22, -18]
	endcase
	utplot, x, y1, ref_tim, xrange=xrange, yrange=yrange, psym=-2, title = tit, year=year
	outplot, x, y2, ref_tim, linestyle=2
	outplot, x, y3, ref_tim, linestyle=2
	if (qbig and (iloop eq 0)) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    end
    plottime, 0, 0, progver & plottime & pprint & pause
end

;-------------------- Number and duration of exposures through different filter plots
;
if (code(2)) then begin
    for i=0,12 do begin
	x = data
	y1 = data.num_expos(i)
	y2 = data.dur_expos(i)/1000./60.	;convert from millisec to minutes
	tit = gt_ssl_explab(i)
	!p.charsize = 1.2
	!p.multi = [0,1,2]
	utplot, x, y1, ref_tim, xrange=xrange, psym=-2, title = tit, ytitle = 'Number of exposures', year=year
	utplot, x, y2, ref_tim, xrange=xrange, psym=-2, title = tit, ytitle = 'Minutes of exposure', year=year
	plottime, 0, 0, progver & plottime & pprint & pause
    end
end
;
;-------------------- Percentage of data received plots
;
if (code(3)) then begin
    !p.charsize = 1.1
    if (qbig) then !p.multi = 0 else !p.multi = [0,2,2]
    x = data
    y1 = (data.pfi_sernum(1)-data.pfi_sernum(0)+1)>1	;not quite right - really want first serial number of next day
    y2 = data.pfi_fl(1)
    y3 = data.pfi_qt(1)
    y4 = (y2+y3)*100./y1
    y5 = data.pfi_hi_cad
    utplot, x, y1, ref_tim, xrange=xrange, title='# PFI (by serial num)', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, y2, ref_tim, xrange=xrange, yrange=[0,max([y2,y3])], title='Received PFI ORs - Flare=solid,Quiet=dash', linestyle=0, year=year
    outplot, x, y3, ref_tim, linestyle=2
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, y4, ref_tim, xrange=xrange, title = 'Percent images received', yrange=[0,120], year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, y5, ref_tim, xrange=xrange, psym=10, title='# PFI with high cadence', year=year
    plottime, 0, 0, progver & plottime & pprint & pause

    y1 = (data.ffi_sernum(1)-data.ffi_sernum(0)+1)>1	;not quite right - really want first serial number of next day
    y2 = data.ffi_qt
    y4 = y2*100./y1
    y5 = data.ffi_buff
    utplot, x, y1, ref_tim, xrange=xrange, title='# FFI (by serial num)', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, y2, ref_tim, xrange=xrange, title='Received FFI - Quiet=solid', linestyle=0, year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, y4, ref_tim, xrange=xrange, title = 'Percent images received', yrange=[0,120], year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, y5, ref_tim, xrange=xrange, psym=10, title='# FFI buffer dumps (patrol images)', year=year
    plottime, 0, 0, progver & plottime & pprint & pause
end

;-------------------- Average SXS1,SXS2,HXT-Low,RBM counting rate plots
;
if (code(4)) then begin
    !p.charsize = 1.1
    if (qbig) then !p.multi = 0 else !p.multi = [0,2,2]
    x = data
    utplot, x, data.avg_sxs1, ref_tim, xrange=xrange, title='Average SXS1', ytit = 'Cnts/sec', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, data.avg_sxs2, ref_tim, xrange=xrange, title='Average SXS2', ytit = 'Cnts/sec', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    ;utplot, x, data.avg_hxt_sum_l, ref_tim, xrange=xrange, title='Average HXT Low Chan', ytit = 'Cnts/sec'
    print, 'Only plotting after Dec-91 for HXT because of change in roadmap definition
    utplot, x(75:*), data(75:*).avg_hxt_sum_l, ref_tim, xrange=xrange, title='Average HXT Low Chan', ytit = 'Cnts/sec', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, data.avg_rbmsd, ref_tim, xrange=xrange, title='Average RBMSD', ytit = 'Cnts/sec', year=year
    plottime, 0, 0, progver & plottime & pprint & pause

    utplot, x, data.max_sxs1, ref_tim, xrange=xrange, title='Maximum SXS1', ytit = 'Cnts/sec', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, data.max_sxs2, ref_tim, xrange=xrange, title='Maximum SXS2', ytit = 'Cnts/sec', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    ;utplot, x, data.max_hxt_sum_l, ref_tim, xrange=xrange, title='Maximum HXT Low Chan', ytit = 'Cnts/sec'
    utplot, x(75:*), data(75:*).max_hxt_sum_l, ref_tim, xrange=xrange, title='Maximum HXT Low Chan', ytit = 'Cnts/sec', year=year
    if (qbig) then begin & plottime, 0, 0, progver & plottime & pprint & pause & end
    utplot, x, data.max_rbmsd, ref_tim, xrange=xrange, title='Maximum RBMSD', ytit = 'Cnts/sec', year=year
    plottime, 0, 0, progver & plottime & pprint & pause
end

end
