
;
; The LS term upsilons have been split into components (sigut_upsdat.txt).
; This routine processes this file into the CHIANTI .upsdat format, making
; use of the .wgfa file and .elvlc file.
;
; PRY, 26-Nov-2007
;
openr,lin,'sigut_upsdat.txt',/get_lun
openw,lout,'mg_2.upsdat_sigut_ls',/get_lun

read_elvlc,'mg_2.elvlc_sigut',l1,term,conf,ss,ll,jj,ecm,eryd,ecmth,erydth,ref

read_wgfa_str,'mg_2.wgfa_ff',wgfastr,ref

ups=fltarr(6)

t=[0.1,0.3,0.5,1.0,2,3]*1e4

WHILE eof(lin) NE 1 DO BEGIN
  readf,lin,format='(2i5,10x,6e10.3)',i,j,ups
  IF j LE 13 THEN BEGIN
  de=abs(eryd[j-1]-eryd[i-1])
  printf,lout,format='(2i5,f10.6,6e10.3)',i,j,de,t
  k=where(wgfastr.lvl1 EQ i AND wgfastr.lvl2 EQ j,nk)
  IF nk EQ 1 THEN gf=wgfastr[k].gf ELSE gf=0.
 ;
 ; in case levels are swapped around
 ;
  k=where(wgfastr.lvl1 EQ j AND wgfastr.lvl2 EQ i,nk)
  IF nk EQ 1 THEN gf=wgfastr[k].gf
 ;
  printf,lout,format='(2i5,e10.3,6e10.3)',i,j,gf,ups
ENDIF
ENDWHILE

free_lun,lin,lout

END
