Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/build_bfsup_tr.pro'
;+
; NAME:
;	Build_BFsup_Tr
; PURPOSE:
;	Build bound-free transitions for SuperLevels by first merging
;	the photo-ionization cross-sections for Levels in each group
;	(if not already done). Then an approximate/simplified
;	photo-ionization cross-section is created/modified for each SuperLevel,
;	interactively with the widget: Approx_Xsecs.
; CALLING:
;	Build_BFsup_Tr
;
; INPUT & OUTPUT:	All thru common blocks:
;
;	ELevs = array of structures with tags for energy of level,
;		quantum numbers, and handles pointing to
;		full and approximate photo-ionization cross-sections.
;
;	SupLevs = array of structures with tags for average energy,
;		quantum numbers, and handles pointing to
;		full and approximate photo-ionization cross-sections.
;		Updated with new approximate photo-ionization cross-sections,
;		(full cross-sections are merged from ELevs).
;
; COMMON BLOCKS:
;	see file: ~/modion/code/modion_common.pro
; EXTERNAL CALLS:
;	pro Merge_Xsecs
;	pro Modion_Status
;	pro Handles_Free
;	function N_struct
;	function Approx_Xsecs	(~/modion/code/widgets/approx_xsecs.pro)
; PROCEDURE:
;	Just call Approx_Xsecs widget and then check the "disp" tag for changes.
; HISTORY:
;	Written: Frank Varosi NASA/GSFC 1995.
;-

pro Build_BFsup_Tr

@modion_common

	if N_struct( ELevs ) LE 0 then begin
		Modion_Status, "energy Levels do not exist",/BELL
		return
	   endif

	if N_struct( SupLevs ) LE 0 then begin
		Modion_Status, "do not exist !",/BELL,/APPEND
		return
	   endif

	for i=0,N_struct( SupLevs )-1 do begin

	   if (SupLevs(i).np LE 0) OR $
	      (NOT handle_info( SupLevs(i).phion_xsec )) then begin

		Handles_Free, SupLevs(i).phion_freq
		Handles_Free, SupLevs(i).phion_xsec
		SupLevs(i).np = 0

		if ( SupLevs(i).E  LT  ion_info.Eion ) then begin
		     edge_freq = aLog10( ( ( ion_info.Eion - SupLevs(i).E ) * $
						ion_info.c ) > 1 )
		     SupLevs(i).edge_freq = edge_freq
		     SupLevs(i).edge_xsec = aLog10( 2.815 ) + 47 - 3*edge_freq $
			+ 4*aLog10( ion_info.Z ) - 5*aLog10( SupLevs(i).N )
		 endif else begin
		     SupLevs(i).edge_freq = 0
		     SupLevs(i).edge_xsec = 0
		     edge_freq = 0
		  endelse

		Merge_Xsecs, ELevs, freq, xsec, GROUP=SupLevs(i).group

		if N_elements( freq ) GT 1 then begin
		     freq = freq - edge_freq
		     xsec = aLog10( ( xsec/SupLevs(i).gw ) > 1e-30 )
		     SupLevs(i).np = N_elements( xsec )
		     SupLevs(i).phion_freq = handle_create( VAL=freq,/NO_COPY )
		     SupLevs(i).phion_xsec = handle_create( VAL=xsec,/NO_COPY )
		  endif
	     endif
	  endfor

	BFree_Trans = SupLevs
	base = Approx_Xsecs( BFree_Trans, ion_info, /MODAL )

	w = where( BFree_Trans.disp, nmod )

	if (nmod GT 0) then begin
		SupLevs(w).npx = BFree_Trans(w).npx
		SupLevs(w).disp = BFree_Trans(w).disp
		SupLevs(w).edge_xsec = BFree_Trans(w).edge_xsec
		SupLevs(w).freq_approx = BFree_Trans(w).freq_approx
		SupLevs(w).xsec_approx = BFree_Trans(w).xsec_approx
	   endif

	if (nmod EQ 1) then mess = " approx. SupLev ioniz-X-sec was modified" $
			else mess = " approx. SupLev ioniz-X-secs were modified"

	Modion_Status, strtrim( nmod,2 ) + mess
end