pro plot_all, xvec,data, $
 	oplot  = oplot , $		; user established scaling	
	normal = normal, $		; normalize if true
	labels = labels, $		; label plot if supplied
	log    = log,    $		; y axis log if set
	pad    = pad,    $		; buffer plot window
	title  = title,  $		; main plot title
        style  = style,  $		; 2 elements=x/ystyle
	which  = which   		; only data(which) plotted	
;+
; NAME: PLOT_ALL
;
; PURPOSE: plot and overplot 2D array
;
; INPUT:
;	
; CALLING SEQUENCE:  plot_all, [xvec,] data
; KEYWORD PARAMETERS:
;	Normal - switch, true to normalize all plots
;	Labels - string array for line labels
;	Log    - switch for Log Y axis
;	Pad    - y padding as percentage of yrange
;	Title  - main plot title (ignored if OPLOT set)
;	Which  - integer vector of n elements for desired vectors
;		 0:no plot, 1:plot
;
; SIDE EFFECTS: plot to currently selected graphics device
;
;

; HISTORY:
;		Written by S.L.Freeland, 5/21/91
;-
;
;
xvectemp=xvec					;dont corrupt return
if n_params() eq 1 then begin			;plot against index
   datatemp = xvectemp
   xvectemp = indgen(n_elements(datatemp(0,*)))
endif else datatemp = data 
;
type = size(datatemp)
n_vectors = type(1)				; #input vectors
;
if not keyword_set(which) then which = $
	make_array (n_vectors,/int) + 1		; enable all plots
;
if not keyword_set(style) then style=intarr(2)
n_plots = total(which)
;
if not keyword_set(pad) then pad = 0		;default is no margin
;
if not keyword_set(title) then title = ''	; default no title
;
plot_types=['plot','plot_io']			;plot type -> string
select = keyword_set(log)			;selection
plot_type = plot_types(select)
;
line_types = 5					;number of styles   
;
min = min(datatemp(where(which)>0,*))		;auto scale for
max = max(datatemp(where(which)>0,*))		;selected vectors
;
pad = (max-min)*.01*pad				;y pad = range*pad%
min = min - pad					;adjust plot margin
max = max + pad
;
minimum = [min,1e-10]				;log range protect
min = max([min,minimum(select)])
;
; if user has not done so, draw box with appropriate scaling
;
if not keyword_set(oplot) then $
   call_procedure,plot_type, xvectemp, datatemp(0,*), /nodata, $
	yrange=[min,max],xstyle=style(0), ystyle=style(1),title=title
;
; for each input vector, plot it if which switch enabled
;
for i=0,n_vectors-1 do begin
   if (which(i))   then $		
      oplot,xvectemp, datatemp(i,*), linestyle = i mod line_types, $
	 thick = i/line_types+1
endfor
return
end
