;+
;
; 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:
;	ion2filename
;
; PURPOSE:
;	Ion names as character strings are converted to
;	provide their complete file name (with out suffix)
;
; CATEGORY:
;	
;	naming utility
;
; CALLING SEQUENCE:
;
;       ION@FILENAME,Ion,Filename
;
;
; INPUTS:
;	Name:   such as 'c_2'
;
;
; OUTPUTS:
;
;	Filename:  !xuvtop/c/c_2
;
;
;
; EXAMPLE:
;
;                     > ion2filename,'c_2d',filename
;                     > print,filename
;                     > !xuvtop/c/c_2d/c_2
;
; MODIFICATION HISTORY:
;
; 	Written by:	Ken Dere
;	September 1999:  added for use with Version 3
;
;-
pro ion2filename,ion,filename
;
if n_params(0) lt 2 then begin
   print,'    use> ion2filename,ion,filename'
   print,'    use> ion2filename,''c_6'',filename'
   print,'           giving filename = /data/c/c_6 , for example'
   return
endif
;
;
name=strtrim(ion,2)
;
;
locname=strlowcase(name)
pos=strpos(locname,'_')
l=strlen(pos)
first=strmid(locname,0,pos)
last=strmid(locname,pos+1,l-pos-1)
;
if pos ge 0 then begin
;
;
if !version.os eq 'vms' then begin
   lentop=strlen(!xuvtop)
   top=strmid(!xuvtop,0,lentop-1)
   dir=top+'.'+first
   name=ion
   filename=dir+'.'+name+']'+name
endif else begin
   dir=!xuvtop+'/'+first
   name=ion
   filename=dir+'/'+name+'/'+name
endelse
;
endif else print,' incorrect format for ion name (i.e., c_2) ',ion
;
return
end
