FUNCTION get_tmax, ionname, ioneqname=ioneqname

;+
; NAME
;
;     GET_TMAX()
;
; PROJECT
;
;     CHIANTI
;
; EXPLANATION
;
;     Returns the temperature of maximum ionization (T_max) for the
;     specified ion.
;
; INPUTS
;
;     IONNAME   The name of the ion in CHIANTI format. E.g., 'fe_13'
;               for Fe XIII.
;
; OPTIONAL INPUTS
;
;     IONEQNAME  The routine reads the default CHIANTI ion balance
;                file (!ioneq_file). To use a different ion balance
;                file, specify the full pathname with this keyword.
;
; OUTPUTS
;
;     Returns the temperature of maximum ionization in K. If the ion
;     balance file is not found, then a value of -1 is returned.
;
; CALLS
;
;     READ_IONEQ, CONVERTNAME
;
; HISTORY
;
;     Ver.1, 9-Oct-2008, Peter Young
;-

IF n_elements(ioneqname) EQ 0 THEN ioneqname=!ioneq_file

IF NOT file_exist(ioneqname) THEN BEGIN
  print,'%GET_TMAX: the specified ionization balance file does not exist. Returning...'
  return,-1.
ENDIF 

read_ioneq,ioneqname,tt,ii,ref

convertname,ionname,iz,ion

ii=reform(ii[*,iz-1,ion-1])

getmax=max(ii,index)

return,10.^tt[index]

END
