Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/commit_xsec.pro'
;+
; NAME:
;	Commit_Xsec
; PURPOSE:
;	Copy the new approximate cross-section into the energy levels array.
;	Interpolate/extrapolate the cross-section at the edge frequency.
;	Stop events from the draw widget (x-sec plot) and
;	start accepting events from the energy level list widget.
;	Called by pro Approx_Xsecs_Ev.
; CALLING:
;	Commit_Xsec, state
; INPUTS:
;	state = structure variable, state of the widget.
; OUTPUTS:
;	state = new state of the widget.
; EXTERNAL CALLS:
;	function Level_info
;	function scalar
; PROCEDURE:
;	If approx. x-secs were modified then just move the handles,
;	otherwise just free the handles.
; HISTORY:
;	Written: Frank Varosi NASA/GSFC 1995.
;-

pro Commit_Xsec, state

   if (state.Lsel GE 0) AND Handle_info( state.ELevel ) then begin

	Handle_value, state.ELevel, ELevel,/NO_COPY
	action = "no change"

	if (state.modified) then begin

		Handle_value, ELevel.freq_approx, freq,/NO_COPY
		Handle_value, ELevel.xsec_approx, xsec,/NO_COPY
		ELevel.edge_xsec = scalar( interpol( xsec, freq, 0 ) )
		Handle_value, ELevel.freq_approx, freq,/NO_COPY,/SET
		Handle_value, ELevel.xsec_approx, xsec,/NO_COPY,/SET

		Plot_Xsec, ELevel, TITLE=Level_info( ELevel )
		Handle_value, state.ELevs, ELevs,/NO_COPY

		if Handle_info( ELevs(state.Lsel).freq_approx ) then begin
			Handle_free, ELevs(state.Lsel).freq_approx
			Handle_free, ELevs(state.Lsel).xsec_approx
		   endif

		ELevs(state.Lsel) = ELevel

		Widget_Control, state.List_wid, SET_VAL = Level_info( ELevs )
		Handle_value, state.ELevs, ELevs,/NO_COPY,/SET
		action = "Stored new approx. X-sec"

	 endif else if Handle_info( ELevel.freq_approx ) then begin

		Handle_free, ELevel.freq_approx
		Handle_free, ELevel.xsec_approx
	  endif

	state.Lsel = -1
	state.modified = 0
	Handle_value, state.ELevel, ELevel,/NO_COPY,/SET
 	Handle_free, state.ELevel

	Widget_Control, state.List_wid,/SENSITIVE
	Widget_Control, state.draw_wid, DRAW_BUTTON=0, DRAW_MOTION=0
	Widget_Control, state.info_wid, SET_VAL=action 
	Widget_Control, state.cursor_wid, SET_VAL="Cursor:"
	Widget_Control, state.instr_wid, SET_VAL="Select from List"
	Widget_Control, state.axes_wid, SENS=0

	for i=0,1 do begin
     		Widget_Control, state.x_wids(i),SENS=0
     		Widget_Control, state.y_wids(i),SENS=0
	  endfor
   endif
end