;+
;
; NAME: 
;       FS_OVERLAY
;
; PURPOSE:
;
;
; CATEGORY:
;       BATSE
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	none
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	none
;
; MODIFICATION HISTORY:
;
;-
pro fs_overlay, scale = scale, error = error
; 
; Generate plot of BATSE data using the operator selected channels, detectors,
; and sample average over the operator selected time range.
;
; Mod 6/28/95 by AES - use lowercase filename
;*******************************************************************************
;
@fscom
@fs_saveplot
;
error = 0
;
; Open plot output file for updating
;
;
;if the device is x windows, loop through the graphics twice to produce
;the plot file
set_graphics, screen= sc_device, printer= hard_device
ifirst = 1 & ilast =2 
if noplotfile then begin
   ifirst = 2 
endif else begin
   if (sc_device eq 'TEK') and (hard_device eq 'TEK') then ilast = 1
endelse
;
colors = [9,12,7,3,10,2]
color = colors ( ((where(last_color eq colors))(0) + 1) mod 6)
last_color = color

for iloop= ifirst,ilast do begin ;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
;
;       First pass is hardcopy file
;	if iloop eq 1 then tek_init, file='FSPLOT', /update
	if iloop eq 1 then tek_init, file='fsplot', /update
        if (iloop eq 2) and (sc_device eq 'TEK') then device,gin_chars=6
        !p = save_bangp(iloop-1)
        !x = save_bangx(iloop-1)
        !y = save_bangy(iloop-1)

	if !d.name ne 'NULL' then linecolors
;
;       Make time array relative to start of day rather than start of data.
;       Base time has already been set to start of day.
	utb = getutbase(0)
	sec_rel = sec_arr - utb ; sec_rel is time array relative to start of day.
;
	plottype = 0  ; value for !psym to connect points with lines
	if histogram then plottype = 10  ; user has selected histogram style plot
	if yaxis then oplot,sec_rel,out_arr*scale,psym=plottype,color=color  else $
	  oplot,sec_rel,out_arr+scale,psym=plottype,color=color
;
;       Close the TEK file. This also sets the output device back to the
;       screen device.
        save_bangp(iloop-1) = !p
        save_bangx(iloop-1) = !x
        save_bangy(iloop-1) = !y
        if iloop eq 1 then TEK_END
ENDFOR ;close iloop ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


goto,getout
;
errorexit:
error = 1                                            
goto,getout
;
getout:
return&end

