
read_elvlc_direct,'ca_2.elvlc_nist',l1,conf,term,ss,ll,spd,jj,mult,ecm,eryd,ecmth,erydth,ref


openr,lin,'ca2_avalues.txt',/get_lun

openw,lout,'ca_2.wgfa_melendez',/get_lun

WHILE eof(lin) NE 1 DO BEGIN
  readf,lin,format='(20x,e12.0,8x,e12.0,2x,i2,2x,i2)',wvl,aval,i,j
  wvl=wvl*10.
 ;
  wvl_nist=1d8/abs(ecm[j-1]-ecm[i-1])
;  IF abs(wvl-wvl_nist)/wvl_nist GE 0.001 THEN print,'**Wavelength Problem ',i,j,wvl,wvl_nist
 ;
  IF aval GE 1e5 THEN BEGIN   ; assume these are allowed transitions
    de=abs(ecm[i-1]-ecm[j-1])
    IF ecm[i-1] GT ecm[j-1] THEN g_k=float(mult[i-1]) ELSE g_k=float(mult[j-1])
    gf=g_k*aval/6.670e-1/de^2
  ENDIF ELSE BEGIN
    gf=0.
  ENDELSE 

  printf,lout,format='(2i5,f15.3,2e15.3)',i,j,wvl,gf,aval
ENDWHILE 

printf,lout,' -1'
printf,lout,'%file: ca_2.wgfa'
printf,lout,'%Prepared for the CHIANTI atomic database by Peter Young, Jan 2009'
printf,lout,'%A-values: Melendez, Bautista, & Badnell, 2007, A&A, 469, 1203'
printf,lout,'%Wavelengths: derived from experimental energies in .elvlc file.'
printf,lout,'%gf-values: derived from A-values and experimental energies.'
printf,lout,'%Comment:'
printf,lout,'  Melendez et al. did not provide gf-values. These have been derived'
printf,lout,'  from the A-values, assuming that allowed transitions have A-values'
printf,lout,'  greater than 1e5.'
printf,lout,' -1'

free_lun,lin,lout

END
