!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Initialization
if .not.exist(window_init) then
   @ window_tools.greg
endif
!
! Plot cleaning
destroy all
clear alpha
@ window_init
!
! Definition of useful variables
if .not.exist(telcal_ss_dir) then
   define character telcal_ss_dir*256 /global
endif
define double daz del ddaz ddel
!
! Definition of window positions
let position 0.214 1.322 0.125 0.9
let inter 0.25 0.4
let aspect_ratio no
!
! Title
@ window_xy 1 1 1
greg1\set expand 1
draw text 0 2.5 "Solve for pointing through a cross" 8 0 /char 8 
greg1\set expand 0.8
!
! Loop on subscans
for isub 1 to 4
  ! Panel position for subscan isub
  @ window_xy 2 2 'isub'
  !
  ! Check structure status
  if (pcross%sub'isub'%fun%flag.eq.0) then
     ! Pointing has been solved => Plot
     limits /var pcross%sub'isub'%dat%x pcross%sub'isub'%dat%y
     pen 0
     histogram pcross%sub'isub'%dat%x pcross%sub'isub'%dat%y
     pen 1
     connect pcross%sub'isub'%sol%x pcross%sub'isub'%sol%y
  else if (pcross%sub'isub'%fun%flag.eq.1) then
     ! Structure is waiting for data
     pen 1
     draw text 0 0 "Waiting for data" 5 0 /char 5
  else if (pcross%sub'isub'%fun%flag.eq.2) then
     ! Structure is waiting for solution
     pen 1
     draw text 0 0 "Waiting for solution" 5 0 /char 5
  else
     ! Unknown structure status
     pen 1
     draw text 0 0 "Something wrong (Unknown status)" 5 0 /char 5     
  endif
  pen 0
  !
  ! Draw box
  box
  !
  ! Draw labels
  ! A translation of character chain through a procedure is needed because
  ! the chain name must be interprated twice...
  @ telcal-let telcal_ss_dir pcross%sub'isub'%dir
  draw text 1 -1 'telcal_ss_dir' 6 0 /char 7
  if (telcal_ss_dir.eq."+LAM".or.telcal_ss_dir.eq."-LAM") then
     draw text 1 1 "Meas \gDAZ = " 6 0 /char 7
     if (pcross%sub'isub'%fun%flag.ne.1) then
        if (pcross%sub'isub'%fun%name.eq."2*GAUSSIAN+BASE") then
           let daz pcross%sub'isub'%fun%par2%value+pcross%sub'isub'%fun%par5%value/2
        else
           let daz pcross%sub'isub'%fun%par2%value
        endif
        let daz  nint(100*daz)/100
        let ddaz nint(100*pcross%sub'isub'%fun%par2%error)/100
        label 'daz'"\r` ("'ddaz'"\r`)"  /center 6
     endif
     label "Az [arc sec]" /x
  else if (telcal_ss_dir.eq."+BET".or.telcal_ss_dir.eq."-BET") then
     draw text 1 1 "Meas \gDEL = " 6 0 /char 7
     if (pcross%sub'isub'%fun%flag.ne.1) then
        if (pcross%sub'isub'%fun%name.eq."2*GAUSSIAN+BASE") then
           let del pcross%sub'isub'%fun%par2%value+pcross%sub'isub'%fun%par5%value/2
        else
           let del pcross%sub'isub'%fun%par2%value
        endif
        let del  nint(100*del)/100
        let ddel nint(100*pcross%sub'isub'%fun%par2%error)/100
        label 'del'"\r` ("'ddel'"\r`)"  /center 6
     endif
     label "El [arc sec]" /x
  else
     say "W-POINT, Unknown scanning direction "'telcal_ss_dir'
  endif
  draw text -3 0 "Intensity" 5 90 /char 4
next isub
!
! Clean up
delete /var telcal_ss_dir
greg1\set expand 1
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
