
function eis_ergs_to_dn, wvl, ergs, slit_ind=slit_ind, exp_time=exp_time, phot=phot

;+
; NAME
;
;     EIS_ERGS_TO_DN()
;
; PROJECT
;
;     Hinode/EIS
;
; EXPLANATION
;
;     Takes a calibrated intensity value (erg/cm2/s/sr) and wavelength
;     and converts it to a data number (DN) value.
;
; INPUTS
;
;     WVL    Wavelengths in angstroms (can be an array).
;
;     ERGS   Calibrated intensity value.
;
; OPTIONAL INPUTS
;
;     SLIT_IND  EIS slit index for the observation. 0 is the 1"
;               slit, 2 is the 2" slit. The default is 0.
;
;     EXP_TIME  The exposure time in seconds. Default is 1.
;
; OPTIONAL OUTPUTS
;
;     PHOT      The photon counts corresponding to the input DN
;               value. 
;
; CALLS
;
;     EIS_EFF_AREA()
;
; HISTORY
;
;     Ver.1, 13-Apr-2010, Peter Young
;-

IF n_params() LT 2 THEN BEGIN
  print,'Use:  IDL> ergs=eis_ergs_to_dn(wvl,ergs [,slit_ind=, exp_time=, phot=])'
  return,-1.
ENDIF 

IF n_elements(slit_ind) EQ 0 THEN BEGIN
  slit_ind=0
  print,'%EIS_DN_TO_ERGS: slit not specified. Assuming 1" slit.'
ENDIF

IF n_elements(exp_time) EQ 0 THEN BEGIN
  exp_time=1.
  print,'%EIS_DN_TO_ERGS: exposure time not specified. Assuming 1s.'
ENDIF 

cal=obj_new('eis_cal',/gen_aeff)


gain=cal->getgain()

de=1.986e-8/wvl
ea=eis_eff_area(wvl,/quiet)

CASE slit_ind OF
  0: pix_siz=1.0*1.0
  2: pix_siz=2.0*1.0
  ELSE: BEGIN
    print,'%EIS_DN_TO_ERGS: the conversion for slot data is not implemented. Returning...'
    return,-1.
  END 
ENDCASE

phot=ergs*ea*pix_siz*(4.848e-6)^2*exp_time/de

dn=phot*12398.5/gain/wvl/3.65

return,dn

END
