!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin data gag_scratch:flux-reference.dat
! Method    Support ellipse      Flux  Tolerance
! (Name) (Xc Yc Major Minor PA)  [Jy]     [%]
  HOGBOM  0  0   5.0   5.5   0   0.562     5
  CLARK   0  0   5.0   5.5   0   0.552     5
  SDI     0  0   5.0   5.5   0   0.522     5
  MULTI   0  0   5.0   5.5   0   0.549     5
  MRC     0  0   5.0   5.5   0   0.570     5
  MX      0  0   5.0   5.5   0   0.566     5
end data gag_scratch:flux-reference.dat
!
begin procedure check-flux
  !---------------------------------------------------------------------
  ! Check if the flux of the current RG buffer matches the expected flux
  ! as found in the flux-reference table. Arguments:
  !   &1: method name (uppercase)
  !---------------------------------------------------------------------
  !
  if (pro%narg.ne.1) then
    message e check-flux "Missing method name"
    return error
  endif
  !
  ! Load the flux reference table
  define integer nmeth
  compute nmeth lines gag_scratch:flux-reference.dat /blank
  define char*10 mname[nmeth]
  define real xc yc majo mino pa refflux tol /like mname
  accept mname xc yc majo mino pa refflux tol /col gag_scratch:flux-reference.dat
  !
  ! Find the corresponding line in the reference table
  define integer imeth
  let imeth 0
  for iline 1 to nmeth
    if mname[iline].eq.pro%arg[1] then
      let imeth iline
      break
    endif
  next iline
  if imeth.eq.0 then
    message e check-flux "Method "'pro%arg[1]'" not found in reference table"
    return error
  endif
  !
  ! Measure the flux in the reference ellipse support
  go poly "ellipse" 'xc[imeth]' 'xc[imeth]' 'majo[imeth]' 'mino[imeth]' 'pa[imeth]'
  greg2\mean  ! NB: assume RG is the cleaned map for current method
  define real flux
  let flux poly%sum/pi/'drawn'major/'drawn'minor*4*log(2)
  !
  ! Check and feedback
  if abs(flux-refflux[imeth]).gt.refflux[imeth]*tol[imeth]/100 then
    message e check-flux "Unexpected flux for method "'mname[imeth]'":" -
     'flux' "Jy instead of" 'refflux[imeth]' "+-" 'tol[imeth]' "%" -
     /format A F0.3 A F0.3 A F0.1 A
    return base
  else
    message i check-flux "Measured flux (" 'flux' -
     "Jy) matches the expected flux for "'mname[imeth]'" within" -
     'tol[imeth]' "% tolerance" /format A F0.3 A F0.1 A
  endif
  !
end procedure check-flux
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
say "Testing UV_MAP"
read uv gag_demo:demo-single-v22
uv_map
let do_contour yes
show dirty
let niter 500
let fres 0
let ares 2e-3
let scale -0.015 0.060
input clean
!
pause "Type CONTINUE to test HOGBOM"
support gag_demo:demo-single.pol
let name Hogbom
hogbom
pause "Type CONTINUE to see HOGBOM result"
show clean
support gag_demo:demo-single.pol
say " "
stat clean
say " "
@ check-flux "HOGBOM"
say " "
!
pause "Type CONTINUE to test CLARK"
support gag_demo:demo-single.pol
let name Clark
clark
pause "Type CONTINUE to see CLARK result"
show clean
support gag_demo:demo-single.pol
say " "
stat clean
say " "
@ check-flux "CLARK"
say " "
!
pause "Type CONTINUE to test SDI ?"
let nmajor 40
support gag_demo:demo-single.pol
let name SDI
sdi /plot
pause "Type CONTINUE to see SDI result"
show clean
support gag_demo:demo-single.pol
say " "
stat clean
say " "
@ check-flux "SDI"
say " "
!
pause "Type CONTINUE to test MultiScale ?" 
let smooth 1.73
support gag_demo:demo-single.pol
let name Multi
multi /flux 0 1
pause "Type CONTINUE to see MultiScale result"
show clean
support gag_demo:demo-single.pol
say " "
stat clean
say " "
@ check-flux "MULTI"
say " "
!
pause "Type CONTINUE to test MRC ?"
support gag_demo:demo-single.pol
let ares 0
let fres 5e-2
let name MRC
mrc
pause "Type CONTINUE to see MRC result"
show clean
support gag_demo:demo-single.pol
say " "
stat clean
say " "
@ check-flux "MRC"
say " "
!
return
!
! MX is not working for the new multi-beam default case.
pause "Type CONTINUE to test MX ?"
support gag_demo:demo-single.pol
mx /flux 0 1
pause "Type CONTINUE to see MX result"
let name MX
show clean
support gag_demo:demo-single.pol
say " "
stat clean
say " "
@ check-flux "MX"
say " "
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
