;+
;
; Returns the SXT dark variation in DN for an input index.
;

FUNCTION dark_orbit, index, ixref, tim2fms=tim2fms

;
; INPUT PARAMETERS:
;	index = image indices to compute orbital dark variation for.
;	ixref = reference orbital phase.  Either an index structure,
;		or a float specifying Time to First Minute of Sun.
;
; OPTIONAL INPUT KEYWORDS:
;	tim2fms = Time to First Minute of Sun, float.  Default
;		is to call TIM2ORBIT for the input index.
;		
; RETURNS:
;	array of dark corrections, DN, to subtract from the images
;	specified by index to adjust them to the reference time.
;
; RESTRICTIONS:
;	USES LINEAR APPROXIMATION TO ORBITAL TREND.
;
; HISTORY:
;	Written  July 14, 1994  Barry LaBonte
;-

; Linear fit is
;  DN = DN0 + SLOPE * TIM2FMS
;
; with SLOPE = -3.412e-4 * TEXP * BINNING - 3.400e-3   (DN/minute)
; where
;	TEXP = exposure time (seconds)
;	BINNING = pixel area  (Full-res pixels)
;
; Coefficients of linear fit
coeflin = [-3.412e-4, -3.400e-3]


; Handle the inputs
sz = SIZE(ixref)
len = N_ELEMENTS(sz)
IF( sz(len-2) EQ 8 ) THEN TIM2ORBIT, ixref, TIM2FMS=timref ELSE timref = ixref

IF( KEYWORD_SET(tim2fms) EQ 0 ) THEN TIM2ORBIT, index, TIM2FMS=fms  $
	ELSE fms = tim2fms

; Time shifts
delfms = fms - timref
; Binning
res = GT_RES(index)
bins = 2^(2*res)
; Exposure times
texp = GT_EXPDUR(index)/1000.

slope = coeflin(0) * texp * bins + coeflin(1)
orbital = slope * delfms

RETURN, orbital
END
