function get_bcsdat,index, data, chan, nbins, lastbin=lastbin
;
;+
;NAME:
;	get_bcsdat
;PURPOSE:
;	Extract the bins associated with a given channel
;	from the data matrix
;CALLING SEQUENCE:
;	dd = get_bcsdat(index, data, chan)
;	dd = get_bcsdat(index, data, chan, n)
;	dd = get_bcsdat(index, data, chan, /lastbin)
;INPUT:
;	index   - BDA index
;	data    - BDA data array
;	chan	- Channel number (1,2,3,4) where
;		  1 = Fe XXVI
;		  2 = Fe XXV
;		  3 = Ca XIX
;		  4 = S XV
;OPTIONAL INPUT:
;	lastbin - If present, return the last bin.  Default
;		  is not to return the last bin since it is
;		  the "catch-all" for all events of unknown
;		  energy
;OPTIONAL OUTPUT:
;	nbins	- the number of bins in the extracted spectra
;OUTPUT:
;	Returns a matrix (or 1-D vector) of the bins
;RESTRICTIONS:
;	Currently restricted to have all of the modes to have
;	identical modeIDs. 
;HISTORY:
;	Written by M.Morrison 7-Mar-92
;       Modified and renamed from EXT_BCSCHAN by D. Zarro Oct'92.
;        - to issue warning in event of mode change
;        - removed REFORM
;-

nbins = 0
;
if (total(index.bcs.modeid - index(0).bcs.modeid) ne 0) then begin
    message, 'warning, ModeIDs are not all the same',/info
endif

;
ist = 0
if (chan gt 1) then ist = total(index(0).bcs.nsamppchan(0:chan-2))
ien = total(index(0).bcs.nsamppchan(0:chan-1)) - 1 - 1		;one -1 to back up to ending bin of previous spectra
								;the other to avoid the last bin of the spectra to be extracted
;
if (keyword_set(lastbin)) then ien = ien + 1
;
nbins = ien-ist+1
return,data(ist:ien, *)
end
