pro fpe_grid, delong, dpa, label = label, charsize = charsize, $
              max_elongation = max_elongation, _extra = _extra

;+
; NAME:
;	FPE_GRID
;
;
; PURPOSE:
;	Add a grid of elongation and position-angle to a SMEI Fisheye
;	plot.
;
;
; CATEGORY:
;	utils
;
;
; CALLING SEQUENCE:
;	fpe_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.
;	max_elongation	float	Set the largest elongation to show
;				(default=135)
;	Any key accepted by PLOTS will be passed through.
;
;
; RESTRICTIONS:
;	Steps will be rounded to the nearest whole degree
;
;
; MODIFICATION HISTORY:
;	Original: 13/2/04; SJT
;	Add labelling support: 16/2/04; 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)
if n_elements(max_elongation) eq 0 then max_elongation = 135

for pa = -180, 180, dpa do begin
    x = [0, -max_elongation*sin(pa*!dtor)]
    y = [0, max_elongation*cos(pa*!dtor)]
    plots, x, y, _extra = _extra
endfor

x = -sin(findgen(361)*!dtor)
y = cos(findgen(361)*!dtor)

for el = delong, max_elongation, delong do begin
    plots, el*x, el*y, _extra = _extra
endfor

if keyword_set(label) then begin
    for pa = -180+dpa, 180, dpa do begin
        x =  max_elongation*sin(pa*!dtor)*1.005
        y =  max_elongation*cos(pa*!dtor)*1.005
        xyouts, x, y, string(pa, format = "(I0)"), charsize = $
                charsize, align = pa gt 0
    endfor

    for elong = delong, max_elongation, delong do begin
        xyouts, -elong, 0.5, string(elong, format = "(I0)"), charsize = $
                charsize, align = 0.5
    endfor
endif

end
