;+
; NAME:
;	dat2bsc
; PURPOSE:
;	convert wave and flux arrays to BSC format
; CALLING SEQUENCE:
;	dat2bsc,wave,flux,bsc_index,bsc_data,chan=chan
; INPUTS:
;	wave = wavelength (Ang) 
;       flux = flux (photons cm-2 s-1 A-1 in second column)
; OUTPUTS:
;       fake bsc_index and bsc_data arrays 
; KEYWORDS:
;       chan = BCS channel 
; OPTIONAL KEYWORDS:
;       counts = count data corresponding to flux
;       error  = error data corresponding to errors inc counts
;       time = ASCII string time in UTPLOT format (e.g. 6-SEP-92  09:04:57.771)
;       accum = accumulation time of spectrum
; EXAMPLE:
;       dat2bsc,wave,flux,chan=3,bsc_index,bsc_data  
; MODIFICATION HISTORY:
;       31 Jan 1994, written DMZ (ARC)
;       19 Apr 1994, fixed bug in CHAN (DMZ)
;       10 May 1994, added 2-d wave,flux capability
;       20 Jul 1994, added unit errors, and counts/error keywords
;                    made CHAN a keyword
;-

        pro dat2bsc,wave,flux,chan=chan,bsc_index,bsc_data,time=time,accum=accum,$
                    counts=counts,error=error

        on_error,1

;-- check inputs

        szw=size(wave) & szf=size(flux)
        bad=(szw(0) ne szf(0)) or $
            (szw(1) ne szf(1)) or $
            (szw(2) ne szf(2)) or $
            (szw(0) lt 1) or (szw(0) gt 2) or $
            (szf(0) lt 1) or (szf(0) gt 2)
         if (bad) then $
          message,'USAGE --> DAT2BSC,WAVE,FLUX,CHAN=CHAN,BSC_INDEX,BSC_DATA'

        if n_elements(chan) ne 1 then begin
          repeat begin
          ichan='' & read,'enter BCS channel number: ',ichan
          ichan=fix(ichan)
         endrep until (ichan gt 0)
        endif else ichan=chan

;-- fake output structures

        wf=reform(wave)
        ff=reform(flux)
        dtype=55          ;-- .wave, .flux, .counts, .bin,  and .error fields
        if (size(wf))(0) eq 1 then ncopy=1 else ncopy=(size(wf))(2)
        nw=(size(wf))(1)
        if not keyword_set(error) then ee=replicate(1.,nw) else ee=error
        if not keyword_set(counts) then cc=replicate(1.,nw) else cc=counts
        bb=findgen(nw)+1

        bsc_index=mk_bsc_str(dtype,nw,/sample,ncopy=ncopy)

        if n_elements(time) ne 0 then begin        ;-- use internal times
         itime=anytim2ints(time)
         bsc_index.gen.time=itime.time
         bsc_index.gen.day=itime.day
        endif

        bsc_index.bsc.st$spacecraft=byte('SYN')
        bsc_index.bsc.chan=ichan
        if n_elements(accum) eq 0 then accum=3000
        bsc_index.bsc.actim=accum
        bsc_index.bsc.total_cnts=100000.           ;-- a big number

        bsc_index.bsc.valid_ans=1             ;-- fake processing options
        bsc_index.bsc.physunits_ans=2
        bsc_index.bsc.wavedisp_ans=2
        bsc_index.bsc.curve_ans=2
        bsc_index.bsc.deadtime_ans=1
        bsc_index.bsc.datarectypes=dtype
        bsc_index.bsc.nstart=0
        bsc_index.bsc.nend=nw-1
        bsc_index.bsc.length=nw
        bsc_index.bsc.nbin=nw
        bsc_data=mk_bsc_str(dtype,nw,ncopy=ncopy)
        bsc_data.counts=cc
        bsc_data.bin=bb
        bsc_data.flux=ff
        bsc_data.error=ee
        wmean=(wf+shift(wf,1))/2.
        wmean=wmean(1:*,*)
        wstart=2.*wf(0,*)-wmean(0,*)
        bsc_data.wave=[wstart,wmean]             ;-- wavelength start values

	return
	end

