;+
; 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_new('01-JAN-2012',255,1)
;   2.33831
; IDL> print,eis_recalibrate_intensity_new('01-JAN-2012',192,4.24)
;   4.87571
;
; REFERENCE TO THE PAPER:
;
;   https://arxiv.org/pdf/2308.06609.pdf
;
; :History:
;   27-AUG-2013: HPW : Documented version.
;   10-OCT-2013: HPW : Added undecay option.
;   24-JUL-2023: HPW : New version.
;   15-AUG-2023: HPW : Released
;
; $Id$
;-
function eis_recalibrate_intensity_new, date, wave, input_ints, $
                                        gdz=gdz, $
                                        wul=wul, $
                                        undecay=undecay

  ;; --- 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

  case 1 of
    keyword_set(gdz): begin
      ratio = eis_ea(wave)/eis_ea_gdz(date, wave)
    end
    keyword_set(wul): begin
      ratio = eis_ea(wave)/eis_ea_nrl(date, wave)
    end
    else: begin
      ratio = eis_ea(wave)/interpol_eis_ea(date, wave, /quiet)
    end
  endcase
  ints = input_ints*ratio

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

return,ints
end
