;+
;
; NAME: 
;       FLARE_MARK
;
; PURPOSE:
;
;
; CATEGORY:
;       BATSE
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       F_start: start time  of flare interval in seconds from utbase
;	F_end: end time of flare interval in seconds from utbase
;	abort: if set, then no background is selected
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	none
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	none
;
; MODIFICATION HISTORY:
; Shelby Kennard                                  1Mar1991
; Version 2, RAS, 8 Aug 1996 to work with X windows cursors!
;
;-
pro flare_mark,f_start,f_end,abort
;
xi = !x.s
abort = 0
;
; Get x and y window limits.
;
l = !x.window(0)
r = !x.window(1)
b = !y.window(0)
t = !y.window(1)

if !d.name ne 'X' then begin

;
start:
;
cursor,x1,y1
;
; Make sure key pressed was a valid letter.
;
if !err lt 65 or !err gt 122 then begin
    goto,start
endif
;
; Determine if 'Q' was press. If so, abort.
;
if !err eq 81 or !err eq 113 then begin
    abort = 1
    goto,finish
endif
;
vert_line,x1,2
;
; Label start line with 'I' character.
;
nx1 = xi(0) + xi(1)*x1
nx1lab = nx1 + .0081
ylab = t - .03
xyouts,nx1lab,ylab,'I',/normal
;
;
restart:
cursor,x2,y2
;
; Make sure key pressed was a valid letter.
;
if !err lt 65 or !err gt 122 then begin
    goto,restart
endif
;
; Determine if 'Q' was pressed. If so, abort.
;
if !err eq 81 or !err eq 113 then begin
    abort = 1
    goto,finish
endif
;
vert_line,x2,3
;
if x1 ge x2 then begin
  xyouts,l+.02,t-.06,'Flare end can not be earlier or equal to flare start,'+$
  ' try again.',/normal
  goto,restart
endif
;
f_start = x1
f_end = x2
;
finish:
;
endif else begin
;
;******************************************************************************
;	X WINDOWS INTERVAL SELECTION
xstart:
buttons = ['Select in Plot Window','Quit without Selection']
val_buttons=['X','T']
abort = 0

point, b1, yblabel, /drawline, /widget, linesty=2, npoints=2, buttons=buttons, $
	val_buttons=val_buttons, newlabel='Select Flare Interval'

f_start = min(b1)
f_end   = max(b1)
bnum=1
;
; Determine if 'Quit' was pressed. If so, abort.
;
if datatype(b1) eq 'STR' then $
if b1(0) eq 'null' then begin
    abort = 1
    goto,xkill
  endif
;
; Label start line with 'I' character.
;
xyouts,f_start,yblabel,'I'

;
;
;
xkill:
;
endelse

end
