; Reads flare catalog into common flare_catalog if it hasn't been read yet,
; checks that requested flare is available and returns the record number
; and structure of that flare.
; Calling arguments:
;   iflare - (input) flare number to get from catalog
;   flare_rec - (output) structure containing record for flare from catalog
;   recordn - (output) record number containing flare iflare (counting 
;             from 0 from beginning of flare records - offset by one from
;             header record.  Flare i is in record i-1)
;   error - (output) =1 if flare not available, 0 otherwise
;
; Kim Tolbert 7/91
;
;+
;
; NAME: 
;       READ_FLARE
;
; 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:
; Version 2, richard.schwartz@gsfc.nasa.gov, 13-jun-2000. Generate error if
;	batse_flare_catalog not readable(available).
;
;-
pro read_flare, iflare, flare_rec, recordn = recordn, error = error
;
@flare_catalog
;
error = 0
;
; Read flare catalog into common flare_catalog if it hasn't been read yet.
batse_read_cat, error=error
if error then goto, getout
;
if iflare lt 0 or iflare gt num_flares then begin
   print, 'Error. Flare numbers range between 1 and ',num_flares
   goto,errorexit
endif
;
rec = where (fldata.flare_num eq iflare, count)
if count eq 0 then begin
   print,'No flare numbered ',iflare, ' in catalog.'
   goto,errorexit
endif
if count gt 1 then print,'Error.  More than one flare numbered ',iflare
;
recordn = rec(0) + 1
flare_rec = fldata(rec(0))
goto,getout
;
errorexit:
error = 1
goto,getout
;
getout:
return&end
