!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure monitor-tsys-defaults
  set unit f
  set align f i
  set tel *E0H*F*
  set sort obs
  file in &1
end procedure monitor-tsys-defaults
!
begin procedure monitor-tsys-vs-time
  gtvl\create directory tsys_vs_time
  gtvl\change directory tsys_vs_time
  greg\set viewport 0.1 0.95 0.55 0.85
  !
  find
  variable gen /index
  define double ut /like idx%head%gen%ut
  let ut idx%head%gen%ut*24/(2*pi)
  limits /var ut idx%head%gen%tsys
  delete /var ut
  g\box
  g\pen 0 /dash 3
  g\rule y
  g\pen 0 /dash 1
  g\label "UT [hr]" /x
  g\label "Tsys [K(Ta*)]" /y 5
  limits /var idx%head%gen%ut idx%head%gen%tsys
  !
  list /toc line tele
  for isetup 1 to toc%nsetup
     pen 1+mod(isetup,6)
     find /line 'toc%setup[isetup,1]' /tele 'toc%setup[isetup,2]'
     variable gen /index
     g\connect idx%head%gen%ut idx%head%gen%tsys
  next isetup
  pen 0
end procedure monitor-tsys-vs-time
!
begin procedure monitor-tsys-vs-freq
  gtvl\create directory tsys_vs_freq
  gtvl\change directory tsys_vs_freq
  greg\set viewport 0.1 0.95 0.15 0.45
  !
  set source tsys
  set mode x 80000 117000
  set mode y user_ymin user_ymax*1.12 ! This assumes that a call to monitor-tsys-vs-time was done before...
  box
  g\pen 0 /dash 3
  g\rule y
  g\pen 0 /dash 1
  g\label "Tsys [K(Ta*)]" /y 5
  !
  ! First the last scan
  find
  get last
  define integer scan
  let scan r%head%gen%scan
  define character cdobs*12
  let cdobs 'r%head%gen%cdobs'
  find /obs 'cdobs' /scan 'scan'
  list /toc line tele
  pen 0
  for isetup 1 to toc%nsetup
     find /obs 'cdobs' /scan 'scan' /line 'toc%setup[isetup,1]' /tele 'toc%setup[isetup,2]'
     get last
     spectrum
  next isetup
  !
  ! Then the average +/- 3*rms
  find
  list /toc line tele
  for isetup 1 to toc%nsetup
     find /line 'toc%setup[isetup,1]' /tele 'toc%setup[isetup,2]'
     pen 1+mod(isetup,6) /dash 1
     average /nocheck /res
     spectrum
     define real ave /like ry
     let ave ry
     rms /nocheck /res
     define real rms /like ry
     let rms ry
     pen 1+mod(isetup,6) /dash 3
     let ry r%head%spe%bad
     let ry ave+3*rms /where (abs(rms-r%head%spe%bad).gt.0).and.(abs(ave-r%head%spe%bad).gt.0)
     spectrum
     let ry ave-3*rms /where (abs(rms-r%head%spe%bad).gt.0).and.(abs(ave-r%head%spe%bad).gt.0)
     spectrum
     delete /var ave rms
     pen 1+mod(isetup,6) /dash 1
  next isetup
  list /toc
  pen 0
  !
  set mode a tot
  set source *
end procedure monitor-tsys-vs-freq
!
begin procedure monitor-tsys-inter
  clear
  @ monitor-tsys-defaults raw-mrtcal/&1/spectraOdp&2
  @ monitor-tsys-vs-time
  @ monitor-tsys-vs-freq
  change directory <greg
  set default
end procedure monitor-tsys-inter

begin procedure monitor-tsys-pipe
  for /while .true.
     @ monitor-tsys-inter &1 &2
     sic date
     say 'sys_date'
     new
  next
end procedure monitor-tsys-pipe
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
!@ monitor-tsys-inter 022-14 20140808
@ monitor-tsys-pipe 022-14 20140811
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
