pro plotdate, PROG, SIZE = size, DEVICE = device, DATA = data, $
        NORMAL = normal, X = x, Y = y
;+
;  Name:
;       PROCEDURE: 
;               PLOTDATE
;       PURPOSE:
;               This procedure puts the user name, calling program and system 
;               time and date in the corner of a plot.  
;       CALLING SEQUENCE:
;               plotdate, Prog, [Charsize=, Charthick=,/device,/data, /normal]
;       OPTIONAL INPUTS:
;               PROG -- Character string containing the name of the calling
;                       program (Default = 'INTERACTIVE')
;       KEYWORD INPUTS:
;               SIZE -- Specify the character size.  (Default = 0.35)
;               X, Y -- Location to put the string.  (Default is lower right 
;                       corner, depedning on the current device size).  
;               DEVICE -- If present and non-zero, X and Y are in DEVICE 
;                         coordinates.  Ignored if X, Y are not both specified.
;                         (Default = 1)
;               DATA -- If present and non-zero, X and Y are in DATA 
;                       coordinates.  Ignored if X, Y are not both specified.
;                       (Default = 0)
;               NORMAL -- If present and non-zero, X and Y are NORMALIZED
;                         coordinates.  Ignored if X, Y are not both specified.
;       NOTE: Only one of [DEVICE, DATA, NORMAL] should be specified.  For 
;             more information regarding these parameters, check documentation
;             of XYOUTS.
;       REVISION HISTORY
;               Modified from RCB::[BOHLIN.IDL]PLOTDATE.PRO 
;               90DEC22-CHANGE XYOUTS FOR V2 AND SIMPLIFY-RCB
;               Converted for general use in MOUSSE.  Keywords added, user name
;               obtained from OS rather than hard-coded.   
;               Joel D. Offenberg, HSTX, 26-Mar-93
;-

IF (n_elements(PROG) eq 0) THEN PROG = "INTERACTIVE"

USER = strupcase(getenv('USER'))

IF (keyword_set(X) AND keyword_set(Y)) THEN BEGIN
        keyck = keyword_set(NORMAL) + keyword_set(DEVICE) + keyword_set(DATA)
        IF (keych eq 0) THEN DEVICE = 1 
        IF (keych gt 1) THEN BEGIN
           message,/inf,'ERROR - Only one of [DEVICE, DATA, NORMAL] can be set'
           return
        endIF
endIF ELSE BEGIN
        X = 0.75
        Y = 0.01
        NORMAL = 1
        DEVICE = 0
        DATA = 0
endELSE

IF not(keyword_set(SIZE)) then SIZE = 0.35

xyouts,X,Y,USER+': '+PROG+'  '+STRMID(!stime,0,17),SIZE=size, $
        DEVICE=device, NORMAL=normal, DATA=data

return
end
;+
;
; NAME:
;	PLOT_RESULTS
;
; PURPOSE:
;	This is a main program for looking at the total BATSE DISCSP CRAB
;	occultation database
;
; CATEGORY:
;	BATSE, OCCULTS
;
; CALLING SEQUENCE:
;
;
; CALLS:
;       plot_ratios, get_subdirs, loc_file, plot_occs_res, legend, wdef, plotdate
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;       none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;       none
;
; KEYWORDS:
;       none
; COMMON BLOCKS:
;       none
;
; SIDE EFFECTS:
;       none
;
; RESTRICTIONS:
;       none
;
; PROCEDURE:
;       none
;
; MODIFICATION HISTORY:
;
;-
  
if n_elements(rs) eq 0 then begin
                checkvar, indir, ''
	dirs = [indir,'./','[]', get_subdirs('USER_DISK0:[richard.occults]'), $
	          get_subdirs('USER_DISK0:[ajking.occults]'), $
	          get_subdirs('/umbra/schwartz/occults'), $
	          get_subdirs('~richard/occults' ),get_subdirs('/umbra/ajking'),$
	          get_subdirs('~ajking') ]
                checkvar, infile, 'new_occ_results3.sav'
	file = loc_file( infile, path=dirs)
	if file ne '' then restore, file,/verb else message,"CAN'T FIND '+INFILE
	r = [old_results,results2,results_out]
	rs = replicate( {res,ut:0.d0,davg:fltarr(2,2),dprd:fltarr(2),$
		edges:fltarr(2,4), id:0L, cos:0.0}, n_elements(r)*4)
	rs.ut=(rebin(reform(r.gro_point,1,n_elements(r)),4,n_elements(r)))(*)
	rs.davg = reform(r.discsp_avg,2,2,n_elements(rs))
	rs.edges = reform(r.edges_d,2,4,n_elements(rs))
	rs.dprd = reform(r.discsp_pred,2,n_elements(rs))
	rs.id = reform(r.det_id_spec,n_elements(rs))
	ucoss=fltarr(4,n_elements(r))
	for i=0,n_elements(r)-1 do ucoss(0,i) = (r(i).cos_spec)(r(i).det_id_spec)
	rs.cos = ucoss(*)
	wdef,0,600,800
	wdef,1,600,800
	wdef,2,600,800
