;+
; NAME:
;       BCS_DSPEC
; PURPOSE:
;       Extracts, decompresses and normalizes the data for a single
;       channel from the BDA data array
; CATEGORY:
; CALLING SEQUENCE:
;       cspec = bcs_dspec(index,data)
;       cspec = bcs_dspec(index,data,chan=n)
;       cspec = bcs_dspec(index,data,ss=ss,new_index=cindex)
; INPUTS:
;       index           BDA index structure
;       data            BDA data array
; KEYWORD INPUT PARAMETERS:
;       chan            channel to be extracted  (def=3, Ca XIX)
;       ss              vector of sub-array of times to be extracted
; OUTPUTS:
;       array contains decompressed, normalized counts for selected channel
; KEYWORD OUTPUT PARAMETERS:
;       new_index       sub-array of index correspending to ss vector
; COMMON BLOCKS:
;       none
; SIDE EFFECTS:
;       Last bin of data array of channel removed. This is catch-all for
;       position encodes whose total energy is marginal
; RESTRICTIONS:
;       Only works on BDA data
; PROCEDURE:
;       In approximation does:
;       cdata = bcs_norm(index,bcs_decomp(ext_bcschan(index,data,channel)))
; MODIFICATION HISTORY:
;       RDB   7-Jan-94  Written
;-

function        bcs_dspec,index,data,chan=chan, $
                        ss=ss,new_index=new_index

;       default to channel 3 if none specified
channel = 3
if keyword_set(chan) then channel=chan
if channel le 0 or channel gt 4 then message,'Channel out of range'

;       extract data for the channel, and for time if selected
;       last bin "lost" since this is catch-all (need /lastbin in ext_bcschan)
;       then decompress and normalize for integration time
if keyword_set(ss) then begin
  chan_data = ext_bcschan(index(ss),data(*,ss),channel)
  dspec = bcs_norm(index(ss),bcs_decomp(chan_data))
  new_index = index(ss)
endif else begin
  chan_data = ext_bcschan(index,data,channel)
  dspec = bcs_norm(index,bcs_decomp(chan_data))
endelse

return,dspec
end
