;+
;
; NAME: 
;       OUT_ARR
;
; 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 out_arr, seconds, bdb, cos, arr_out, top4
;
; Return output arrays that fit the quicklook plot requirements.
;
; Shelby Kennard                         17January1991
; Re-written to not use temporary arrays (takes too much space) - just use
; bdb.disk directly.  Kim
;****************************************************************
common quick_com, plot_st, plot_en, first_sec, fctr
;
; Create an integer array with dimension equal to the number of data samples
; by 8.
;
data_siz = size(bdb.disc)
num_samp = data_siz(4)*2
;
arr_out = fltarr(num_samp, 8)
;
; Extract the indexes for the top 4 and bottom 4 cosine values from the 
; pointing cosine array.
;
cos_det = cos
cosines = cos_det(*,0)
chg_ndx = rotate (sort(cosines),2)  ; sort into decreasing order
top4 = chg_ndx(0:3)    ; top4(0) is most sunward det, top4(3) least
low4 = chg_ndx(4:7)    
;
; Accumulate arrays for 4 most sunward detectors.
;
for j=0,3 do begin
   arr_out(*,j) = (bdb.disc(0,top4(j),*,*) and 65535)
endfor
;
; Accumulate array for sum of 4 sunward detectors, corrected for aspect.
;
arr_out(*,4) = (bdb.disc(0,top4(0),*,*) and 65535) + $
               (bdb.disc(0,top4(1),*,*) and 65535) + $
               (bdb.disc(0,top4(2),*,*) and 65535) + $
               (bdb.disc(0,top4(3),*,*) and 65535) 
;
; Acumulate array for sum of 4 anti-sunward detectors.
;
arr_out(*,7) = (bdb.disc(0,low4(0),*,*) and 65535) + $
               (bdb.disc(0,low4(1),*,*) and 65535) + $
               (bdb.disc(0,low4(2),*,*) and 65535) + $
               (bdb.disc(0,low4(3),*,*) and 65535) 
;
; Accumulate array of 4 sunward CPDs (stored as channel 6)
;
arr_out(*,6) = (bdb.disc(5,top4(0),*,*) and 65535) + $
               (bdb.disc(5,top4(1),*,*) and 65535) + $
               (bdb.disc(5,top4(2),*,*) and 65535) + $
               (bdb.disc(5,top4(3),*,*) and 65535) 
;
; Accumulate array of channel 2 for 4 sunward detectors 
;
arr_out(*,5) = (bdb.disc(1,top4(0),*,*) and 65535) + $
               (bdb.disc(1,top4(1),*,*) and 65535) + $
               (bdb.disc(1,top4(2),*,*) and 65535) + $
               (bdb.disc(1,top4(3),*,*) and 65535) 
;
return&end
