;+
;
; NAME: 
;       GETFLARE
;
; 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 getflare, burst_id = burst_id, tjd_id = tjd_id, quiet=quiet, $
	num=num, tjd_corresp=tjd_corresp, batse_corresp=batse_corresp

;Takes BATSE Burst ID or TJD + Secs of Day, and...
;
;...if given BATSE Burst ID, returns flare number ("num")
;from the SDAC BATSE archive as well as the TJD + Secs of Day
;that corresponds to the given BATSE Burst ID ("tjd_corresp").
;
;...if given TJD + Secs of Day, returns flare number ("num")
;from the SDAC BATSE archive as well as the BATSE Burst ID
;that corresponds to the given TJD + Secs of Day ("batse_corresp").



checkvar, quiet, !quiet ;if quiet is set, then don't print results

@flare_catalog

batse_read_cat

TYPE:

checkvar, burst_id, 0
checkvar, tjd_id, 0

if (burst_id eq 0) and (tjd_id(0) eq 0) then begin

	print,'Type 0 to enter a BATSE Burst ID (e.g. 920109_45661) or'
	print,'type 1 to enter a TJD + Secs of day (e.g. 8630, 45661) or'
	p=''
	read,'type Q to quit. ',p

	if (p eq 'Q') or (p eq 'q') then goto, GETOUT
	if (p ne '0') and (p ne '1') then goto,TYPE

	if p eq '0' then begin
	  quiet=0
	  burst_id=''
	  read,'Enter BATSE Burst ID (example: 920202_32738): ',burst_id
	  goto,BATSE
	endif

	if p eq '1' then begin
	  quiet=0
	  tjd_id=''
	  read,'Enter TJD + Secs of day (example: 8654, 32738): ',tjd_id
	  goto,TJD
	endif
endif


if burst_id ne 0 then begin

	BATSE:
	
	yy = strmid(burst_id,0,2)
	mm = strmid(burst_id,2,2)
	dd = strmid(burst_id,4,2)
	secsofday = strmid(burst_id,7,5)

	burst_time_batse = utime(yy+'/'+mm+'/'+dd) + long(secsofday)

endif

if tjd_id(0) ne 0 then begin

	TJD:

	vartype = (reverse(size(tjd_id)))(1)

	if vartype eq 7 then begin
		v = parse_comline(tjd_id,nvalues)
		if nvalues eq 1 then v = parse_comline(tjd_id+',00000',nvalues)
		if nvalues ne 2 then goto, GETOUT
		day = v(0)
		secs = v(1)
	endif

	if vartype ne 7 then begin
		day = tjd_id(0)
		secs = tjd_id(1)
	endif

	day = fix(day)

	burst_time_tjd = ((day - 3874)*86400.d0) + long(secs)

endif

if burst_id ne 0 then begin
	q1 = min(abs(burst_time_batse - fldata.start_secs),n1)
	num = (fldata.flare_num)(n1)

	if not quiet then $
	  print,'The flare number for '+strtrim(burst_id,2)+' is ' $
	  +strtrim(num,2)+'.'

	corresp_date=long(((burst_time_batse - long(secsofday))/86400) + 3874)
	tjd_corresp=[corresp_date,long(secsofday)]	

	if not quiet then begin
	  tjd_corresp_print = string(tjd_corresp)
	  tjd_corresp_print = strtrim(tjd_corresp(0),2) + ', ' + $
		strtrim(tjd_corresp(1),2)
	  print,'The TJD + Secs of Day for '+strtrim(burst_id,2)+' is: '+ $
	  	tjd_corresp_print+'.'
	endif
endif

if tjd_id(0) ne 0 then begin

	q2 = min(abs(burst_time_tjd - fldata.start_secs),n2)
	num = (fldata.flare_num)(n2)

       	if not quiet then begin
	  tjd_id_print = strtrim(day,2)+', '+strtrim(secs,2)
          print,'The flare number for '+tjd_id_print+' is ' $
	    +strtrim(num,2)+'.'
	endif

        parse_atime, burst_time_tjd-secs, year=yr, month=mo, day=da, $
           sec=sssss, /st
	batse_corresp = yr+mo+da+'_'+sssss	
	if not quiet then $
	  print,'The BATSE Burst ID for '+strtrim(tjd_id_print,2)+' is '+ $
	  batse_corresp+'.'
endif

GETOUT:
return
end
