PRO  	BSC_RASTER,BSC_INDEX,BSC_DATA,CHAN=CHAN,INTENSITY=INTENSITY,NX=NX,NY=NY,$
                   HC=HC,NOPRINT=NOPRINT,SS=SS,PLOT_ACROSS=PLOT_ACROSS
;+
;  NAME:  BSC_RASTER.PRO
;  
;  PURPOSE:
;	Plots bsc (i.e., processed) spectra in a raster form, a-la sxt's xy_raster.
;	Default is flux units (photons cm^-2 s^-1 A^-1).
;
;  CALLING SEQUENCE:
;      IDL> bsc_raster,bsc_index,bsc_data,chan=chan,intensity=intensity,nx=nx,ny=ny,$
;		       hc=hc,noprint=noprint,ss=ss,plot_dir=plot_dir
;                   
;  NOTES:
;	Requires pre-processed bsc data.
;
;  INPUTS:
;	bsc_index	Index array from mk_bsc
;	bsc_data	Data array from mk_bsc
;
;  OPTIONAL INPUTS:
;
;  OPTIONAL INPUT KEYWORDS:
;       chan		Channel of the data to be plotted.  Default is CaXIX (Chan=3)
;	intensity	If set, plots spectra in counts/s/bin instead of flux units.
;	nx		Number of plots in x-direction.  Default = 3.
;	ny		Number of plots in y-direction.  Default = 4.
;	hc              for hardcopy -- auto prints unless /noprint is used too.
;	noprint		if used with /hc, will create idl.ps file, but not print it.
;	ss		array of subset of spectral elements to be plotted.
;	plot_across	if set, plot spectra from left to right instead of top to bottom first
;
;  OUTPUTS:
;
;  HISTORY:
;        Written        20-Oct-1995, A. Sterling
;
;-
;               -------------- Error Handling Cards  ------------------

on_error,1              ; Return to main routine

if n_params() lt 2 then begin
    message,'Calling sequence ==> BSC_RASTER,BSC_INDEX,BSC_DATA,CHAN=CHAN,INTENSITY=INTENSITY,$',/contin
    print,     '                    NX=NX,NY=NY,HC=HC,NOPRINT=NOPRINT,SS=SS,PLOT_ACROSS=PLOT_ACROSS'
    return
endif
if n_elements(chan) eq 0 then chan=3

;               -------------- Extract Relavent Spectral Data  ------------------
if keyword_set(ss) then begin
  index=bsc_index(ss)
  data =bsc_data(ss)
  endif else begin
     index=bsc_index
     data =bsc_data
     endelse

sel_bsc,index,data,tindex,tdata,wave,flux,eflux,chan=chan,$
  		counts=counts,error=error,ss=ss_sel
xx=wave
;               -------------- Setup Cards  ------------------
if keyword_set(intensity) then begin
  spec=fltarr(n_elements(tdata(0).counts(*)),n_elements(tdata(*).counts(0)))
  accum = tindex.bsc.actim/1000.
  for ii=0,n_elements(accum)-1 do begin
     spec(*,ii) = tdata(ii).counts(*)/accum(ii) 
     endfor
  spec_type='Count/S/Bin'
  endif else begin
     spec=flux & spec_type='Flux'
     endelse

num_x=3 & if keyword_set(nx) then num_x=nx
num_y=4 & if keyword_set(ny) then num_y=ny
    

;               	-------------- Do the Plots  ------------------

!x.margin=[9,2]  & !y.margin=[2,1] 
!y.omargin=[2,1] & !x.omargin=[2,1]
if keyword_set(hc) or keyword_set(noprint) then begin
  set_plot,'ps'
  device,color=0,/landscape,xsize=7.5,ysize=5.,/inch, $
	xoff=(8.-5.)/2.,yoff=11.-(11.-7.5)/2.
  ffont=0
  qplot=1
  endif else begin
    ffont=-1
    qplot=0
    endelse

plot_dir=1		;set default plot direction from top to bottom
if keyword_set(plot_across) then plot_dir=0
!p.multi=[0,fix(num_x),fix(num_y),0,plot_dir]
n_ele = n_elements(spec(0,*))
for i_ele=0,n_ele-1 do begin
     plot,xx(*,0),spec(*,i_ele),psym=10,charsize=1.5,font=ffont
     
     ;annotate each spectrum with time:
     xyouts,/data,0.98*(!x.crange(1)-!x.crange(0))+!x.crange(0), $
           0.8*(!y.crange(1)-!y.crange(0))+!y.crange(0), $
	   strmid(fmt_tim(tindex(i_ele)),11,8),charsize=1.0,font=ffont,align=1

     ;print out ss values and times:
     if keyword_set(ss) then begin
        ss_val=strtrim(ss(i_ele),2)
        endif else begin
           ss_val=strtrim(ss_sel(i_ele),2)
           endelse
     print,'ss value = '+ss_val+'    '+fmt_tim(tindex(i_ele))


     ;annotate all (except for last maybe) page of plots:
     if (((i_ele mod (num_x*num_y)) eq num_x*num_y-1) and (i_ele ne n_ele-1)) then begin
        xyouts,0.,0.,'Plot made: '+fmt_tim(!stime),charsize=0.90,/normal,font=ffont
        xyouts,0.5,0.98,strmid(fmt_tim(tindex(i_ele)),0,9)+	$
           ' '+gt_bsc_chan(tindex,/string,/uniq),		$
	   /normal,charsize=1.5,font=ffont,align=.5
        xyouts,0.5,0.005,spec_type+' vs. Wavelength (A)',	$
		/normal,charsize=1.5,font=ffont,align=.5
     endif

     ;--cycle pages if not doing plot:
     if !d.name ne 'PS' then begin
         if (((i_ele mod (num_x*num_y)) eq num_x*num_y-1) and (i_ele ne n_ele-1)) then begin
           ans = ''
           read, 'Hit <CR> to continue to the next page (q to quit)', ans
           if (strupcase(ans) eq 'Q') then return
           erase
           end
     endif
endfor						

;annotate last page of plots
xyouts,0.,0.,'Plot made: '+fmt_tim(!stime),charsize=0.90,/normal,font=ffont
xyouts,0.5,0.98,strmid(fmt_tim(tindex(0)),0,9)+	$
    ' '+gt_bsc_chan(tindex,/string,/uniq),		$
    /normal,charsize=1.5,font=ffont,align=.5
xyouts,0.5,0.005,spec_type+' vs. Wavelength (A)',	$
    /normal,charsize=1.5,font=ffont,align=.5



if qplot then begin
  pprint,noprint=noprint
  set_plot,'x'
endif

;               	-------------- Clean Up and Get Out  ------------------
clearplot

return
end
