
FUNCTION eis_slit_width, yip, slit_ind=slit_ind

;+
; NAME
;
;     EIS_SLIT_WIDTH()
;
; PROJECT
;
;     Hinode/EIS
;
; EXPLANATION
;
;     Returns the EIS instrumental width for the user-specified
;     Y-position on the CCD.
;
;     The method for determining the instrumental width is described
;     in EIS Software Note #7.
;
; INPUTS
;
;     YIP   The Y-position on the EIS CCD. Must be a number between 1
;           and 1023.
;
; OPTIONAL INPUTS
;
;     SLIT_IND  The index of the EIS slit. SLIT_IND=0 corresponds to
;               the 1" slit (default option), and SLIT_IND=2
;               corresponds to the 2" slit.
;
; OUTPUTS
;
;     A vector of same size as the input YIP is returned. The vector
;     contains the values of the instrumental width (full width at
;     half maximum) in angstroms.
;
; HISTORY
;
;     Ver. 0.1, 28-Feb-2011, Peter Young
;     Ver. 1.0, 6-Sep-2012, Peter Young
;       Tidied up header; added checks on input parameters.
;     Ver. 1.1, 8-Jan-2013, Peter Young
;       Corrected error in header; no change to code.
;-


IF n_params() LT 1 THEN BEGIN
  print,'Use:  wid = eis_slit_width( ypix [, slit_ind=] )'
  print,''
  print,'      slit_ind=0   -> 1" slit'
  print,'      slit_ind=2   -> 2" slit'
  return,-1
ENDIF 


IF n_elements(slit_ind) EQ 0 THEN BEGIN
  slit_ind=0
  print,'%EIS_SLIT_WIDTH: The slit index (slit_ind) has not been specified. Assuming slit_ind=0, corresponding to 1" slit.'
ENDIF 


IF slit_ind NE 0 AND slit_ind NE 2 THEN BEGIN
  print,'%EIS_SLIT_WIDTH: The slit index (slit_ind) must be either 0 or 2. Returning...'
  return,-1
ENDIF 

;
; A 4 degree polynomial was used to fit the width variation. The
; coefficients of the polynomial are returned below.
;
CASE slit_ind OF
  0: BEGIN
    c=[0.059358,-1.5094e-5,-5.6848e-9,8.3517e-11,-4.5428e-14]
  END 
  2:BEGIN
    c=[0.067721,-2.2514e-5,2.5833e-8,4.0998e-11,-2.9560e-14]
  END 
ENDCASE 

result=poly(yip,c)

return,result

END
