function sxt_adjacent_image, times, init=init, $
   preceding=preceding, before=before, after=after, following=following, $
   exact=exact, dts=dts, debug=debug
;
;+
;   Name: sxt_adjacent_image
;
;   Purpose: return observing log records for preceding/following  
;
;   Input Parameters:
;      times - index/roadmap/times of desired images
;
;   Output:
;      function returns observing logs (inc times...) of image
;      immediately preceding or following input
;
;   Keyword Parameters:
;     before/preceding (synonyms) - return preceding image info
;     after/following  (synonyms) - return following image info [DEFAULT]
;     exact - if set, return eact match (or closest) from obslog
;  
;   Calling Examples:
;      preceding=sxt_adjacent_image(index,/before)
;      subsequent=sxt_adjacent_image(index,/after)
;      exact=sxt_adjacent_image(index,/exact)
;
;   History:
;      7-Aug-2001 - S.L.Freeland     
;
;-


common sxt_adacent_image_blk,t0, t1, sxtimages

debug=keyword_set(debug)

if n_elements(t0) eq 0 then begin 
   t0=''
   t1=''
endif

time_window,times,t0in,t1in,minutes=[-30,30]

init=(t0 ne t0in) or (t1 ne t1in) or keyword_set(init)

if init then begin 
   t0=t0in
   t1=t1in
   get_utevent,t0,t1,sxtf,/sxtf            ; full frame
   get_utevent,t0,t1,sxtp,/sxtp            ; partial frame
   sxtimages=sort_index(sxtf,sxtp,/uniq)   ; merged images
endif

nout=n_elements(times)

ss=tim2dset(sxtimages,times,delta=dts)     ; closest 

if max(dts) gt 0 then begin 
   box_message,'Could not find exact image for at least one input'
endif

adjacent=1-keyword_set(exact)
before=keyword_set(before)
after = keyword_set(after) or (1-before)          

retss=ss + (([-1,1])(after)*adjacent)     ; adjust SS as requested
retss=retss>0< (n_elements(sxtimages)-1)

retval=sxtimages(retss)                   ; adjacent subset

if debug then stop

return, retval
end
