pro rpe_grid, delong, dpa, label = label, charsize = charsize, $
              _extra = _extra

;+
; NAME:
;	RPE_GRID
;
;
; PURPOSE:
;	Add a grid of elongation and position-angle to a SMEI
;	rectangular plot.
;
;
; CATEGORY:
;	utils
;
;
; CALLING SEQUENCE:
;	rpe_grid[, delong, dpa]
;
;
; OPTIONAL INPUTS:
;	delong	int	The step in elongation angle.
;	dpa	int	The step in position angle.
;
;
; KEYWORD PARAMETERS:
;	/label			If set, then label the grid.
;	charsize	Float	Set a size for the labels (ignored if
;				label is not set.)
;	Any key accepted by PLOTS will be passed through.
;
;
; RESTRICTIONS:
;	Steps will be rounded to the nearest whole degree
;
;
; MODIFICATION HISTORY:
;	Original (after fpe_grid): 9/7/08; SJT
;-

if n_params() ne 2 then dpa = 30 else dpa = round(dpa)
if n_params() eq 0 then delong = 30 else delong = round(delong)

y = [0., 180.]
for pa = -180, 180, dpa do begin
    x = replicate(pa, 2)
    plots, x, y, _extra = _extra
endfor

x = [-180., 180.]
for el = 0, 180, delong do begin
    y = replicate(el, 2)
    plots, x, y, _extra = _extra
endfor

if keyword_set(label) then begin
    y = 0.5
    for pa = -180, 180, dpa do begin
        x = pa+0.5
        xyouts, x, y, string(pa, format = "(I0)"), charsize = charsize
    endfor

    x = 0.5
    for elong = 0, 180, delong do begin
        y = elong+0.5
        xyouts, x, y, string(elong, format = "(I0)"), charsize = charsize
    endfor
endif


end
