;+
; NAME:
;	GAIN_TEMP_PLOT
; PURPOSE:
;	Plots the relationship of the gain of the BCS detectors against 
;	temperature
; CALLING SEQUENCE:  
;	.run GAIN_TEMP_PLOT
; INPUTS:
;	reads data from $DIR_BCS_LOGS:GAIN_TEMP_LOG.DAT
; OUTPUTS:
;
; OPTIONAL OUTPUTS:
;
; RESTRICTIONS:
;
; PROCEDURE:
;
; MODIFICATION HISTORY:
;	RDB	1991
;	RDB  21-Jun-91	Capitalized $DIR_BCS_LOGS for Unix
;			Used CONCAT_DIR
;-
npnts = 100
centroid = fltarr(4,npnts)
fwhm = fltarr(4,npnts)
temps = fltarr(npnts)

openr,lun,concat_dir('$DIR_BCS_LOGS','gain_temp_log.dat'),/get_lun
ss=''
readf,lun,ss & print,ss
readf,lun,ss & print,ss
tempr = 0.0
vars=fltarr(8)
jj=0

while not eof(lun) do begin
	readf,lun,'$(f5.1,3x,2(x,2(x,f8.3,f7.3)))',tempr,vars
	print,'$(f6.1,8f9.3)',tempr,vars
	qq = vars([0,2,4,6]) & centroid(4*jj) = qq
	qq1 = vars([1,3,5,7]) & fwhm(4*jj) = qq1
	temps(jj) = tempr
	jj = jj+1
	endwhile

close,lun
ans=''
read,'Plot',ans

centroid = centroid(*,0:jj-1)
fwhm = fwhm(*,0:jj-1)
temps = temps(0:jj-1)

tek
;reset_plot,!device
set_xy
!xtitle = 'Temperature (C)'
!fancy=1

!grid=0
!mtitle = 'BCS-A Gain variation with Temperature  (F2)'
;;!ymin=2.5 & !ymax=3.5
;;!ytitle = 'FWHM'
!ymin=13 & !ymax=23
!ytitle = 'Resolution (percent)'

;;!psym=-1
;;plot,days,fwhm(0,*)/centroid(0,*)*100.
;;!psym=-2
;;oplot,days,fwhm(1,*)/centroid(1,*)*100.

!psym=-1
cfwhm = fwhm(0,*) & vv = where(cfwhm gt 0) & !c=0
plot,temps(vv),fwhm(vv*4+0)/centroid(vv*4+0)*100.
!psym=-2
cfwhm = fwhm(1,*) & vv = where(cfwhm gt 0) & !c=0
oplot,temps(vv),fwhm(vv*4+1)/centroid(vv*4+1)*100.

ans=''
read,ans

!grid=1
;;!type=16
!yticks=10
!ymin=0.9 & !ymax=1.1
;;set_xy
!ytitle = 'Gain'

;;!psym=-1
;;plot,days,(centroid(0,*)-centroid(0,0))/centroid(0,0)+1.
;;!psym=-2
;;oplot,days,(centroid(1,*)-centroid(1,0))/centroid(1,0)+1.

!psym=-1
cgain = centroid(0,*) & vv = where(cgain gt 0) & !c=0
plot,temps(vv),(centroid(vv*4+0)-centroid(0,2))/centroid(0,2)+1.
!psym=-2
cgain = centroid(1,*) & vv = where(cgain gt 0) & !c=0
oplot,temps(vv),(centroid(vv*4+1)-centroid(1,2))/centroid(1,2)+1.

read,ans

!mtitle = 'BCS-B Gain variation with Temperature  (F4)'

!grid=0
!type=0 & !yticks=0
;;!ymin=2.5 & !ymax=4.0
;;!ytitle = 'FWHM'
!ymin=13 & !ymax=23
!ytitle = 'Resolution (percent)'

!psym=-1
cfwhm = fwhm(2,*) & vv = where(cfwhm gt 0) & !c=0
plot,temps(vv),fwhm(vv*4+2)/centroid(vv*4+2)*100.
!psym=-2
cfwhm = fwhm(3,*) & vv = where(cfwhm gt 0) & !c=0
oplot,temps(vv),fwhm(vv*4+3)/centroid(vv*4+3)*100.

read,ans

!grid=1
;;!type=16
!yticks=10
!ymin=0.9 & !ymax=1.1
;;set_xy
!ytitle = 'Gain'

;;!psym=-1
;;plot,days,(centroid(2,*)-centroid(2,0))/centroid(2,0)+1.
;;!psym=-2
;;oplot,days,(centroid(3,*)-centroid(3,0))/centroid(3,0)+1.

!psym=-1
cgain = centroid(2,*) & vv = where(cgain gt 0) & !c=0
plot,temps(vv),(centroid(vv*4+2)-centroid(2,2))/centroid(2,2)+1.
!psym=-2
cgain = centroid(3,*) & vv = where(cgain gt 0) & !c=0
oplot,temps(vv),(centroid(vv*4+3)-centroid(3,2))/centroid(3,2)+1.

!type=0 & !yticks=0
!grid=0
!mtitle=''

end
