;+
;
; NAME: 
;	SLED
;
; PURPOSE:
;	Subroutine to calculate the SLED correction. 
;
;
; CATEGORY:
;	BATSE
;
; CALLING SEQUENCE:
;	sled,ndet,slope,xvec,olight
;
; CALLS:
;	none
;
; INPUTS:
;c        ndet--detector number
;c        slope--the linear term (b) in the calibration equation
;c        xvec--vector of uncompressed channel boundaries
;c        olight--vector of light output for each channel
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;c     Output:
;c        olight--vector of light output adjusted for the SLED
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	INHIBIT - if set then olight isn't modified on subsequent calls to SLED.  
;			used alone, e.g. sled,INHIBIT=1 and sled, INHIBIT=0
; COMMON BLOCKS:
;      common sled_com, sb,sc,sd,scut
;      common sled_test_com, test, sbt, sct, sdt, scutt, inhibit_hold
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	The correction is an adjustment to the light output in the linear term of the calibration 
;	equation. 
;
; MODIFICATION HISTORY:
;c     written 11/8/91            last modified  12/6/91       LAF
;c 	converted to IDL by RAS 92/6/3
;	modified, ras, 8-dec-95, inhibit keyword added
;	Version 4, ras, 7-jun-1996, documentation modified
;-
;
;      real xvec(0:256),olight(0:256),sb(0:7),sc(0:7),sd(0:7),scut(0:7)
;c
     pro sled,ndet,slope,xvec,olight, inhibit=inhibit

      common sled_com, sb,sc,sd,scut
      common sled_test_com, test, sbt, sct, sdt, scutt, inhibit_hold

;
;	If INHIBIT is set, then the sled correction is disabled.
;

if n_elements(inhibit) eq 1 then inhibit_hold = inhibit
if fcheck(inhibit_hold,0) then return

;c
;c     Adjust light output for SLED
;c
	checkvar, test, 0
	if test eq 1 then begin
		sbh = sb & sch = sc & sdh = sd & scuth= scut
		sb = sbt & sc = sct & sd = sdt & scut=scutt
	endif

	 index = where( xvec le scut(ndet))
	 denom=1.-tanh(sb(ndet)*(xvec-sc(ndet)))

	 olight(index) = olight(index) + slope*sd(ndet)*denom
	;stop
	if test eq 1 then begin
		sb = sbh & sc=sch & sd = sdh & scut=scuth
	endif
;c
      return
      end
