;+
;
; NAME: 
;       FLARE_FDB
;
; 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:
;
;-
; Routine to check FDB files.  Gets the total number of BATSE flares cataloged.
; Loops through all flare numbers finding their corresponding FDB files.
; Prints message if 
;  1. A flare doesn't have an FDB file
;  2. A flare has more than one FDB file.  Also prints earliest/latest times for
;     flare.
; Writes output in file FLARE_FDB.DAT
;
; Kim Tolbert   7/91
;
;----------------------------------------------------------------------------
;
pro flare_fdb
;
@flare_catalog
;
batse_read_cat
print, 'Number of flares in catalog = ',num_flares

earliest = (fldata.bkg1_start_secs<fldata.start_secs)
latest = (fldata.bkg2_start_secs+fldata.bkg2_duration > $
         (fldata.start_secs+fldata.duration))
;
openw, lunout, 'flare_fdb.dat', /get_lun
for i = 1,num_flares do begin
   strnum = strtrim (string(i),2)
   files = findfile (concat_dir((chklog('BATSE_FDB'))(0),'*.fdb_'+strnum), count=count)
;   print,strnum,count,files
   index = where(fldata.flare_num eq i, fcount)
   if fcount gt 1 then printf, lunout, fcount, $
      ' entries with number ',i, 'in catalog.'
   if index(0) eq -1 then begin
      printf, lunout, 'There is no flare ',i  
   endif else begin
      if count eq 0 then printf,lunout, 'Flare with no fdb file = ',i
      if count gt 1 then printf,lunout, 'Flare with > 1 fdb file = ',i
      if count ne 1 then printf,lunout, 'Flare earliest, latest times = ',$
          atime(earliest(index(0))), '  ', atime(latest(index(0)))
      if count gt 1 then printf,lunout, files
      if count ne 1 then printf,lunout, ' '
   endelse
endfor

print, 'Output written in FLARE_FDB.DAT'
free_lun, lunout
return&end
