
FUNCTION eis_slit_tilt_array, nx, ny, ybin, slit_ind, yip, date_obs, $
                              ystart=ystart, refpix=refpix, long=long

;+
; NAME
;
;    EIS_SLIT_TILT_ARRAY()
;
; PROJECT
;
;    Hinode/EIS
;
; EXPLANATION
;
;    Creates a 2D array of specified dimensions that contains
;    wavelength offsets due to the tilt of the EIS slits. The offset
;    is defined such that subtracting the offset from an EIS
;    wavelength will yield the corrected wavelength.
;
;    The tilt array takes account of any Y-binning that has been
;    performed on the data.
;
;    The parameters for the slit tilt are obtained from the routine
;    eis_slit_tilt in Solarsoft.
;
; INPUTS
;
;    NX     X-size (in pixels) of output array.
;
;    NY     Y-size (in pixels) of output array.
;
;    YBIN   Size of Y-bins.
;
;    SLIT_IND  The EIS slit index (0 - 1", 2 - 2") which determines
;              which slit tilt value is used.
;
;    YIP    The start pixel on the detector for the exposure. It is
;           stored in FITDATA.YIP, where FITDATA is the output from
;           EIS_AUTO_FIT_NEW.PRO.
;
;    DATE_OBS  String. This is the start time of the observation in
;              the format of the DATE_OBS tag of the EIS FITS header. 
;
; OPTIONAL INPUTS
;
;    REFPIX  The default behavior of the routine is produce a tilt
;            array that has a zero offset at the center of the raster
;            (in Y). By specifying REFPIX one can choose where in the
;            array the zero offset will occur.
;
;    YSTART  This is the same as the YSTART input to EIS_BIN_WINDATA
;            and which is stored in the START_PIX tag of the FITDATA
;            structure produced by EIS_AUTO_FIT_NEW. The default value
;            is zero.
;
; CALLS
;
;    EIS_SLIT_TILT_ARRAY
;
; HISTORY
;
;    Version 1, 2-Feb-2010, Peter Young
;-


IF n_elements(ystart) EQ 0 THEN ystart=0


IF slit_ind EQ 0 THEN slit=1 ELSE slit=2
IF keyword_set(long) THEN short=0 ELSE short=1
dw=eis_slit_tilt(yip,ny*ybin,slit=slit,short=short,long=long,date=date_obs,locations=y0)

y1=yip+ystart+round((ybin-1)/2)+findgen(ny)*ybin

IF n_elements(refpix) EQ 0 THEN refpix=round(mean(findgen(ny)))

y2=spl_init(y0,dw)
tilt_vec=spl_interp(y0,dw,y2,y1)

tilt_vec=tilt_vec-tilt_vec[refpix]

;plot,y0,dw
;oplot,y1,tilt_vec,psym=2

arr=fltarr(nx,ny)
FOR i=0,nx-1 DO arr[i,*]=tilt_vec

return,arr

END
