;+
; NAME:
;	MK_BSA
; PURPOSE:
;	to produce a BSA structure that contains information
;       to guide the production of a BSC file via MK_BSC.
; CALLING SEQUENCE:
;	MK_BSA,BDA_INDEX,BSA_INDEX
; INPUTS:          
;	BDA_INDEX    - an array of BDA index (or roadmap) structures
;
;       BSA_INDEX    - an initial BSC index structures with fields
;                      set according to user specifications described below.
;                      The BSA_INDEX will be input to MKBSC to create a BSC
;                      file.
; KEYWORDS:
;       CHANS        - channels to select:
;                      e.g. CHANS=1 to select channel 1, 
;                      CHANS=[1,4] to select channels 1 and 4, etc.
;                      Default is [2,3,4] channels.
;
;       ACCUM        - seconds of integration to accumulate spectrum:
;                      e.g. ACCUM=3 to accumulate all desired channels 
;                      with 3 second intervals; ACCUM=[3,10] to use 3 and 10
;                      second intervals in channels selected via CHAN, etc.
;                      Setting ACCUM=0 will deliver the highest available time
;                      resolution. Default is 9 sec accumulation.
;
;       THRESH       - threshold counts upon which to base accumulation time.
;                      e.g. THRESH=100 to accumulate all desired channels
;                      until 100 counts is reached; THRESH=[100,200] to 
;                      accumulate data in channels selected via CHAN 
;                      until 100 and 200 counts are reached, etc.
;                      Default is NO threshold (THRESH=0).
;      
;       DEADTIME     - 0 = no deadtime correction
;                      1 = use LIM/ACC DP_SYNC counts
;                      2 = use SUM(LIM)/SUM(ACC) counts were SUM is taken over
;                          channel 1 & 2, and 3 & 4.
;       DT_INTERP    - 1 = interpolate zero deadtime factors
;                        = do not interpolate
;
;       FLUXCAL      - 1 = convert count rates to photon flux
;                      0 = do not flux calibrate
;
;       WAVECAL      - 1 = apply wavelength calibration to spectra
;                      0 = do not wavelength calibrate
;   
;       BLOCKID      - Block ID to select (def=0; normal)
;
;       MODEID       - Mode ID to select (def=all)
;
;       XCORR        - 1 = apply crystal curvature corrections
;                      0 = do not correct for curvature
;
;       TRANGE       - [TSTART,TEND] time range to confine processing,
;                      where TSTART.TIME=MSOD, TSTART.DAY=DS79, etc.
;                      Default is to process all data times in BDA_INDEX.
;
;       ERR          - 1 if failed else 0
;
; PROCEDURE:
;                      Calls MK_BSA_STC and MK_BSA_INTERV
; HISTORY:
;                      Written Apr'93 by D. Zarro (Applied Research Corp).
;-


pro mk_bsa,bda_index,bsa_index,chans=chans,accum=accum,thresh=thresh,$
          deadtime=deadtime,fluxcal=fluxcal,xcorr=xcorr,modeid=modeid,$
          blockid=blockid,err=err,trange=trange,wavecal=wavecal,$
          dt_interp=dt_interp,verbose=verbose
                              
on_error,1

if n_params() eq 0 then begin
 message,'usage --> MK_BSA,BDA_INDEX,BSA_INDEX'
endif

;-- make initial BSA structure with user requests

mk_bsa_stc,bsa_index,chans=chans,accum=accum,thresh=thresh,$
          deadtime=deadtime,fluxcal=fluxcal,xcorr=xcorr,modeid=modeid,$
          blockid=blockid,wavecal=wavecal,dt_interp=dt_interp

;-- now compute time intervals for accumulation


mk_bsa_interv,bda_index,bsa_index,trange=trange,err=err,verbose=verbose


return & end

