!
on error return
!
var list
!
let nOtf 0 /new integer
let i0 0 /new integer
!
for i 1 to list%found
    if (list'i'%procedure.eq."onTheFly".or.list'i'%procedure.eq."DIY").and.list'i'%scan.ne.i0 then
       let i0 list'i'%scan
       let nOtf nOtf+1
    endif
next
!
if nOtf.eq.0 then
   say " "
   say "W-VIEW, only for OTF maps."
   say " "
   return
endif
!
g\set plot square 
g\set expand 1.2
!
define integer nphases
define real ndump
define double chi
!
let bval -1.e10 /new real
let npix 9 /new integer
define double xp[npix] yp[npix]
define character previousObject*20
!
define integer scanId[nOtf]
define character timeStamp*19[nOtf]
!
let indx 0 /new integer
!
let i0 0
!
for i 1 to list%found
!
    if (list'i'%procedure.eq."onTheFly".or.list'i'%procedure.eq."DIY").and.list'i'%scan.ne.i0 then
       scan list'i'%scan
       let i0 list'i'%scan
       if indx.gt.1 then
          if scan%header%object.ne.previousObject then
	     say " "
	     say "W-PLOT: inconsistent data set."
	     say "Please load only one source into index list."
	     say " "
	     return
	  endif
       endif
       let indx indx+1
       if indx.eq.1 then
          var scan
	  var data
	  var array
	  var febe
       endif
       let timeStamp[indx] 'scan%header%date_obs'
       let scanId[indx] list'i'%scan

       define real aux /like data1%data%integnum
       let aux data1%data%integnum
       let npix febe1%header%febefeed
       let nphases febe1%header%nphases
       compute ndump max aux
       del /var aux
       define double xx'indx'[ndump,npix] yy'indx'[ndump,npix]
!
       for j 1 to npix
           let xx'indx'[j] data1%data%longoff*3600.
           let yy'indx'[j] data1%data%latoff*3600.
       next
!
       for j 1 to nphases
           for k 1 to ndump
               if array1%data1%iswitch[k,j].eq."OFF" then
	          let yy'indx'[k,1:npix] bval
	       endif
           next
       next
!
       xp = febe1%data%feedoffx*3.6d+3
       yp = febe1%data%feedoffy*3.6d+3
!
       if febe1%header%dewrtmod.ne."EQUA" then
          if febe1%header%dewrtmod.eq."CABIN" then
             chi  = -data1%data%elevatio[1]
             chi  = chi+data1%data%parangle[1]
          else if febe1%header%dewrtmod.eq."HORIZ" then
             chi = data1%data%parangle[1]
          else if febe1%header%dewrtmod.eq."UNDEF" then
             chi = 0.
             say " "
             say "W-PLOT, dewar rotation mode unknown."
             say "W-PLOT, dewar rotation angle set to zero."
             say " "
          endif
          chi = chi*pi/180.
          xp = -febe1%data%feedoffx*cos(chi)+febe1%data%feedoffy*sin(chi)
          yp =  febe1%data%feedoffx*sin(chi)+febe1%data%feedoffy*cos(chi)
          xp = xp*3600.
          yp = yp*3600.
       endif

       for j 1 to npix
           let xx'indx'[j] xx'indx'[j]+xp[j]
           let yy'indx'[j] yy'indx'[j]+yp[j] /where yy'indx'[j].ne.bval
       next
!
       let previousObject 'scan%header%object'
!
   endif
!
next
!
g\set marker 4 3 .1
!
for j 1 to npix
    if j.eq.1 then
       limits /var xx1[j] yy1[j] /blanking bval 0.
    else
       limits < > < > /var xx1[j] yy1[j] /blanking bval 0.
    endif
    for i 2 to nOtf
        limits < > < > /var xx'i'[j] yy'i'[j] /blanking bval 0.
    next
next
!
g\set box match 4.0 2.5
box
label "\gD\ga [\r`]" /x
label "\gD\gd [\r`]" /y
g\draw relocate -3 -1.5 /box 1
g\set expand 1.6
g\label 'scan%header%object' /center 6
g\set expand 1.2
!
for j 1 to npix
    for i 1 to nOtf
        points xx'i'[j] yy'i'[j] /blanking bval 0.
    next
next
!
let dy 31-box_ymax /new real
let dx 31-box_xmax /new real
!
if dy.gt.dx then
   if nOtf.le.7 then
      for i 1 to nOtf
          draw relocate -4 '7-(i-1)' /box 7
          label "Scan: "'scanId[i]'" Time: "'timeStamp[i]' /center 6
      next
      pen /def
   else
      for i 1 to 7 
          draw relocate -4 '7-(i-1)' /box 7
          label "Scan: "'scanId[i]'" Time: "'timeStamp[i]' /center 6
      next
      for i 8 to nOtf
          draw relocate  -2 '15-i' /box 8
          label "Scan: "'scanId[i]'" Time: "'timeStamp[i]' /center 6
      next
   endif
else
   g\set expand 1
   for i 1 to nOtf
       draw relocate 4 '7-(i-1)' /box 9
       label 'scanId[i]'"  "'timeStamp[i]' /center 6
   next
endif
!
g\set expand 1.0
