!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
if ((size[1].eq.0).or.(size[2].eq.0)) then
   message e extract-fov "Size of field of view must be > 0"
   return base
endif
!
define double xmin xmax
define double ymin ymax
let xmin (center[1]-0.5*size[1])*sec
let xmax (center[1]+0.5*size[1])*sec
let ymin (center[2]-0.5*size[2])*sec
let ymax (center[2]+0.5*size[2])*sec
!
define uvtable in 'name' read
if ((in%daps%iloff.eq.0).or.(in%daps%imoff.eq.0)) then
   message e extract-fov "No DAPS column loff or moff"
   return base
endif
define integer ix iy
let ix in%daps%iloff
let iy in%daps%imoff
!
define real mvisi inside[in%nvisi]
let inside 0
let inside 1 /where ((xmin.le.in[ix,]).and.(in[ix,].le.xmax).and.(ymin.le.in[iy,]).and.(in[iy,].le.ymax))
compute mvisi sum inside
!
define integer nvisi
let nvisi mvisi
message i extract-fov "Found "'nvisi'" visibilities out of "'in%nvisi'
define uvtable ou['in%dim[1]',nvisi] 'name'"-ext" real
let ou% in%
let nvisi 0
for ivisi 1 to in%nvisi
   if (inside[ivisi].eq.1) then
      let nvisi nvisi+1
      if (nvisi.le.in%nvisi) then
         let ou[nvisi] in[ivisi]
      else
         message e extract-fov "Found more visibilities than expected "'in%nvisi'
         return base
      endif
   endif
next ivisi
delete /var ou in
header 'name'"-ext.uvt"
!
let name 'name'"-ext"
message i extract-fov "name set to "'name'
! 
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
