;+
; NAME:
;	QUEUE_STUFF
; PURPOSE:
;	Plot queue pages/sectors, DP bit rate and Ca XIX lightcurve
;	against time for diagnostic of BCS Queue Memory
; CALLING SEQUENCE:  
;	.run queue_stuff
; INPUTS:
;	none
; OUTPUTS:
;	graphic output
; RESTRICTIONS:
;	Must be run after CPU_DIAG
; PROCEDURE:
;
; MODIFICATION HISTORY:
;	RDB  Autumn, 91
;	RDB  11-May-94	Remapped the dp modes and bitrates for more compact 
;			plot, added SAA, Night and DP Flare
;	RDB  13-May-94	Added HVMON plot; option to only do 2nd plot...
;       RDB  30-Aug-94  Read roadmap if not present
;
;-

print,'**** Remember to run CPU_DIAG first!!!!

clearplot
clear_utplot

!x.range = x_hr_range
!p.charsize=1.5

yesnox,'* Only do the DP Mode/Rate plot',ansq
if ansq then begin
  if !d.name eq 'PS' then device,/landscape
  goto,second_plot
endif

ps_long

!p.multi = [0,1,3]
plot,ttime(ss64),out_pgs,title='Queue Read and Write Pointers
oplot,ttime(ss64),in_pgs,color=210

;;plot,ttime(ss64),qfree,title='Queue Free',psym=3

second_plot:
dpmode = dpmode_rmap((dp_sync.dp_mode and '1f'x),dpms)	;0=msb
rr = [0,1,2,0,3]		;remap dprate
dprate = rr((dp_sync.dp_rate)/32)

plot,ttime,dpmode,title='DP Mode & Bit Rate, SAA & Night, and DP Flare', $
	ystyle=1, psym=3, $
	yrange = [0,16], yticks=16, yminor=-1, yticklen=0.005, 	$
	ytickname=[' ',dpms,' ','Night ','SAA ','DP flare ',' ','LOW ','MED ','HIGH ',' ']
oplot,ttime,dprate+12,psym=3

oplot,ttime,dp_flare/3.+11		;,psym=3

;	plot expected times of SAA and Night
if max([tesaa]) gt -1 then  $
  for j= 0,n_elements(tesaa)-1 do oplot,[tesaa(j),txsaa(j)],[10,10],thick=3
if max([tonit]) gt -1 then  $
  for j= 0,n_elements(tonit)-1 do oplot,[tonit(j),today(j)],[9,9],thick=4
;	overplot actual status from spacecraft
;color=255 & if !d.name eq 'X' then color=210
oplot,ttime(wrbm),rbm(wrbm)+9-.3,psym=3			;,color=color
oplot,(ttime(ss64))(wnight),night(wnight)+8-.3,psym=3	;,color=color

;	BCS HV monitor
hvmon  = fix((dp_sync.hv_mon(0)-50)/170.)
whvmon = where(hvmon eq 1)	;plot where on!
oplot,ttime(whvmon),hvmon(whvmon)+9.+.3,psym=3,color=150

if ansq then goto,endit

;		do lightcurve for spectral data
if n_elements(roadmap) le 1 then begin
  yesnox,'* No roadmap, read it',ansrr
  if ansrr then rd_roadmap,ffq(where(strlen(ffq) gt 0)),roadmap
endif
rttime = roadmap.time/3600./1000. + (roadmap.day - roadmap(0).day)*24.

qq = where(((roadmap.blockid eq 0) or (roadmap.blockid eq 1)) and 	$
	(rttime ge !x.range(0)) and (rttime le !x.range(1)))
integ_time = roadmap.dgi*0.125;*(roadmap.controltally+1)		;******
cymax = max(roadmap(qq).total_cnts(2)*10./integ_time(qq))
if cymax gt 2000 then begin
  print,'Maximum value is',cymax
  read,'Enter cymax: ',cymax
  endif

ymax = (cymax +35)/25*25

plot,rttime(qq),roadmap(qq).total_cnts(2)*10./integ_time(qq), $ ;(roadmap(qq).dgi*0.125),	$
	yrange=[0,ymax],psym=1,	$
	xtitle='UT',title='Ca XIX  Total_counts Lightcurve',		$
	ytitle='Counts/sec'	;DGI'	;,xrange=x_hr_range


endit:
xyouts,0.9,0.05,/device,filnam+ext,siz=1.2	;,/normal

!p.charsize=0
!x.range=0
ps_reset

end
