;+
; NAME:				GET_BSD v0.9
;
; PURPOSE:			Read BSD files into IDL
;
; CALLING SEQUENCE:  		GET_BSD
;
; INPUTS:			none - all prompted for
;
; OUTPUTS:			Data structures as described in BSD_STRUCT.PRO
;				bsd_header - header of file
;				bsd_rdmap  - roadmap
;				bsd_index  - record headers 
;				bsd_data   - bins/counts/wave 
;
; OPTIONAL OUTPUTS:		none
;
; RESTRICTIONS:			
;
; PROCEDURE:			calls in order
;					bcs_getfile 
;					rd_bsd_header 
;					rd_bsd_rdmap
;					rd_bsd_data			
;
; MODIFICATION HISTORY:
;
;		JTM: (24 Oct 91) Blatant ripoff of test_rd
;
;		JTM: (13 Jan 92) Fixed so that files with
;		  less than 4 channels can be read
;
;		ATP: (13 may 92) Updated to use new structures.
;		
;		ATP: (6 july 92) changed bcs_getfile.pro
;
;		ATP: (7/7/92)    Several fixes 
;
;-
;
print, ''
print, 'get_bsd V0.9 (7 july 92)'
print, ''
;
; define the structures - needs bsd_struct vn 0.9
;
bsd_struct
;
; get filename
;
bcs_getfile,filename,defstr="bsd*.*"
if (filename eq '-1') then stop
;
;
break_file, filename, dsk_log, dir, filnam, ext
;
; Read the header
;
rd_bsd_header, filename, bsd_header
print, 'File: ', filename
print, 'Total spectra:', bsd_header.totspc
print, '    Channel 1 spectra:', bsd_header.numchn(0)
print, '    Channel 2 spectra:', bsd_header.numchn(1)
print, '    Channel 3 spectra:', bsd_header.numchn(2)
print, '    Channel 4 spectra:', bsd_header.numchn(3)
;
maxdat = max(bsd_header.numchn(*))
;
; Read the roadmap 
;
rd_bsd_rdmap,filename,bsd_header,bsd_rdmap
;
; get the channel numbers
;
nchanstr= ' ';
print, ''
ier = 1;
while (ier ne 0) do begin
print, 'Enter the channels 1,2,3,4 or * for all'
read, nchanstr
range,nchanstr,4,channels,ier,1
endwhile
;
; get dset numbers 
;
ndset_str = ' ';
ier =1
while (ier ne 0) do begin
print, ''
print, 'Enter data sets to extract (comma delimited list, 3-5, or * for all)'
print, '   If you enter *, all data sets will be extracted
print, '   If you enter -99, use data sets specified in variable ss
print, '   If you enter -888, no reading
read, ndset_str
if (ndset_str eq '-99') then begin
	dset_arr=ss
	ier = 0;
	endif else begin
	if (ndset_str eq '-888') then begin
		ier = 0;
		stop 
		endif else begin
		range,ndset_str,maxdat,dset_arr,ier,1
		endelse
	endelse 
endwhile
;
;  read data
;
rd_bsd_data, filename, dset_arr, bsd_header, bsd_rdmap, bsd_index, bsd_data, $
	channels
;
; return to idl
;
end
