PRO rd_chianti, cdslist, sumer=sumer, ascii=ascii

if keyword_set(sumer) then begin   
   file = concat_dir('$CDS_ATOMIC','CHIANTI_SUMER_line_list')
endif else begin
   file = concat_dir('$CDS_ATOMIC','CHIANTI_CDS_line_list')
endelse

;
;  read to find size
;
cdslist = rd_ascii(file)
sl = n_elements(cdslist)

;
;  ascii format wanted?
;
if keyword_set(ascii) then return


OPENR,unit,file,/get_lun
;   
; create structure to hold the entire table contents
;
cdslist = {wavelength:fltarr(sl), $ ; Observed wavelength
             intensity:fltarr(sl),  $ ; Observed intensity (erg/cm2/s/sr)
             comment:STRARR(sl),    $ ; Comment '='   
             element:STRARR(sl),    $ ; Element
             ion:STRARR(sl),        $ ; Ionization stage
             tmax:fltarr(sl),       $ ; Tempertur of formation
             conf:STRARR(sl,2),     $ ; Configuration
             terms:STRARR(sl,2),    $ ; Terms
             info:STRARR(10)}         ; info block


text = ' '

FOR i = 0, sl-1 DO BEGIN
   
   READF,unit,text   

   cdslist.wavelength(i) = DOUBLE(STRMID(text,0,7))
   cdslist.intensity(i) = DOUBLE(STRMID(text,21,8))
   cdslist.comment(i) = STRMID(text,19,1)
   
   txt = str2arr(STRMID(text,9,8),delim=' ')
   cdslist.element(i) = txt(0)
   cdslist.ion(i) = txt(1)
   cdslist.tmax(i) = DOUBLE(STRMID(text,31,3)) 

   
   t1 = str2arr(STRMID(text,36,50),delim='-')
   t2 = str2arr(strtrim(t1(0),2),delim=' ')
   t3 = str2arr(strtrim(t1(1),2),delim=' ')
   cdslist.Conf(i,0) = t2(0)
   cdslist.Conf(i,1) = t3(0)
   IF N_ELEMENTS(t2) NE 1 THEN cdslist.Terms(i,0) = t2(1)
   IF N_ELEMENTS(t3) NE 1 THEN cdslist.Terms(i,1) = t3(1) 
   
END

cdslist.info(0:5) = ['This line list generated from CHIANTI_SS output',$
                     'for all wavelength bands of the CDS using ',$
                     'Quiet sun DEM, Meyer coronal abundances and',$
                     'Arnaud-Rothenflug ionisation equilibrium.',$
                     ' ','  CDP, 10-Oct-96']


close,unit
free_lun,unit
END