Viewing contents of file '../idllib/astron/contrib/varosi/code/allpro/conv_elevs.pro'
;+
; NAME:
;	Conv_ELevs
; PURPOSE:
;	Convert energy levels from Rydberg units to wave-number/cm,
;	and make them all positive relative to fundamental (minimum) level.
;	Also returns structure with ionization energy and other info.
;	Can be called just once after reading energy Levels from TOPBASE
;	(routine will not apply converson twice).
; CALLING:
;	Conv_ELevs, ELevs, ion_info
; INPUTS:
;	ELevs = array of structures with tags for
;		energy of level, quantum numbers, etc. (see Read_ELevs).
; OUTPUTS:
;	ELevs = same structure with energy converted to wavenumber per cm.
;
;	ion_info = scalar structure variable, basic info about atom/ion.
;
; EXTERNAL CALLS:
;	function N_struct
;	function get_words
;	function get_text_input
; HISTORY:
;	Written: Frank Varosi NASA/GSFC 1994.
;	F.V.1995, mod to allow user to change ionization energy.
;-

pro Conv_ELevs, ELevs, ion_info, NAME=name

  common Read_ELevs, elev

	NLev = N_struct( ELevs )

	if (NLev LE 0) then begin
		message,"first arg. must be structure of energy Levels",/INFO
		return
	   endif

	if min( ELevs.E ) GE 0 then begin
		message,"energy Levels have already been converted",/INFO
		return
	   endif

	ion_info = {	NLev: fix( NLev )	,$
			NZ: ELevs(0).NZ		,$
			Nel: ELevs(0).Nel	,$
			file:""			,$
			name:""			,$
			Z:0			,$
			Eion:0.0		,$
			c: 2.997925e10		,$
			hc: 1.9863e-8		,$
			Ryd: 109737.3		}

	if VarType( name ) EQ "STRING" then begin
 		ion_info.name = strmid( get_text_input( DEF=name, $
					"Name of ion/atom (4 chars) ?" ), 0,4 )
	   endif

	ion_info.Z = ion_info.NZ - ion_info.Nel +1
	ion_info.Ryd = ion_info.Ryd/( 1 + 1/(3672.*ion_info.NZ) )

	ELion = elev		;add empty Level just for ionization threshold
	ELion.NZ = ion_info.NZ
	ELion.Nel = ion_info.Nel
	ELevs = [ ELevs, ELion ]

	Eion = string( -min( ELevs.E, iminE )*ion_info.Ryd, FORM="(G12.10)" )
	ion_info.Eion = float( get_text_input( DEFAULT=Eion, $
				ion_info.name + " ionization energy (/cm) ?") )
	Modion_Status,"ionization energy = " + $
			string( ion_info.Eion, F="(G12.10)" ) + "/cm"

	ELevs.E = ion_info.Eion + ELevs.E * ion_info.Ryd	;convert to /cm.
	ELevs(iminE).E = 0					;ground state.

	w = where( ELevs.E LT ion_info.Eion, nw )

	if (nw GT 0) then begin			;bound Levels, can be ionized.
		Ebind = ion_info.Eion - ELevs(w).E
		N = ion_info.Z/sqrt( Ebind/ion_info.Ryd )
		ELevs(w).N = N
		efreq = aLog10( Ebind * ion_info.c )
		ELevs(w).edge_freq = efreq
		ELevs(w).edge_xsec = aLog10( 2.815 ) + 47 - 3*efreq + $
					4*aLog10( ion_info.Z ) - 5*aLog10( N )
	   endif
end