pro lcbsd,filename,data,channel=channel,spectra=spectra,psym=psym,stack=stack, $
        quiet=quiet,plot_page=plot_page,landscape=landscape,charsize=charsize
;+
; NAME:				lcbsd.pro
;
; PURPOSE:			plots the count rate in a bsd file, 
;				as a function of time.
;
; CALLING SEQUENCE:		LCBSD[,bsdfilename][,channel='1,2,3',psym=4 $ 
;				  spectra='1,2,3-4,*',/landscape,chars=1.6,/stack]  
;				or
;
;				LCBSD,bsd_index,bsd_data[,...etc...]
;
; INPUTS:			bsd filename - filename and path of a bsd file
;				 if null then prompted for a wildcard search.
;
;				or
;
;				  bsd_index and data structures
;
; keywords:			channel - string, '1,2,3,4' or '1-3' etc 
;				spectra - string, '1,2-40' (see Range.pro) 
;				plot_page - plot all channels on one page
;				quiet - eliminate extra info
;				psym  - the plotsymbol
;				stack - stack plots vertically (lcbda)
;				landscape - if plot device is ps then
;					use landscape orientation
;
;
; OUTPUTS:			plots to graphics devices
;
; OPTIONAL OUTPUTS:		none
;
; RESTRICTIONS:			use pprint.pro or site dependent equivalent 
;				to printout postscript files.
;
; PROCEDURE:			read file, extr index section, plot light curve
;
; MODIFICATION HISTORY:
;		author:        Andy Phillips , mssl 1991
;		atp 14.7.92 atp v1.2 - new structures, use of utplot etc...
;
;-
; no need for this in doc_library
; history:
;		Written 4/9/91 - atp V. 0.3
; 		modified 4/9/91 - atp , af v.5
;		modified 17/9/91 - atp v.7
;		modified 14/3/92 - atp v.9
;		atp 14.7.92 atp v1.2 - new structures, use of utplot etc...
;		keywords, bsd_index and data structures input
; 
; Notes:	use pprint.pro or site dependent equivalent to printout
;		postscript files.
;
;
version = 'v 1.6'
ion = ['FeXXVI','FeXXV ','CaXIX ','SXV   ']
;
; print program header                                               
;                                                                    
if (not keyword_set(quiet)) then verbose=1 else verbose=0

if (verbose) then print,'LCBSD - Light Curves Version:',version,' 1991 '
;
; get data
;
if (n_tags(filename) eq 0) then begin ;/*is a file name */
if (not keyword_set(filename)) then $
        bcs_getfile,filename,defstr="bsd*.*" $
    else if filename eq '' then bcs_getfile,filename,defstr="bsd*.*" 

if (filename eq '-1') then return

;
; strip out identifier 
;              
break_file,filename,dsk_log,dir,bsdnam,ext,filver
;
; extract identifier.
;
ident = bsdnam
if strpos(bsdnam,'bsd') eq 0 then $
   ident = strtrim(strmid(bsdnam,3,strlen(bsdnam)),2)
;
;                                                                               
; read header info + roadmap                                                             
;                                                                               
rd_bsd_header,filename,bsd_header
rd_bsd_rdmap,filename,bsd_header,bsd_road
 got_data=0
endif else begin 
 ;/* is a structure */
 ; sanity check
 if ( (size(bsd_index))(1) le 1) then begin
	print,'lcbsd: traditionally light curves consist of more than one point....'
	stop
	endif
 ident=''
 verbose=0
 bsd_index=filename
 bsd_data = data
 got_data=1
 endelse 
;
; Set up plotting conventions, vector font, landscape + plotfilename
;
!p.font=-1  				; vector font
;
if (verbose) then begin
print,'Current Graphics Device ',!d.name
print,'File ',bsdnam+ext
print,'number of spectra/channel ',bsd_header.numchn
print,' '
endif
set_plot,!d.name
if (!d.name eq 'X') then window,7,xs=600,ys=700 
if (!d.name eq 'PS') then begin 
	if (keyword_set(landscape)) then device,/landscape else begin
	 device,/portrait
	 ps_reset
	 ps_long 
	 endelse
        endif

chars=!p.charsize
if (keyword_set(charsize)) then !p.charsize = charsize else !p.charsize=1.4
;
; get spectra,channels range
;

if (not keyword_set(channel)) then channel = '*'
if (not got_data) then begin
if (not keyword_set(spectra)) then spectra = '*' 

range,spectra,max(bsd_header.numchn),dset_arr,ier,1
if (ier ne 0) then begin
  print,' spectra range error '
  print,'error in bsd file header.numchn = ',header.numchn
  stop
  endif
endif


range,channel,4,chans,ier,1
if (ier ne 0) then begin
  print,' channel range error '
  stop
  endif
nchan = n_elements(chans)

if (not got_data) then begin


rd_bsd_data,filename,dset_arr,bsd_header,bsd_road,bsd_index,dummy,chans,/nodata
endif
;
; display data. ask if multi plot.
;
if (nchan gt 1) then begin
 if (not keyword_set(plot_page)) then begin
  print,' '
  print,' Display All channels on same page ?'
  print,' Press y for yes, any other key for individual plots.'
  if (!d.name eq 'PS') then begin
   print,' If using postscript hardcopy, print using the command;'
   print,'  pprint or site dependent equivalent'
  endif

 if (get_kbrd(1) eq 'y') then begin
	multi = 1
	endif else begin
	!p.multi = 0
	multi = 0
	endelse
 endif else multi=1 ;/*plotpage*/

endif else multi=0

if (verbose) then print,'    plotting.......'

;
; Loop through all the channels plotting the light curve
;
if (multi eq 1) then begin
 savemulti = !p.multi
 if (nchan eq 2) then !p.multi = [0,0,2,0,0]
 if (nchan eq 3) then !p.multi = [0,0,3,0,0]
 if (nchan eq 4) then $ 
  if (keyword_set(stack)) then !p.multi = [0,0,4,0,0] else $ 
		!p.multi = [0,2,2,0,0] 
endif


for fred = 0,nchan-1 do begin
chan = chans(fred)
;
; Branch at multi plotting 
;
 if (multi eq 1) then begin
  if (chan eq 1) then    $
   kptitle = 'Yohkoh/BCS Light Curve - Chan '+string(format='(i2)',chan)+' '+ion(chan-1) 

  if (chan ge 2) then     $
   kptitle = 'Chan '+string(format='(i2)',chan)+' '+ion(chan-1)

  endif else begin
  
  kptitle = 'Yohkoh/BCS Light Curve - Chan '+string(format='(i2)',chan)+' '+ion(chan-1)

  endelse
	
 kytitle='Counts/second'

;
   xtime = int2secarr(reform(bsd_index(fred,*).time))
   utplot,xtime,reform(bsd_index(fred,*).crate), $
          reform(bsd_index(fred,0).time),title=kptitle,ytitle=kytitle
;
; oplotting of symbols 
;
   if (keyword_set(psym)) then outplot,xtime,bsd_index(fred,*).crate,psym=psym
;
; Not multi plot, plot, and wait if not hardcopying
;
   if (multi eq 0) then if ((!d.name ne 'PS') and (nchan gt 1)) then dummy = get_kbrd(1);
  endfor; channel loop
;
;  remove effects of the multi statement.
;
if (multi eq 1) then !p.multi = savemulti
;
; finish
;
!p.charsize=chars 
!y.type = 0
ps_reset

end
