;+
;
; NAME: 
;	LLD_CHAN
;
; PURPOSE:
;	This function returns the LLD channel in PHA space as a function of
;	the commanded SLLD level for the BATSE SPEC detectors.
;
; CATEGORY:
;	BATSE
;
; CALLING SEQUENCE:
;        lld_chan( ut, ndet,  s=s, p=p, f0=lld_fid0, f1=lld_fid1)
;	Channels = LLD_CHAN( Ut, Ndet )
;
; CALLS:
;	none
;
; INPUTS:
;       Ut - date in ANYTIM format
;	Ndet - detector number
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORD INPUTS:
;	SCHWARTZ- his fiducials
;	PREECE  - his fiducials
;	SKELTON - his fiducials
;	f0  - preece fiducials
;	f1  - schwartz fiducials
;	f2  - skelton fiducials
;	SPEC_LLD - 8 SLLD values from housekeeping. overrides date.
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	Use the SLLD/LLD linear relationship with the coefficients of choice.
;
; MODIFICATION HISTORY:
;	Version 1, RAS, 26-Nov-1996
;	Version 2, richard.schwartz@gsfc.nasa.gov, added SPEC_LLD keyword, 1-apr-1998.
;-
function lld_chan, ut, ndet,  schwartz=schwartz, preece=preece, skelton=skelton, $
	f0=lld_fid0, f1=lld_fid1, f2= lld_fid2, spec_lld=spec_lld

;	R Schwartz estimate of lld channel as a function of setting
lld_fid1 = reform( [ 36,21,.47, 32, 24, .47, 44,6,.47, 36, 11, .47, $
	             36,24,.47, 28, 16, .47, 36, 24, .47, 44, 19,.47], 3,8)

;	Rob Preece's estimate
lld_fid0 = transpose( reform( $
	[fltarr(8), 5.84, 6.94, -15.98, -3.26,7.90, 5.96, 10.48, 5.88, $
	 0.384, 0.3816, 0.4535, 0.384,  0.4193, 0.4122, 0.4205, 0.3680 ], 8,3))

;	T Skelton fiducials.
lld_fid2 = transpose( reform( $
	[fltarr(8),4.335, 9.509, -14.723, -5.04291, 7.03375, 3.66165, 6.83836, -1.03621, $
	0.455964, 0.471768, 0.519375, 0.468118, 0.473876, 0.479256, 0.487769, 0.490639], 8,3))

checkvar, ndet, indgen(8)
checkvar, wfid, 1 ;schwartz

if keyword_set(preece) then wfid = 0
if keyword_set(skelton) then wfid = 2
if not keyword_set(spec_lld) then spec_lld = get_slld(ut(0))
f = lld_fid1
test = execute('f=lld_fid'+strtrim(wfid,2))

chan = ( f(1,*) - (f(0,*)-spec_lld)*f(2,*))(ndet)


return, chan

end

