;+
; NAME:
;	EXTRACT_TRIGGERS
;
; PURPOSE:
;	Extracts the times of BATSE flare triggers from the trigger file
;	obtained from the BATSE PI team at Marshall Space Flight Center.
;
; CATEGORY:
;	BATSE
;
; CALLING SEQUENCE:
;	EXTRACT_TRIGGERS, B_num, B_tjd, B_secs
;
; INPUTS:
;	None - reads database file Burst_trigger.lst on BATSE_DATA
;
; OUTPUTS:
;	B_num: Trigger number from spacecraft and MSFC
;	B_tjd: Truncated Julian Day of trigger
;	B_secs: Seconds in day of trigger
;
; PROCEDURE:
;	Read the database file and parse it.
;Trigger List has a format like the following :
;
; Burst Trunc  Sec  Comments
;  No.   JD  of day
;   146  8380 65642 Single peak lasting 30 s, with some structure.  Channel 3.
;                   GOES C flare.
;   151  8382 58292 Single peak with structure lasting 15 seconds.  Channel 2.
;                   GOES C flare.
;   155  8382 84146 Multiple. Triggered on precursor lasting about 20 s.  Main
;                   peak lasting 300 s, came 200 s later.  Channel 2.
;
; MODIFICATION HISTORY:
; 	Written by:	RAS
;	December, 1995
;       Modified by:   AES 97/02/18  Checked for mail-generated trailers
;		at the end of burst_trigger.lst.  Assumed anything after
;		the trailer would be bogus.
;-
;
pro EXTRACT_TRIGGERS, B_num, B_tjd, B_secs, error=error

;
;
checkvar, filename, concat_dir((chklog('BATSE_DATA'))(0),'burst_trigger.lst')
file = (findfile(filename, count=error))(0)
error = 1-error
if error then begin
	message,filename + ' not found. Error.'
	return
endif
read_seqfile, s, file
; s now contains all lines read from file.  We want s to contain only
; the first line of data (some entries take two lines).
; Find first line of data in file (we know it is burst no. 146)
q = where (strmid(s,0,7) eq '    146')
; Get rid of header info.
s = s(q(0):*)
; Get rid of completely blank lines
notblank = where(s ne '')
s = s(notblank)
; Get rid of second line for an entry (burst entry will be blank)
data_lines = where(strmid(s,0,7) ne '       ')
s = s(data_lines)

;Look for all blank lines with spaces and remove
q = where( strtrim(s,2) ne '')
s = s(q)
;
;   Eliminate any events saying unclassified triggers
;
q = where( strpos(strupcase(s), 'UNCLASSIFIED TRIGGERS') eq -1)
s = s(q)
;
;   Check for trailing mailer information in the extracted message,
;	and delete if there is any.  Assume anything after an RFC
;	trailer is bogus.
;
q = where( strpos(strupcase(s), 'RFC') ne -1, count)
if (count ne 0) then s=s(0:(q(0)-1))
;
print,'Burst list contains ',n_elements(s), ' bursts.'
;                                                   
;Extract appropriate columns of information into three arrays (b_num_arr
;for Burst Trigger Number; b_tjd_arr for TJD of burst; and b_trig_secs_arr for
;triggertime of burst in seconds of day).
;
b_num = fix(strmid(s,0,7))
b_tjd = fix(strmid(s,8,5))
b_secs = long(strmid(s,14,5))
;
end
