;+
; A routine that returns a re-calibrated EIS intensity given a date
; and wavelength. For example, if an Fe XXIV 255 intensity of 1 was
; observed on 01-JAN-2012 using the pre-flight calibration then the
; revised intensity should be
;
; IDL> print,eis_recalibrate_intensity('01-JAN-2012',255,1)
;   1.34642
; IDL> print,eis_recalibrate_intensity('01-JAN-2012',192,4.24)
;   3.76245
;
; Alternatively, the Giulio Del Zanna correction can be
; calculated. See *eis_ea_gdz* for more details. For example,
;
; IDL> print,eis_recalibrate_intensity('01-JAN-2012',255,1,/gdz)
;   2.86151
; IDL> print,eis_recalibrate_intensity('01-JAN-2012',192,4.24,/gdz)
;   4.90082
;
; :History:
;   27-AUG-2013: HPW : Documented version.
;   10-OCT-2013: HPW : Added undecay option. 
;
; $Id: eis_recalibrate_intensity.pro 3060 2013-10-20 12:29:19Z hwarren $:
;-
function eis_recalibrate_intensity,date,wave,input_ints,gdz=gdz,undecay=undecay,quiet=quiet

  ;; --- taken from eis_ltds
  ;; For about 2 years, the recommended calibration option for eis_prep
  ;; was to use the keyword /correct_sensitivity. This applied an
  ;; exponential sensitivity decay to all lines, with a decay time of
  ;; 1894 days. The /undecay keyword allows this old correction to be
  ;; undone.
  IF keyword_set(undecay) THEN BEGIN
    tref_tai=anytim2tai('22-sep-2006 21:36')
    input_tai=anytim2tai(date)
    dt_days=(input_tai-tref_tai)/86400.
    decay_factor=exp(-dt_days/1894.0)
    new_input_ints = input_ints*decay_factor
    if not(keyword_set(quiet)) then begin
      print,' Reversing eis_prep /correct_sensitivity'
      print,' input ints   = '+trim(input_ints)+' -> '+trim(new_input_ints)
      print,' decay factor = '+trim(decay_factor)
    endif
    input_ints = new_input_ints
  ENDIF

  if keyword_set(gdz) then begin
    ratio = eis_ea(wave)/eis_ea_gdz(date,wave)
  endif else begin
    ratio = eis_ea(wave)/eis_ea_nrl(date,wave)
  endelse
  ints = input_ints*ratio

  if n_elements(ints) eq 1 then ints = ints[0]

return,ints
end
