!
! @ p_legend X|Y Header%
!
define logical seconds absolute
define integer ii
define real offset
define character action*8 kind*1 label*1 legend*20
!
! Legend and coordinate definitions
if ("&1".eq."X") then
  let ii 1
else if ("&1".eq."Y") then
  let ii 2
else
  return
endif
!
if (&2%unit'ii'.eq."RA") then
   if (abs(&2%angle).gt.1e-5) then
      let legend "\Gdx (`)"
      let kind "s" ! Seconds
   else if (do_rcoord) then
      let legend "\GdR.A.(`)"
      let kind "s" ! Seconds
   else
      let legend "Right Ascension "
      let kind "a" ! Absolute
   endif
else if (&2%unit'ii'.eq."DEC") then
   if (abs(&2%angle).gt.1e-5) then
      let legend "\Gdy  (`)"
      let kind "s" ! Seconds
   else if (do_rcoord) then
      let legend "\GdDec. (`)"
      let kind "s" ! Seconds
   else
      let legend "Declination"
      let kind "a" ! Absolute
   endif
else
   let legend &2%unit'ii' /format a20
   let kind "o" ! Other
endif
  !
if ii.eq.1 then
  if (mod(nx_box,2).eq.0) then
    @ window_xy 'nx_box' 'ny_box' 'nx_box/2' 1
    g\draw text 0 -2 'legend' 5 0 /char 3
  else
    @ window_xy 'nx_box' 'ny_box' '(nx_box+1)/2' 1
    g\draw text 0 -2 'legend' 5 0 /char 2
  endif
else
  !
  if ny_box.gt.2 then
    let offset -2
  else
    let offset -5.5
  endif
  if (mod(ny_box,2).eq.0) then
    @ window_xy 'nx_box' 'ny_box' 1 'ny_box/2'
    g\draw text offset 0 'legend' 5 90 /char 7
  else
    @ window_xy 'nx_box' 'ny_box'  1 '(ny_box+1)/2'
    g\draw text offset 0 'legend' 5 90 /char 4
  endif
endif
