;+
; Name:
;   	EIS_SLOTOVERLAP
;   
; Purpose:
;   	To give an initial estimate of the overlap array that 
;   	can be used in routines like EIS_READSLOT.PRO.
;
; Calling Sequence:
;   	IDL> overlap=eis_slotoverlap(data)
;
; Inputs:
;   	DATA	:   data structure as given by EIS_GETWINDATA.PRO
;
; Outputs:
;       OVERLAP :   overlap in pixels between slots with adjacent pointing. 
;                              OVERLAP=[overlap,leftcrop,rigthcrop]
;                   where: overlap = leftcrop + rightcrop
;                   LEFTCROP and RIGHTCROP determine the amount to be cropped 
;                   from each side of individual slots when merging. Their sum 
;   	    	    is the total overlap. See EIS_READSLOT.PRO.
;   	    	
;   	    	    As a first estimate, leftc = overlap/2 and rightc = overlap - leftc
;
;
; Keywords:
;
; Example:
;   	IDL> data=eis_getwindata('eis_l0_20080815_195226.fits',195.1)
;   	IDL> overlap=eis_slotoverlap(data)
;   	IDL> print,overlap
;   	      12.0000      6.00000      6.00000
;   	IDL> eis_readslot,'eis_l0_20080815_195226.fits', out, overlap=overlap
;   	IDL> plot_image,alog10(out.int)
;
;
; Modification History:
;   	20090813    I. Ugarte-Urra. NRL
;   	20090824    IUU     Return 0 when fmir step size is 0.
;   	20100315    IUU     Deal with negative excess. Return [0.,0.,0.].
;-

FUNCTION eis_slotoverlap, data

slitsize = float(str2number(data.hdr.slit_id))
if slitsize lt 40 then begin
    message,'Narrow slit. Aborting...',/info
    return,-1
endif

wvl = n_elements(data.wvl)
stepsize = data.hdr.fmir_ss/4
if stepsize ne 0 then begin 
    excess = wvl - slitsize
    if excess lt 0 then return,[0.,0.,0.]	;Corrupt data? or weird choice?
    overlap = slitsize - stepsize + excess
    leftc=overlap/2
    rightc=overlap-leftc
    overlap=[overlap,leftc,rightc]
endif else overlap=[0.,0.,0.]

return,overlap
END
