
FUNCTION eis_tilt_error, fitdata, refpix

;+
; NAME:
;     EIS_TILT_ERROR()
;
; PURPOSE:
;     Computes a 2D array containing 1-sigma errors on wavelengths that
;     are due to uncertainties in the slit tilt.
;
;     The method assumes that there is a reference pixel (in the Y
;     direction). The tilt error then depends on the distance
;     in pixels from this reference pixel.
;
; CATEGORY:
;     Hinode; EIS; spectral tilt.
;
; CALLING SEQUENCE:
;     Result = EIS_TILT_ERROR ( FitData, RefPix )
;
; INPUTS:
;     FitData:  An EIS fit structure produced by eis_auto_fit.pro.
;     RefPix:   A reference Y-pixel. Usually this is returned by
;               eis_update_fitdata.pro. 
;
; OUTPUTS:
;     A 2D array of size (fitdata.nx * fitdata.ny) containing the error
;     due to the slit tilt uncertainty. Units: angstroms.
;
; PROGRAMMING NOTES:
;     * The tilt uncertainties come from EIS Software Note No. 4.
;     * The uncertainty at Y=refpix is defined as zero since it is the
;       reference pixel.
;
; MODIFICATION HISTORY:
;     Ver.1, 14-Apr-2010, Peter Young
;     Ver.2, 10-Jul-2020, Peter Young
;       Updated header; no change to code.
;-


IF n_params() LT 2 THEN BEGIN
  print,'Use:  IDL> tilt_err = eis_tilt_error( fitdata, refpix) '
  return,-1
ENDIF 

nx=fitdata.nx
ny=fitdata.ny
yy=findgen(ny)+fitdata.yrange[0]

yref=refpix

IF fitdata.slit_ind EQ 0 THEN BEGIN
 ;
 ; 1" slit tilt uncertainties
 ;
  sig1=2.90e-6
  sig2=2.40e-9
ENDIF ELSE BEGIN
 ;
 ; 1" slit tilt uncertainties
 ;
  sig1=2.40e-6
  sig2=2.40e-9
ENDELSE 

yerr=(yy-yref)*sig1+(yy-yref)^2*sig2

error_array=fltarr(nx,ny)

FOR i=0,nx-1 DO error_array[i,*]=yerr

return,error_array

END
