;+
;
; NAME: 
;       CHECK_GAIN_ANGLE
;
; PURPOSE:
;	This is a main program for examining the calibration and attitude
;	history of the BATSE mission.
;
; CATEGORY:
;	BATSE
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; INPUTS:
;       main program unit
;
; 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:
;
;-

batse_read_cat
; 
;Reading BATSE flare catalog ...                                                 
@flare_catalog

setup_batse

edges=fltarr(3,8,1000)
cspecs=fltarr(8,1000)
clads = fltarr(8,1000)

for i=0,3999,4 do begin

  endtime = fldata(i).start_secs + 300

  fdbread,t,y, flare=i+1, endtime=endtime
  edg=discsp_edges(t(0)+getutbase())
  spec_point, cos_det=cos_det, cos_spec=cos_spec,inradec=crab_radec

  if i mod 10 eq 0 then begin
	print, 'Flare ',i+1
	print, edg(0:2,*)
	print, cos_spec(*,0)
  endif


  edges(0,0,i/4) = edg(0:2,*)
  w0 = ( where( total( abs(cos_det),1) ne 0))(0)>0

  cspecs(0,i/4) = cos_spec(*,w0)
  clads(0,i/4) = cos_det(*,w0)
  if i mod 100 eq 0 then save,file='check_gain_angle.sav',edges,cspecs,clads

endfor
end
