! @ p_beam &1 [&2]
!
! Plots clean-beam for &1% (AAA or other header variable)
!
! Beam box size is given by &2 (default 0.2)
!
if (&1%major.eq.0) then
  return
endif
define real box[4] user[4] poly[4,2] fraction
if pro%narg.gt.1 then
  fraction = &2
else
  fraction = 0.2
endif
let box[1] box_xmin
let box[2] box_ymin
let box[3] box_xmax
let box[4] box_ymax
greg1\set box box[1] box[1]+fraction*(box[3]-box[1]) box[2] box[2]+fraction*(box[4]-box[2])
!
let user[1] user_xmin
let user[2] user_ymin
let user[3] user_xmax
let user[4] user_ymax
greg1\limits user[1] user[1]+fraction*(user[3]-user[1]) user[2] user[2]+fraction*(user[4]-user[2])
let poly user_xmin user_xmax user_xmax user_xmin user_ymin user_ymin user_ymax user_ymax
!
! Remember current polygon
if (exist(poly%nxy)) then
 define real opol[poly%nxy,2]
 let opol[1] poly%x
 let opol[2] poly%y
else
 define real opol[1,2]
endif
greg2\polygon poly /variable
greg2\polygon /fill 7
greg2\polygon opol /variable
!
define double a b c no s ca sa u1[2] v1[2] u2[2] v2[2] u0 v0
define integer hache
let u0 user[1]+fraction*(user[3]-user[1])/2
let v0 user[2]+fraction*(user[4]-user[2])/2
let hache 3
let a 1+(&1%minor|&1%major)**2
let sa sin(pi|2-&1%pa)
let ca cos(pi|2-&1%pa)
for i -hache to hache
  let b i*&1%major|hache
  let no 0.5*b
  let c no^2-&1%minor^2|4
  let s b*b-4*a*c
  if (s.gt.0) then
    let s sqrt(s)
    let u1[1] (-b+s)|(2*a)
    let u1[2] (-b-s)|(2*a)
    let v1 u1+no
    let u2 (u1*ca-v1*sa)+u0
    let v2 (u1*sa+v1*ca)+v0
    greg1\connect u2 v2
  endif
next
greg2\ellipse 0.5*&1%major 0.5*&1%minor 90-180*&1%pa|pi /box abs(box[3]-box[1])*fraction/2 abs(box[4]-box[2])*fraction/2
!
greg1\box n n n
greg1\set box box[1] box[3] box[2] box[4]
greg1\limits user[1] user[3] user[2] user[4]
!
