;
;+
;
; Returns the Observing Log information for SXT terminator images.
;

PRO term_obs, weekid, sxtf, time2set, suncent

;
; INPUT PARAMETERS:
;	week_id = year and week number, string, e.g. '94_12'
;
; OUTPUT PARAMETERS:
;	sxtf = FFI observing log structure for all valid terminators
;		during the specified week.
;	time2set = time in seconds,  image time minus sunset time.
;	suncent = sun center position in SXT Full resolution pixels,
;		dimensioned 2 x n.
;
;
; PROCEDURES CALLED:
;	TERM_TIMES, TIM2ORBIT, GET_SUNCENTER
;
; HISTORY:
;	Written June 7, 1994  Barry LaBonte
;	Add sun center positions  June 10, 1994  BJL
;
;-

; Check input for error
wkid = weekid
IF( STRMID(weekid, 2, 1) EQ '-' ) THEN STRPUT, wkid, '_', 2

; Get the terminator times

times = TERM_TIMES(WEEKID=wkid)
ntimes = N_ELEMENTS(times)

IF( ntimes GT 0) THEN BEGIN
	first = 1

; Look in a 4 minute window
	ctim = ANYTIM2INTS(times)
	stim = ctim
	etim = ctim
	stim.time = stim.time - 120000
	etim.time = etim.time + 120000

	FOR i=0,ntimes-1 DO BEGIN

		RD_OBS, stim(i), etim(i), bcs, sxt, /NOBCS
; Is there a valid image?
		sz = SIZE(sxt)
		IF( sz(0) NE 0) THEN BEGIN
; Get actual sunset time
			TIM2ORBIT, sxt, TIM2NIGHT=offs
			offs = -60. * offs
			sunc = GET_SUNCENTER( INDEX=sxt )
			IF( first EQ 1 ) THEN BEGIN
				sxtf = sxt
				time2set = offs
				suncent = sunc(0:1,*)
				first = 0
			ENDIF ELSE BEGIN
				sxtf = STR_CONCAT(sxtf, sxt)
				time2set = [time2set, offs]
				suncent = [[suncent],[sunc(0:1,*)]]
			ENDELSE
		ENDIF
	ENDFOR
ENDIF

RETURN
END

