;+
;
; NAME: 
;      PLOT_DISCSP_CRAB
;
; PURPOSE:
;      This main program displays the measured countrates vs energy
;      and overlays the figure with the predicted countrates
;
; CATEGORY:
;      BATSE, OCCULTS
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; 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:
;	Version 1, ras, 7 June 1996
;-
!p.multi=0
if !d.name eq 'PS' then begin
	device,file='threshold.ps', scal=.8
endif
if not exist(crab) then begin
;
;      Find discsp_crab.sav on the system somewhere!!!
;
	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, 'discsp_crab.sav'
        	file = loc_file( infile, path=dirs)
        	if file ne '' then restore, file,/verb else message,"CAN'T FIND '+INFILE
	;restore,/verb,'discsp_crab.sav
	wbest=intarr(2,16435)
	for i=0,16434 do for j=0,1 do $
	 wbest(j,i)=(sort(crab(i).counts(1,j,*)))(0)
	c=fltarr(2,n_elements(crab))
	ncrab=n_elements(crab)
	for i=0,ncrab-1 do for j=0,1 do $
		c(j,i)=crab(i).counts(0,j,wbest(j,i))
	e=findgen(195)+5.
	apar=[ .0074*(30./50.)^2.12,2.12,1000.,2.12,1,2.12]
	model='f_bpow
	cosines=findgen(7)*(-.1) + .97
	thetas = acos(cosines)*!radeg
	rsp=fltarr(195,7)
	for i=0,6 do begin
	  for j=0,194 do begin
	    discsp_resp, [e(j),1000.], thetas(i), apar, resp, model=model
	    rsp(j,i)=resp
	  endfor
	endfor
endif


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=[-0,60],xmargin=[8,4], ymargin=[2,2],$
	xcharsize= 2.2*(!d.name eq 'PS')/2. + 1.3*(!d.name eq 'X')/2., $
	ycharsize= 2.2*(!d.name eq 'PS')/2. + 1.3*(!d.name eq 'X')/2.
for j=0,6 do oplot, findgen(195)+5., rsp(*,j),psy=0, linestyle=1
timestamp
legend, label, psym=symkey(4:9),posi=[40,35],charsiz=.8
if !d.name eq 'PS' then begin
	device,/cl
endif

end
