;+
;
; NAME: 
;       GET_TRIG
;
; PURPOSE:
;
;
; CATEGORY:
;       BATSE
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	none
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	none
;
; MODIFICATION HISTORY:
;
;-
pro get_trig, flare=flare, in_secs=in_secs, in_sece=in_sece, $
   utburst_trig=utburst_trig, burst_num = burst_num

;GET_TRIG takes IN_SECS (a time in seconds since 79/1/1, 0000) as input
;and returns UTBURST_TRIG (the triggertime (in secs rel to 79/1/1, 0000) of
;the burst whose start time is closest to the in_secs time inputed.) Or,
;if the flare keyword is defined, returns the burst trigger time for that 
;flare.
;
;Written to be used with FSPLOT and FLDISPLAY programs.

@flare_catalog

batse_read_cat
checkvar, quiet, !quiet
checkvar,in_secs, 0

if keyword_set(flare) then begin
   q=where (fldata.flare_num eq flare,count)
   if count eq 0 then goto,notrig
   index = q(0)
endif else begin
   if in_secs eq 0 then begin
      quiet = 0
      alpha_page
      read,'INPUT START TIME OF BURST IN SECS REL TO 79/1/1? ',in_secs
   endif

;   temp = min(abs(in_secs - fldata.start_secs),index)
;  Changed to find first burst trigger within plot interval, 3/18/93 AKT
   q = where (fldata.burst_trig_secs ne 0, count)
   bst = 86400.d0 * (fldata(q).burst_tjd - 3874) + fldata(q).burst_trig_secs
   qq = where (bst ge in_secs and bst le in_sece, count2)
   if count2 gt 0 then index = q(qq(0)) else goto, notrig
endelse

;print,index,fldata(index).flare_num, atime(fldata(index).start_secs)

if fldata(index).burst_trig_secs eq 0 then goto,notrig
burst_num = fldata(index).burst_num
utburst_trig = 86400.d0 * (fldata(index).burst_tjd - 3874) + $
               fldata(index).burst_trig_secs 
if not quiet then print,'BURST TRIG SECS in UT is ', utburst_trig
goto, getout

notrig:
utburst_trig = 0 
burst_num = 0

GETOUT:
return
end
