pro pr_gbe, st_date, en_date, above=above, qstop=qstop, outfile=outfile, $
	hc=hc, event=event, data=data
;
;+
;NAME:
;	pr_gbe
;PURPOSE:
;	To list the GRO/BATSE events
;CALLING SEQUENCE:
;	pr_gbe, '1-jan
;	pr_gbe, '30-oct-91', '2-nov-91', /hc
;	pr_gbe, event=3944
;INPUT:
;	st_date	- The JST date to search for.  If no date is entered,
;		  the current date is used.  The year is not
;		  required, but if entered should be of the
;		  form 1-Oct-91 style.  The date should be
;		  entered in string style with date first.
;OPTIONAL INPUT:
;	en_date	- The ending date to list data for.  If no date is passed,
;		  it only searches for "st_date"
;OPTIONAL KEYWORD INPUT:
;	above	- If passed, then only list events that have a counting 
;		  rate above this value
;	event	- If passed, only list event with this BATSE event number.
;	
;	outfile	- If a filename is passed, the results will also
;		  be written to that file
;	hc	- If set, write the results to a temporary file, print
;		  it and delete it.
;OUTPUT:
;	The times and classes of the GOES events
;HISTORY:
;	Written 13-Apr-93 by M.Morrison
;	RDB   6-Aug-93  Added /event keyword
;-
;
qhc = 0
qout = 0
if (keyword_set(outfile)) then begin
    openw, lunout, outfile, /get_lun
    qout = 1
end
if (keyword_set(hc)) then begin
    openw, lunhc, 'pr_gbe.temporary', /get_lun
    qhc = 1
end
;
if (n_elements(st_date) eq 0) then begin
    st_date = strmid(!stime, 0, 6)
end else begin
    ; If the date was provided, make sure to add a yr if none provided:
    day_arr = timstr2ex(st_date)
    if day_arr(6) eq 0 then day_arr(6) = fix(strmid(!stime,9,2))
    ;;dummy = fmt_tim(day_arr, day_str, time_str)
    ;;st_date = day_str
    st_date = fmt_tim(day_arr)
end
;
day_arr1 = timstr2ex(st_date)
;
if (n_elements(en_date) eq 0) then begin
    ex2int, day_arr1, time, day
    int2ex, time, day+1, day_arr2		;just end 24 hours later
end else begin
    day_arr2 = timstr2ex(en_date)
end
;
if (n_elements(above) eq 0) then above = 0.0
;
if keyword_set(event) then begin		;look for given event no.
    rd_gbe,'1-sep-91',strmid(!stime, 0, 6),gbe_data
    qw = where(gbe_data.event eq event)
    if qw(0) eq -1 then begin
	print, 'PR_GBE: Event not available: ',event
	return
    endif
    gbe_data = gbe_data(qw)
endif else begin
    rd_gbe, fmt_tim(day_arr1), fmt_tim(day_arr2), gbe_data, status=status
    if (status gt 0) then begin
	print, 'PR_GBE: No events available between ', fmt_tim(day_arr1), ' and ', fmt_tim(day_arr2)
	return
    end
endelse
;
;
tit = strarr(5)
tit(0) = 'PR_GBE.PRO Run on: '+ !stime
tit(1) = '  '
tit(2) = '   Date             Time (UT)       Duration  Event     Peak      Total
tit(3) = '             Begin     Max     End    (sec)    Num      Rate      Cnts
tit(4) = '  '
        ;' 8-APR-93  20:33:46 20:37:42 20:46:17   751  3874      8243.2   1812093.6
;
for i=0,n_elements(tit)-1 do begin
    print, tit(i)
    if (qhc) then printf, lunhc, tit(i)
    if (qout) then printf, lunout, tit(i)
end
;
qfirst = 1
for i=0,n_elements(gbe_data)-1 do begin
    gbe = gbe_data(i)
    rate = gbe.cnts_peak

    qwrite = (rate gt above)
    if (qwrite) then begin
	tim1 = fmt_tim(gbe)
	tim2 = gt_time( anytim2ints(gbe, off=gbe.peak) , /str)
	tim3 = gt_time( anytim2ints(gbe, off=gbe.duration), /str)
	str = string(tim1, tim2, tim3, gbe.duration,  gbe.event, gbe.cnts_peak, gbe.cnts_total, $
							format='(3(a,1x), i5, i6, 2f12.1)')

	print, str 
	if (qhc) then printf, lunhc, str
	if (qout) then printf, lunout, str
    end
end
;
if (qhc) then begin
    free_lun, lunhc
    dprint, 'pr_gbe.temporary', /delete
end
if (qout) then free_lun, lunout
if keyword_set(data) then data = gbe_data
;
if (keyword_set(qstop)) then stop
end