endif
symkey = [3,3,3,3,1,2,4,5,6,7]
label=string(findgen(6)*.1+.37,form='(f4.2)')+$
	' < COSINE < '+string(findgen(6)*.1+.47,form='(f4.2)')
w=where(rs.davg(1,0) ne 0)
rw=rs(w)

!p.multi=[0,1,3]
if !d.name eq 'X' then begin
	 wset,0
endif
if !d.name eq 'PS' then begin
	device,/cl
	device,file='counts.ps'
endif
plot_occs_res,[rw.edges(1,0),rw.edges(1,0) ], $
	[rw.davg(0,1)+rw.davg(0,0)>0,rw.davg(0,0)], $
	[rw.cos,rw.cos], [.37,.97],/xtype, $
	xtit='DISCSP1 DISCSP2 BOUNDARY (keV)', $
	ytit='Measured Count Rate (s!u-1!n)!C!CDISCSP1 & SUMMED 1&2',$
	xrange=[5,200],yran=[-10,70],xmargin=[14,4], $
	xcharsize= 1.2*(!d.name eq 'PS') + 1.3*(!d.name eq 'X'), $
	ycharsize= 1.2*(!d.name eq 'PS') + 1.3*(!d.name eq 'X')

legend, label, psym=symkey(4:9),posi=[60,65]


plot_occs_res,[rw.edges(1,0),rw.edges(1,0) ], $
	[rw.dprd(1)+rw.dprd(0),rw.dprd(0)], $
	[rw.cos,rw.cos], [.37,.97],/xtype, $
	xtit='DISCSP1 DISCSP2 BOUNDARY (keV)', $
	ytit='Predicted Count Rate (s!u-1!n)!C!CDISCSP1 & SUMMED 1&2',$
	xrange=[5,200],yran=[-10,70],xmargin=[14,4], $
	xcharsize= 1.2*(!d.name eq 'PS') + 1.3*(!d.name eq 'X'), $
	ycharsize= 1.2*(!d.name eq 'PS') + 1.3*(!d.name eq 'X')


plot_occs_res,[rw.edges(1,0)], $
	f_div(rw.dprd(1)+rw.dprd(0),rw.davg(0,1)+rw.davg(0,0)>0), $
	rw.cos, [.37,.97],/xtype, $
	xtit='DISCSP1 DISCSP2 BOUNDARY (keV)', $
	ytit='Total Predicted Count Rate / Measured Count Rate', $
	xrange=[5,200],yran=[0,3],xmargin=[14,4],$
	xcharsize= 1.2*(!d.name eq 'PS') + 1.3*(!d.name eq 'X'), $
	ycharsize= 1.2*(!d.name eq 'PS') + 1.3*(!d.name eq 'X')
plotdate, 'DISCSP OCCULT STUDY'
!p.multi=[0,1,2]
if !d.name eq 'PS' then begin
	device,/cl
	device,file='threshold.ps'
endif
if !d.name eq 'X' then begin
	 wset,2
endif

plot_occs_res,[rw.edges(0,0),rw.edges(1,0) ], $
	[rw.dprd(1)+rw.dprd(0),rw.dprd(1)], $
	[rw.cos,rw.cos], [.37,.97],/xtype, $
	xtit='Energy Threshold (keV)', $
	ytit='Predicted Rate',$
	xrange=[5,200],yran=[-10,70],xmargin=[14,4], $
	xcharsize= 1.2*(!d.name eq 'PS')/2. + 1.3*(!d.name eq 'X')/2., $
	ycharsize= 1.2*(!d.name eq 'PS')/2. + 1.3*(!d.name eq 'X')/2.

plot_occs_res,[rw.edges(0,0),rw.edges(1,0) ], $
	[rw.davg(0,1)+rw.davg(0,0)>0,rw.davg(0,1)], $
	[rw.cos,rw.cos], [.37,.97],/xtype, $
	xtit='Energy Threshold (keV)', $
	ytit='Measured Rate',$
	xrange=[5,200],yran=[-10,70],xmargin=[14,4], $
	xcharsize= 1.2*(!d.name eq 'PS')/2. + 1.3*(!d.name eq 'X')/2., $
	ycharsize= 1.2*(!d.name eq 'PS')/2. + 1.3*(!d.name eq 'X')/2.
plotdate, 'DISCSP OCCULT STUDY'
legend, label, psym=symkey(4:9),posi=[50,65],charsiz=.8

if !d.name eq 'PS' then begin
	device,/cl
	device,file='ratios.ps'
endif
!p.multi=[0,1,2]

@plot_ratios
end
