;+
;
; NAME: 
;	SETUP_BATSE_ARRAYS
;
; PURPOSE: 
;	To initialize and extend accumulation arrays in batse_menu as needed by type.
;
; CATEGORY: 
;	CGRO/BATSE
;
; CALLING SEQUENCE:
;	SETUP_BATSE_ARRAYS, NTIMES_IN=NTIMES_IN, NADD=NADD, EXT_DISCLA=EXT_DISCLA,$
;	EXT_CONT=EXT_CONT, EXT_DISCSP=EXT_DISCSP
;       
; CALLED BY:
;	SETUP_BATSE
;
; CALLS:
;	CHECKVAR, FCHECK
;
; INPUTS:
; KEYWORDS:
;       NTIMES_IN - minimum size to initialize arrays to.  Units of number of seconds for DISCLA
;		1 every 1.024 seconds, or 2 per packet
;	NADD      - size to extend accumulation arrays.  Same units as NTIMES_IN
;	EXT_DISCLA- if set, extend DISCLA arrays
;	EXT_CONT  - if set, extend CONT arrays
;	EXT_DISCSP- if set, extend DISCSP arrays
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; COMMON BLOCKS:
;	fs_saveaccum
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	Extends accumulation arrays by concatenation.
;
; MODIFICATION HISTORY:  
;	Derived from SETUP_ARRAYS written by AKT
;	Version 1, ras, 27-March-1996, explicit memory management
;-
pro setup_batse_arrays, ntimes_in=ntimes_in, nadd=nadd, ext_discla=ext_discla,$
	ext_cont=ext_cont, ext_discsp=ext_discsp
;************************************************************

@fs_saveaccum
common setup_ntimes_batse, ntimes

checkvar, ntimes, ntimes_in, 1000

; don't need to define arrays if they already exist (takes a long time)
if (size(seconds))(1) eq 0 then begin
   discla = fltarr (6,8,ntimes)
   seconds = dblarr (ntimes)
   npack = ntimes/2
   pseconds = dblarr (npack)
   xpos = intarr (npack)
   ypos = intarr (npack)
   zpos = intarr (npack)
   xra = intarr (npack)
   xdec = intarr (npack)
   zra = intarr (npack)
   zdec = intarr (npack)
   livet = fltarr (8,ntimes)
   cont = fltarr (16,8,npack)
   cseconds = dblarr (npack)
   discsp = fltarr (4,8,npack)
   spseconds = dblarr (npack)
   sp_livet = fltarr(8,npack)
   cont_livet = fltarr(8,npack)
   maxindex = 0
   maxposindex = 0
   maxcindex = 0
   maxspindex = 0
endif
if fcheck(nadd,0) gt 0 then begin
	npack = nadd/2
	if keyword_set(ext_discla) then begin
		discla = temporary( [[[discla]],[[fltarr(6,8,nadd)]]])
		seconds= temporary( [seconds, dblarr(nadd)] )
		livet  = [[livet], [fltarr(8,nadd)]]
	endif
	if keyword_set(ext_cont)  then begin
		cont = temporary( [[[cont]],[[fltarr(16,8,npack)]]])
		cseconds= temporary( [cseconds, dblarr(npack)])
		cont_livet  = temporary( [[cont_livet], [fltarr(8,npack)]])
	endif
	if keyword_set(ext_discsp)    then begin
		discsp = temporary([[[discsp]],[[fltarr(4,8,npack)]]])
		spseconds= temporary([spseconds, dblarr(npack)])
		sp_livet  = temporary([[sp_livet], [fltarr(8,npack)]])
	endif
	addpack = max([n_elements(seconds)/2, n_elements(cseconds), n_elements(spseconds)]) $
		 - n_elements(pseconds)
	if addpack gt 0 then begin
		pseconds= temporary( [pseconds, dblarr(addpack)])
		xpos    = temporary( [xpos, intarr(addpack)])
		ypos    = temporary( [ypos, intarr(addpack)])
		zpos    = temporary( [zpos, intarr(addpack)])
		xra     = temporary( [xra, intarr(addpack)])
		xdec    = temporary( [xdec, intarr(addpack)])
		zra     = temporary( [zra, intarr(addpack)])
		zdec    = temporary( [zdec, intarr(addpack)])
	endif
endif

;stop
end

