pro im_contour, a, absc, ordin, WINDOW_SCALE = window_scale, ASPECT = aspect, $
	INTERP = interp, nlevels = nlevels, levels=levels, 	$
	xticklen = xticklen, yticklen = yticklen, title = title, $
	xtitle = xtitle, ytitle = ytitle, font = font, follow=follow, $
	color=color,background=background
;+
; NAME:
;	IMAGE_CONT
;
; PURPOSE:
;	Overlay an image and a contour plot.
;
; CATEGORY:
;	General graphics.
;
; CALLING SEQUENCE:
;	IMAGE_CONT, A
;
; INPUTS:
;	A:	The two-dimensional array to display.
;
; KEYWORD PARAMETERS:
; WINDOW_SCALE:	Set this keyword to scale the window size to the image size.
;		Otherwise, the image size is scaled to the window size.
;		This keyword is ignored when outputting to devices with
;		scalable pixels (e.g., PostScript).
;
;	ASPECT:	Set this keyword to retain the image's aspect ratio.
;		Square pixels are assumed.  If WINDOW_SCALE is set, the
;		aspect ratio is automatically retained.
;
;	INTERP:	If this keyword is set, bilinear interpolation is used if
;		the image is resized.
;
; OUTPUTS:
;	No explicit outputs.
;
; COMMON BLOCKS:
;	None.
;
; SIDE EFFECTS:
;	The currently selected display is affected.
;
; RESTRICTIONS:
;	None.
;
; PROCEDURE:
;	If the device has scalable pixels, then the image is written over
;	the plot window.
;
; MODIFICATION HISTORY:
;	DMS, May, 1988.
;	ISTP, Oct, 1995. A number of keywords is added. Corrected the mistake
;	of (N-1) seen on small arrays.
;-

on_error,2                      ;Return to caller if an error occurs
sz = size(a)			;Size of image
if sz(0) lt 2 then message, 'Parameter not 2D'

if n_elements(nlevels) le 0 then nlevels=6
if n_elements(xticklen) le 0 then xticklen=0.02
if n_elements(yticklen) le 0 then yticklen=0.02
if n_elements(absc) le 0 then absc=findgen(sz(1))
if n_elements(ordin) le 0 then ordin=findgen(sz(2))
if n_elements(title) le 0 then title=' '
if n_elements(xtitle) le 0 then xtitle=' '
if n_elements(ytitle) le 0 then ytitle=' '
if n_elements(font) le 0 then font=-1
if n_elements(color) le 0 then color=!p.color
if n_elements(background) le 0 then background=!P.background


	;set window used by contour
contour,[[0,0],[1,1]],/nodata, xstyle=4, ystyle = 4
erase,background

px = !x.window * !d.x_vsize	;Get size of window in device units
py = !y.window * !d.y_vsize
swx = px(1)-px(0)		;Size in x in device units
swy = py(1)-py(0)		;Size in Y
six = float(sz(1))		;Image sizes
siy = float(sz(2))
aspi = six / siy		;Image aspect ratio
aspw = swx / swy		;Window aspect ratio
f = aspi / aspw			;Ratio of aspect ratios

if (!d.flags and 1) ne 0 then begin	;Scalable pixels?
  if keyword_set(aspect) then begin	;Retain aspect ratio?
				;Adjust window size
	if f ge 1.0 then swy = swy / f else swx = swx * f
	endif

  tvscl,a,px(0),py(0),xsize = swx, ysize = swy, /device

endif else begin	;Not scalable pixels
   if keyword_set(window_scale) then begin ;Scale window to image?
	tvscl,a,px(0),py(0)	;Output image
	swx = six		;Set window size from image
	swy = siy
    endif else begin		;Scale window
	if keyword_set(aspect) then begin
		if f ge 1.0 then swy = swy / f else swx = swx * f
		endif		;aspect

if keyword_set(interp) then $

	tvscl,poly_2d(bytscl(a),$	;Have to resample image
		[[0,0],[(six-1)/swx,0]], [[0,(siy-1)/swy],[0,0]],$
		keyword_set(interp),swx,swy), $
		px(0),py(0) else $

	tvscl,poly_2d(bytscl(a),$	;Have to resample image
		[[0,0],[six/swx,0]], [[0,siy/swy],[0,0]],$
		keyword_set(interp),swx,swy), $
		px(0),py(0)

	endelse			;window_scale
  endelse			;scalable pixels

mx = !d.n_colors-1		;Brightest color
colors = [mx,mx,mx,0,0,0]	;color vectors
if !d.name eq 'PS' then colors = mx - colors ;invert line colors for pstscrp

	if n_elements(levels) le 0 then $

contour,a, absc, ordin, /noerase,/xst,/yst,$	;Do the contour
	   pos = [px(0),py(0), px(0)+swx,py(0)+swy],/dev,$
	c_color =  colors, nlevels = nlevels, $
	xticklen = xticklen, yticklen = yticklen, follow=follow, $
	title = title, xtitle = xtitle, ytitle = ytitle, font = font, $
	color=color,background=background else $

contour,a, absc, ordin, /noerase,/xst,/yst,$	;Do the contour
	   pos = [px(0),py(0), px(0)+swx,py(0)+swy],/dev, $
	c_color =  colors, nlevels = nlevels, levels=levels, $
	xticklen = xticklen, yticklen = yticklen,  follow=follow, $
	title = title, xtitle = xtitle, ytitle = ytitle, font = font, $
	color=color,background=background


return
end
