! Plot Cuts through UV plane...
! Input
!	NAME	name of UV data set, assume "uvcuts" extension
!	FIRST and LAST channels
destroy all
pen /def
set box sq
sic\define image t 'name'.uvcuts read
define real x1 dx y1
define inte nx na nc n1 n2 n nmap k jc imark
define character cmark*12
define double xmark
set blank 0 0.001
let nx t%dim[1]
let na t%dim[2]
let nc t%dim[3]
if do_header then
  sic\@ p_header.greg t      ! Draw header
endif
def real x[nx] a[na] y[nx] z[nx]
let x[i] t%convert[2,1]+(i-t%convert[1,1])*t%convert[3,1]
let a[i] t%convert[2,2]+(i-t%convert[1,2])*t%convert[3,2]
let y t[1,1,1]
lim 0 * 0 * /var x y
let x1 box_xmin
let y1 box_ymin
if first.eq.0 then
  let n1 1
else
  let n1 first
endif
if last.eq.0 then
  let n2 nc
else
  let n2 last
endif
if first.gt.last then
  let last first
  let n2 n1
endif
let nmap n2-n1+1
let n int(sqrt(nmap+1))
if (n**2.lt.nmap) then
  let n = n+1
endif
set expand min(3./n,1.)
let dx (box_xmax-x1)/n
let dx min((box_ymax-y1)/n,dx)
!
!
! first pass to get limits
let y t[1,1,1]
if (box_limits.eq." ") then
  symbol alimits "0 * 0 *"
else
  symbol alimits 'box_limits'
endif
limits 'alimits' /var x y
for ic n1 to n2
  for j 1 to na
    let y t[j,ic,1]
    lim 0 > 0 > /var x y
  next
next
!
! SECOND PASS TO PLOT
let k n1-1
for j 1 to n
  for i 1 to n
    set box x1+(i-1)*dx x1+i*dx y1+(n-j)*dx y1+(n+1-j)*dx
    let k k+1
    if ((k.gt.nc).or.(k.gt.n2)) then
      set expand 1.0
      return
    else
      let xmark g_veloff+(k-g_convert[1,2])*g_velres
      if (mark.eq."FREQUENCY") then
        let imark nint((-(xmark-g_veloff)*g_restfre/299792.458+g_restfre)*1e3)
        let xmark 1d-6*imark
      else if (mark.eq."CHANNEL") then
        let xmark k
      else
        let mark "VELOCITY"
        let imark nint(xmark*10.)
        let xmark 1d-1*imark
      endif
      pen 0
      let jc k
      if i.eq.1.and.(k+n.gt.n2) then
        box
        label "UV radius (m)" /x
        label "Amplitude (Jy)" /y
      else
        box n n
      endif
      set coord box
      let cmark 'xmark'
      dra text 0.1 -0.1 'cmark' 3 /box 7
      for icut 1 to na
        pen icut
        set mark icut+2 0 .4
        let y t[icut,jc,1]
                                !      conn x y
        let x x+0.005*user_xmax*(icut-1)
        poin x y
        let z 1e-3/sqrt(t[icut,jc,3]+1e-34)
        err y x y z
        let x x-0.005*user_xmax*(icut-1)
        draw mar -0.5 -icut /box 9
        draw text -1 -icut '0.1*nint(a[icut]*1800/pi)' 4 /box 9
      next
    endif
  next
next

