! GO PLOTFLUX plots the integrated flux as a function of velocity in
! the polygon 'name'.pol
! the data is 'name'.'type'
! the channels are 'first' to 'last'
!
on error return
if exist(h) then
    del /var h
end if
define header h 'name'.'type' read /global
@ p_header.greg h
!
!Que vaut "text" ici  ????
if .not.file(text) then
	polygon
	write pol 'name'.pol
endif
greg2\polygon 'name'.pol
gtvl\destroy all
say "Using polygon "'name'".pol"
!
def integer i1 i2 n
let n h%dim[3]
def real beam_area v[n] flux[n]
let beam_area pi*h%major*h%minor/4/log(2)
let i1 first
let i2 last
if i1.eq.0 then
  let i1 1
endif
if i2.eq.0 then
  let i2 h%dim[3]
endif
let flux h%blank[1]
let v h%blank[1]
sic out 'name'.flux
for i i1 to i2
  greg3\image 'name'.'type' /plane i
  greg2\mean
  let v[i] h%convert[2,3]+(i-h%convert[1,3])*h%convert[3,3]
  let flux[i] poly%sum/beam_area
  say 'v[i]' 'flux[i]'
next
sic out
greg1\limits /var v flux
greg1\set mar 4 0 .1
greg1\histogram v flux
greg1\points v flux
greg1\box
greg1\label "Velocity (km/s)" /x
greg1\label "Integrated Flux (Jy)" /y
let air 0.1*nint(10.*poly%area/sec^2) /new double
greg1\draw text 0 -.3 "Flux in \\i"'name'".pol\\i ("'air'" `\u2)" 2 /box 8
!
