

function eis_orbit_spline_quick, intime, wd, tt

;+
; NAME
;
;    EIS_ORBIT_SPLINE_QUICK()
;
; PROJECT
;
;    Hinode/EIS
;
; EXPLANATION
;
;    Represents the orbital variation of EIS line centroids by a spline
;    function with nodes spaced at 5 minute intervals. Returns the value
;    of the centroid at the input times.
;
; INPUTS
;
;    INTIME  The times for which you want the centroid position.
;
;    WD   The data array produced by data->getvar(). This array needs to be
;         de-biased before input to this routine. Otherwise it can be in
;         any form (DN, photons, intensity).
;
;    TT   The start time of each exposure in WD.
;
; OUTPUT
;
;    The shift(s) of the emission line centroid in angstroms at the specified
;    time(s) (INTIME), relative to the first exposure.
;
;    To correct a measured line centroid for the orbital variation one would
;    thus subtract the value derived from this routine from the measured
;    value.
;
; CALLS
;
;    LINE_CENTROID
;
; HISTORY
;
;    Ver.1, 21-Feb-2007, Peter Young
;    Ver.2, 27-Jul-2009, Peter Young
;      Routine now checks for exposures with anomalously large
;      exposure start times (which are due to missing data), and also
;      filters out exposures where there are no data at all (so
;      centroid can not be determined).
;    Ver.3, 30-Jul-2009, Peter Young
;      Changed call to non-Solarsoft routine ave() to mean().
;-

missing=-100

; Collapse the 3D array along the slit (2nd dimension)
wdx=average(wd,2,missing=missing)

siz=size(wdx)
nx=siz[2]
nl=siz[1]

x=findgen(nl)

cen=fltarr(nx)

FOR i=0,nx-1 DO BEGIN
  y=wdx[*,i]
  IF max(y) NE min(y) THEN BEGIN
    line_centroid,x,y,cent,/silent
    cen[i]=cent
  ENDIF ELSE BEGIN
    cen[i]=-100.   ; set to arbitrary large negative value
  ENDELSE 
ENDFOR 


;
; convert cen from pixels to wavelength
;
k=where(cen GE 0.)
av_cen=mean(cen[k])
cen[k]=(cen[k]-av_cen)*0.0223
scen=cen
;scen=smooth(cen,5,missing=-100.)

;
; Since the antenna problems there are often exposures that get
; assigned incorrect exposure start times of > 1e6 s. This caused
; problems for eis_orbit_spline_quick so I now filter out these
; points. 
;
k=where(tt LE 1e5 AND scen,nk)
;
; Convert times to minutes
;
t=tt[k]/60.

scen_k=scen[k]
intime_k=intime[k]

;
; For the spl_init and spl_interp routines to work, the T array has to be
; in ascending order, so need to check for this.
;
IF t[1] LT t[0] THEN BEGIN
  t=reverse(t)
  scen_k=reverse(scen_k)
ENDIF


;
; define a spline (ti,yi) with nodes at every 5 minutes
;
t_max=fix(max(t)/5)*5
ti=findgen(t_max/5+1)*5
y2=spl_init(t,scen_k)
yi=spl_interp(t,scen_k,y2,ti)

y2=spl_init(ti,yi)  

outcen=spl_interp(ti,yi,y2,intime_k/60.)

;
; The following sets any points with bad exposure start times to have
; a centroid shift of zero.
; 
IF n_elements(outcen) LT nx THEN BEGIN
  outcen2=fltarr(nx)
  k=where(tt LE 1e5,nk)
  outcen2[k]=outcen
  outcen=outcen2
ENDIF


return,outcen

END
