;+
;  Name:
;       FCRYSTAL1
;  Purpose:
;
; 	This function calculates the energy loss in the NaI crystal given
;	 the light observed.  The light is assumed to be
;           		L  =  E * g_c(E)
; 	where g_c and its derivative are provided.  A simple interpolation
;	 algorithm is used on the assumption that the relation is very well behaved.
;
;  Category:
;	BATSE
;  Calling Sequence:
;	result = fcrystal1( olight )
;   Inputs:
;	olight
;   Outputs:
;	The result is the derived energy loss in keV  
;   Restrictions:
;   Adapted from measurements made by UCSD on BATSE SPEC detectors.
;
;   Common Blocks:
;    fcrystal1_com
;
;  History:
;c Version 1, adapted from fcrystal by ras, 16-Mar-1996
;c
;c*****************************************************************************
;-
function fcrystal1, olight


common fcrystal1_com, eee, lll

if not exist(eee) then begin
	eee = [findgen(510)*0.1 + 3.0, findgen(400)*0.5+54., findgen(100)+254.]
	g_c, eee, lll
	lll = lll*eee
endif

wless=where( olight le max(lll), nless)
result = olight * 0.0

if nless ge 1 then result(wless) = interpol( eee, lll, olight(wless))

wgt = where( olight gt max(lll), nmore)
if nmore ge 1 then for i=0,nmore-1 do result(wgt(i)) = fcrystal( olight(wgt(i)))

return, result
end
