;+
;
; PROJECT:  CHIANTI
;
;       CHIANTI is an atomic database package for the calculation of
;       continuum and emission line spectra from astrophysical plasmas. It is a 
;       collaborative project involving the Naval Research Laboratory
;       (Washington DC, USA), the Arcetri Observatory (Firenze, Italy), and the
;       Cambridge University (United Kingdom).
;
;
; NAME:
;	ZION2FILENAME
;
; PURPOSE:
;
;	help locate CHIANTI database files
;
; CATEGORY:
;
;	database.
;
; CALLING SEQUENCE:
;
;       ZION2FILENAME, Iz, Ion, Filename
;
;
; INPUTS:
;
;	Iz:  nuclear charge of ion of interest, i.e. 26 for Fe
;       Ion:   charge state of ion of interest, i.e. 2 for Fe II	
;
;  KEYWORDS:
;       
;       diel:  set if excitation of this ion is by dielectronic
;		recombination
;
; OUTPUTS:
;
;	Filename:  the complete filename and path specification for generic
;                  CHIANTI database file, i.e. '.elvlc' suffix is not included
;
;
; RESTRICTIONS:
;
;	!xuvtop must be set
;
;
; EXAMPLE:
;
;             > zion2filename,26,2,filename
;             > print,filename
;             > /data1/xuv/fe/fe_2   assuming !xuvtop = '/data1/xuv'
;
; MODIFICATION HISTORY:
; 	Written by:	Ken Dere
;	March 1996:     Version 2.0
;       Sept  1996:     Modified for use with VMS
;       December 1998:  Modified to diel keyword
;
;-
pro zion2filename,z,ion,filename,diel=diel
;
;  convert Z, ionization state to the filename
;  i.e.     z=26  ion=24 > !xuvtop/fe/fe_24
;
if n_params() lt 3 then begin
   print,' '
   print,'   IDL> zion2filename,z,ion,filename, [/diel]
   print,'  i.e.> zion2filename,26,11,filename
   print,'         yields filename = ''!xuvtop/fe/fe_11/fe_11''   '
   print,'  or '
   print,'  i.e.> zion2filename,26,11,filename,/diel
   print,'         yields filename = ''!xuvtop/fe/fe_11d/fe_11d''   '
   print,' '
   return
endif
;
z_lbl=['h','he','li','be','b','c','n','o','f','ne','na','mg','al','si','p','s','cl','ar','k','ca','sc','ti','v','cr','mn','fe','co','ni','cu','zn']
;
;
if !version.os eq 'vms' then begin
   lentop=strlen(!xuvtop)
   top=strmid(!xuvtop,0,lentop-1)
   dir=top+'.'+strtrim(z_lbl(z-1),2)
   name=strtrim(z_lbl(z-1),2)+'_'+strtrim(string(ion,'(i2)'),2)
   if keyword_set(diel) then name=name+'d'
   filename=dir+'.'+name+']'+name
endif else begin
   dir=!xuvtop+'/'+strtrim(z_lbl(z-1),2)
   name=strtrim(z_lbl(z-1),2)+'_'+strtrim(string(ion,'(i2)'),2)
   if keyword_set(diel) then name=name+'d'
   filename=dir+'/'+name+'/'+name
endelse
;
;
end


