pro grid,nx,ny,xx,yy,color=color,xoffset=xoffset,yoffset=yoffset, $
	narrow=narrow

;+
;  NAME
;	grid
;  PURPOSE
;	Draw a grid on a window.
;  CALLING SEQUENCE
;	grid,nx,ny,x,y,color=color,xoffset=xoffset,yoffset=yoffset
;	grid,2,3,256,128,yoffset=128
;  INPUT PARAMETERS
;	nx	: number of boxes in x direction
;	ny	: number of boxes in y direction
;	xx	: x dimension of a single box
;  OPTIONAL INPUTS
;	yy	: y dimension of a single box 
;		   (Optional, default is y=x.)
;  OPTIONAL KEYWORD INPUTS
;	color = color to draw the grid (default color = 255)
;	xoffset, yoffset = offsets in x & y to apply to each grid element.
;	narrow - draw single-pixel-width lines (default is 2 pixels)
;  HISTORY
;	2/14/92, lwa
;	4/04/94, lwa  (added y parameter and header)
;	8/04/94, lwa  (replaced tvplot with plots and
;		added soffset & yoffset keywords)
;	12/03/94, lwa (added narrow keyword)
;-

if NOT keyword_set(color) then color=255 else color=color
if n_elements(yy) eq 0 then yy=xx

if NOT keyword_set(xoffset) then xoffset=0 else xoffset=xoffset
if NOT keyword_set(yoffset) then yoffset=0 else yoffset=yoffset

x2 = nx*xx-1
y2 = ny*yy-1

;	Draw the horizontal lines.

for i=0,ny do begin
     y = yy*i
     if i eq ny then begin
          y = y-2
	  if keyword_set(narrow) then y = y+1
     endif
     plots,/device,[0,x2]+xoffset,[y,y]+yoffset,color=color
     if NOT keyword_set(narrow) then begin
        plots,/device,[0,x2]+xoffset,[y+1,y+1]+yoffset,color=color
     endif
endfor

;	Draw the vertical lines.

for i=0,nx do begin
     x = xx*i
     if i eq nx then begin
          x = x-2
	  if keyword_set(narrow) then x = x+1
     endif
     plots,/device,[x,x]+xoffset,[0,y2]+yoffset,color=color
     if NOT keyword_set(narrow) then begin
        plots,/device,[x+1,x+1]+xoffset,[0,y2]+yoffset,color=color
     endif
endfor

end


