;+
; Name: 
;	DATPLOT
;
; CALLING SEQUENCE:
;	datplot,xl,xh,y,xnew,ynew, STAIRS=STAIRS, color=color, xs=xs
;
; PURPOSE:
;	This procedure is used to OVERplot histograms between channel edges.
; CATEGORY:
;	J6 - plotting, graphics, one dimensional.
; INPUTS:
;	xl - Low edges of abscissae
;	xh - High edges of abscissae
;	y  - Ordinates
;	
; Optional Inputs:
;	xs - xl and xhi are packed into xs(0,*) and xs(1,*)
;	if xs is passed, then y is still the third argument,
;	  the first two arguments are not used but required
;	
; Optional Outputs:
;	xnew - If /stairs, then array used for abscissae bins
;	ynew - If /stairs, then ordinate array
;
; KEYWORDS:
;	/stairs - connect all the bins together, looks like stairs
;	/nolegs - leave the ends floating under stairs option
;	color   - plotting color to use, as with linecolors
;	psym  - symbol to plot at center of horizontal bar, def=no effect
;	sysmsize - size of symbol, def=0.1
;	All remaining keywords available to OPLOT		
; RESTRICTION:
;       Initial call to plot must be made to establish scaling
; MODIFICATION HISTORY:
;	91/12/06, FOR VERSION2
;       	18-oct-93, ras, nolegs and color
;	19-may-94, ras, indicate gaps between intervals using stairs
;	Version 4, RAS, 17-Jun-1997, protect case of a single data interval to plot.
;-

pro datplot,xl,xh,y,xnew,ynew, xs=xs, _extra=oplotextra, $
    STAIRS=STAIRS, color=color, nolegs=nolegs, psym=psym, symsize=symsize


if n_elements(xs) ge 2 then begin
    xl = xs(0,*)
    xh  = xs(1,*)
    endif 

nel=n_elements(xl)

;PLOT BARS 
if NOT KEYWORD_SET(STAIRS) $ 
then for i=0,nel-1 do oplot, [xl(i),xh(i)], [y(i),y(i)], psy=0,$
  color=fcolor(color),  _extra=oplotextra $
    else begin
    
    ;OR PLOT STAIRS
    ;find where data bins are not contiguous
    if nel gt 1 then $
	wncont = where( abs(xh - xl(1:*)) ge .01 *abs(xh-xl) , nncont) $
	else nncont = 0
    
    xnew = transpose( reform( [xl(*),xh(*)],nel,2) )
    ynew = transpose( reform( [y(*),y(*)], nel, 2) )
    if not keyword_set(nolegs) then begin
        xnew = [ xnew(0), xnew(*), xnew(nel*2-1) ]
        yrange = crange('y')
        ynew = [ yrange(0), ynew(*), yrange(0) ]
        endif
    oplot,xnew,ynew,PSYM=0,color=fcolor(color),  _extra=oplotextra
    if nncont gt 0 then $ ;overplot blanks during gaps
    for i=0, nncont-1 do $
    oplot, [xh(wncont(i)),xl(wncont(i)+1)], [y(wncont(i)),y(wncont(i)+1)], $
    psym=0, color = fcolor(0), _extra=oplotextra
    
    
    endelse
checkvar, psym, 0
checkvar, symsize,0.1
if psym ne 0 then begin
	if !x.type eq 1 then xm = sqrt(xl*xh) else xm=(xl+xh)/2
	oplot, xm, y, psym=psym, symsize=symsize, color = fcolor(color)
endif

end

