!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! p_3view_sub.ima
!
! Support for INSPECT_3D
!
! Derived from GO 3VIEW (J.Pety), with a number
! of improvements
! - Arbitrary axis order
! - Side window for current pixel
! - Variables grouped in inspect% structure
! 
!
if (&1%dim[3].le.1) then
  message E INSPECT_3D "Only 2 dimensions"
  return base
endif
!
! Definitions - to be cleaned up
if (.not.exist(inspect)) then
  define structure inspect /global
  define integer inspect%ix inspect%iy inspect%iv /global
  define logical inspect%init inspect%movie /global
  define double inspect%ulimit[2,3] inspect%vrange[2] /global
  define real inspect%boxes[4,4] /global
  define char inspect%cbox*8[5] /global
  define integer inspect%plane /global
  define real inspect%velo /global
  define double inspect%freq inspect%jyperk /global
  !
  define logical inspect%old /global
  let inspect%old no
  !
  let inspect%cbox "xy" "vy" "xv" "spectrum" "outside"
  let inspect%init  no
  let inspect%movie no
endif
if (.not.exist(vlsr)) then
  define real vlsr /global
endif
!
greg2\rgdata &1 /var
let inspect%jyperk &1%major*&1%minor/4./log(2.0)
let inspect%jyperk 2.0*1.38d3*pi*inspect%jyperk|(299792.458d3|&1%restfre*1d-6)^2
!
! This will properly re-define the projection in case of strange ordering
@ p_axes &1
!
if (box_limits.ne." ") then
  define real lim[4]
  symb alim 'box_limits'
  let lim 'alim'
  let lim lim*box%aunit
  let inspect%ulimit[1] lim[1] lim[2]
  let inspect%ulimit[2] lim[3] lim[4]
  dele /var lim
else if size[1].eq.0 then
  greg1\limits (0.5-&1%convert[1,i_x])*&1%convert[3,i_x]+&1%convert[2,i_x]  - 
    (&1%dim[i_x]+0.5-&1%convert[1,i_x])*&1%convert[3,i_x]+&1%convert[2,i_x] - 
    (0.5-&1%convert[1,i_y])*&1%convert[3,i_y]+&1%convert[2,i_y] - 
    (&1%dim[i_y]+0.5-&1%convert[1,i_y])*&1%convert[3,i_y]+&1%convert[2,i_y]  
  let inspect%ulimit[1] user_xmin user_xmax
  let inspect%ulimit[2] user_ymin user_ymax
else !! if (size[1].gt.0) then
!  greg1\limits center[1]+size[1]|2 center[1]-size[1]|2 center[2]-size[1]|2 center[2]+size[1]|2 seconds
  let inspect%ulimit[1] '(center[1]+size[1]|2)*box%aunit' '(center[1]-size[1]|2)*box%aunit'
  let inspect%ulimit[2] '(center[2]-size[1]|2)*box%aunit' '(center[2]+size[1]|2)*box%aunit'
endif
!
let inspect%ulimit[3]   (0.5-&1%convert[1,i_f])*&1%convert[3,i_f]+&1%convert[2,i_f] -
  (&1%dim[i_f]+0.5-&1%convert[1,i_f])*&1%convert[3,i_f]+&1%convert[2,i_f]
if (inspect%ulimit[1,3].gt.inspect%ulimit[2,3]) then
   let u inspect%ulimit[1,3] /new real
   let inspect%ulimit[1,3] inspect%ulimit[2,3]
   let inspect%ulimit[2,3] u
   dele /var u
endif
!
if (exist(range)) then
  let inspect%vrange range
  if (range[1].ne.0.or.range[2].ne.0) then
   let inspect%ulimit[1,3] max(inspect%ulimit[1,3],range[1])
   let inspect%ulimit[2,3] min(inspect%ulimit[2,3],range[2])
  endif
endif
if (span[1].ne.0.or.span[2].ne.0) then
   let inspect%ulimit[1,3] max(inspect%ulimit[1,3],span[1])
   let inspect%ulimit[2,3] min(inspect%ulimit[2,3],span[2])
endif
!
!
if exist(popup) delet /var popup
!
if (inspect%init) then
  if ("&1".eq."?") then
    @ input_3view
  else
    let inspect%movie no
    let inspect%ix min(inspect%ix,&1%dim[i_x])
    let inspect%ix max(1,inspect%ix)
    let inspect%iy min(inspect%iy,&1%dim[i_y])
    let inspect%iy max(1,inspect%iy)
    let inspect%iv min(inspect%iv,&1%dim[i_f])
    let inspect%iv max(1,inspect%iv)
    @ re_3view &1
    @ loop_3view &1
  endif
  dele /var i_x i_y i_f
  return
else
  let inspect%ix 0.5*&1%dim[i_x]
  let inspect%iy 0.5*&1%dim[i_y]
  let inspect%iv 0.5*&1%dim[i_f]
endif
!
! Reset full image
!
begin procedure 3view_sub_box
  ! Select the box position
  define real views[4]  thebox[4]
  define integer ibox
  let inspect%boxes[1] 4. 14. 1 11
  let inspect%boxes[2] 16. 26. 1 11
  let inspect%boxes[3] 4. 14. 11 21
  let inspect%boxes[4] 16. 26.  11 21
  let views 0.05 0.95 0.075 0.975
  !
  let ibox &1
  let thebox[1] inspect%boxes[1,ibox]+views[1]*(inspect%boxes[2,ibox]-inspect%boxes[1,ibox])
  let thebox[2] inspect%boxes[1,ibox]+views[2]*(inspect%boxes[2,ibox]-inspect%boxes[1,ibox])
  let thebox[3] inspect%boxes[3,ibox]+views[3]*(inspect%boxes[4,ibox]-inspect%boxes[3,ibox])
  let thebox[4] inspect%boxes[3,ibox]+views[4]*(inspect%boxes[4,ibox]-inspect%boxes[3,ibox])
  greg1\set box thebox[1] thebox[2] thebox[3] thebox[4]
end procedure 3view_sub_box
!
begin procedure crosses
  !
  define real xpos ypos vpos
  let xpos ((inspect%ix-&1%convert[1,i_x])*&1%convert[3,i_x]+&1%convert[2,i_x])
  let ypos ((inspect%iy-&1%convert[1,i_y])*&1%convert[3,i_y]+&1%convert[2,i_y])
  let vpos ((inspect%iv-&1%convert[1,i_f])*&1%convert[3,i_f]+&1%convert[2,i_f])
  !
  gtvl\change directory
  gtvl\change directory xy
  !
  greg1\draw relo cross*sec 0 /user
  greg1\draw line -cross*sec 0 /user
  greg1\draw relo 0 cross*sec /user
  greg1\draw line 0 -cross*sec /user
  greg1\draw relo xpos user_ymin /user
  greg1\draw line xpos user_ymax /user
  greg1\draw relo user_xmin ypos /user
  greg1\draw line user_xmax ypos /user
  !
  gtvl\change directory
  gtvl\change directory vy
  greg1\draw relo vpos user_ymin /user
  greg1\draw line vpos user_ymax /user
  greg1\draw relo user_xmin ypos /user
  greg1\draw line user_xmax ypos /user
  !
  if (vlsr.ne.0.0) then
    greg1\pencil /col 1
    greg1\draw relo vlsr -cross*sec /user
    greg1\draw line vlsr +cross*sec /user
    greg1\draw relo vlsr-0.05*(user_xmax-user_xmin) 0 /user
    greg1\draw line vlsr+0.05*(user_xmax-user_xmin) 0 /user
    greg1\pencil /col 0
  endif
  gtvl\change directory
  gtvl\change directory xv
  greg1\draw relo user_xmin vpos /user
  greg1\draw line user_xmax vpos /user
  greg1\draw relo xpos user_ymin /user
  greg1\draw line xpos user_ymax /user
  if (vlsr.ne.0.0) then
    greg1\pencil /col 1
    greg1\draw relo -cross*sec vlsr /user
    greg1\draw line +cross*sec vlsr /user
    greg1\draw relo  0 vlsr-0.05*(user_ymax-user_ymin) /user
    greg1\draw line  0 vlsr+0.05*(user_ymax-user_ymin) /user
    greg1\pencil /col 0
  endif
  !
end procedure crosses
!
begin procedure inspect_extract
  ! @ inspect-extract Cube Plane Axis Map
  !    Map = Cube Plane along specified Axis
  if (&3.eq.3) then
    let &4 &1[&2]
  else if (&3.eq.1) then
    let &4 &1[&2,,]
  else
    let &4 &1[,&2,]
  endif
end procedure 
!
begin procedure show_plot
  if (do_bit) then
    greg2\plot /scal lin &1%min &1%max
  endif
  if do_grey then
    greg2\rgmap quiet /grey /abs
    greg2\rgmap quiet /abs
  else if do_contour then
    greg2\rgmap quiet /abs
  endif
end procedure show_plot
!
begin procedure re_3view
  !
  ! RE_3VIEW is called at the first time before loop_3view
  !
  define chara cdo*4
  !
  if (pro%narg.eq.1) then
    let cdo "*"
  else
    let cdo &2
  endif
  gtvl\change directory <greg
  if (.not.inspect%movie) then
    gtvl\clear directory
  endif
  !
  define integer nx ny nv ibox
  let nx &1%dim[i_x]
  let ny &1%dim[i_y]
  let nv &1%dim[i_f]
  define structure xy
  define structure vy
  define structure xv
  define real xy%data[nx,ny] vy%data[nv,ny] xv%data[nx,nv]
  define double xy%convert[3,2] vy%convert[3,2] xv%convert[3,2]
  define double numb xspectre[nv] yspectre[nv]
  !
  ! Plot the current plane
  if (cdo.eq."*".or.cdo.eq."V") then
    gtvl\change directory <greg
    let ibox 1
    if (.not.inspect%movie) then
      gtvl\create directory 'inspect%cbox[ibox]'
    endif
    gtvl\change directory 'inspect%cbox[ibox]'
    @ 3view_sub_box 'ibox'
    if (i_x.gt.i_y) then
      define real ab[ny,nx] /global
      @ inspect_extract &1 'inspect%iv' 'i_f' ab
      transpose ab xy%data 21
    else
      define real ab[nx,ny] /global
      @ inspect_extract &1 'inspect%iv' 'i_f' ab
      xy%data = ab
    endif
    delet /var ab
    let xy%convert[1] &1%convert[i_x]
    let xy%convert[2] &1%convert[i_y]
    greg1\limits inspect%ulimit[1,1] inspect%ulimit[2,1] inspect%ulimit[1,2] inspect%ulimit[2,2]
    !
    greg2\rgdata xy /var
    !plot
    @ show_plot &1
    !
    if (inspect%old) then
      if (&1%ptype.ne.0) then
        greg1\box /unit sec ! /abs
        greg1\label "R.A. Offset (`)" /X
        greg1\label "Dec. Offset (`)" /Y
      else
        greg1\box
        greg1\label '&1%unit1'  /X
        greg1\label '&1%unit2'  /Y
      endif
    else
      if box%kindx.eq."A" then
        greg1\box /abs
      else
        greg1\box /unit 'box%kindx'
      endif
      greg1\label 'box%legendx' /x
      greg1\label 'box%legendy' /Y
    endif
    let numb 0.001*nint(1000*((inspect%iv-&1%convert[1,i_f])*&1%convert[3,i_f]+&1%convert[2,i_f]))
    !
    greg1\draw text 1 -1 "V\\dLSR\\u "'numb' 6 0 /CHAR 7
  endif
  !
  !
  ! Plot the YV cut
  if (cdo.eq."*".or.cdo.eq."X") then
    gtvl\change directory <greg
    let ibox 2
    if (.not.inspect%movie) then
       gtvl\create directory 'inspect%cbox[ibox]'
    endif
    gtvl\change directory 'inspect%cbox[ibox]'
    @ 3view_sub_box 'ibox'
    !
    greg1\limits inspect%ulimit[1,3] inspect%ulimit[2,3] inspect%ulimit[1,2] inspect%ulimit[2,2]
    !
    if (i_f.gt.i_y) then
      define real ab[ny,nv] /global
      @ inspect_extract &1 'inspect%ix' 'i_x' ab
      transpose ab vy%data 21
    else
      define real ab[nv,ny] /global
      @ inspect_extract &1 'inspect%ix' 'i_x' ab
      vy%data = ab
    endif
    delete /var ab
    !
    let vy%convert[1] &1%convert[i_f]
    let vy%convert[2] &1%convert[i_y]
    !
    greg2\rgdata vy /var
    @ show_plot &1
    !
    greg1\box n n n
    greg1\axis xl
    greg1\axis xu
    if (inspect%old) then
      if (&1%ptype.ne.0) then
        greg1\limits inspect%ulimit[1,3] inspect%ulimit[2,3] inspect%ulimit[1,2]/sec inspect%ulimit[2,2]/sec
      endif
      greg1\axis yl /label N
      greg1\axis yr /label O
      greg1\limits inspect%ulimit[1,3] inspect%ulimit[2,3] inspect%ulimit[1,2] inspect%ulimit[2,2]
    else
      greg1\limits inspect%ulimit[1,1] inspect%ulimit[2,1] inspect%ulimit[1,2] inspect%ulimit[2,2]
      if (box%kindy.eq."A") then
        greg1\axis yl /abs /label N
        greg1\axis yr /abs /label O
      else
        greg1\axis yl /unit 'box%kindy' /label N
        greg1\axis yr /unit 'box%kindy' /label O
      endif
      greg1\limits inspect%ulimit[1,3] inspect%ulimit[2,3] inspect%ulimit[1,2] inspect%ulimit[2,2]
    endif
    greg1\label "Velocity (km/s)" /X
    !
    let numb (inspect%ix-&1%convert[1,i_x])*&1%convert[3,i_x]+&1%convert[2,i_x]
    if (&1%ptype.ne.0) then
      let numb 0.001*nint(1000*numb/sec) 
      greg1\draw text 1 -1 "\gdRA "'numb'"`" 6 0 /CHAR 7
    else
      let numb 0.001*nint(1000*numb) 
      greg1\draw text 1 -1 '&1%unit1'" "'numb' 6 0 /CHAR 7
    endif
    if (do_bit) then
      greg2\wedge left
      greg1\draw text -3.5 0 "Flux (Jy/beam)" 5 90 /char 4
    endif
  endif
  !
  ! Plot the XV cut
  if (cdo.eq."*".or.cdo.eq."Y") then
    gtvl\change directory <greg
    let ibox 3
    if (.not.inspect%movie) then
       gtvl\create directory 'inspect%cbox[ibox]'
    endif
    gtvl\change directory 'inspect%cbox[ibox]'
    @ 3view_sub_box 'ibox'
    !
    if (i_f.gt.i_x) then
      define real ab[nx,nv] /global
      @ inspect_extract &1 'inspect%iy' 'i_y' ab
      xv%data = ab
    else
      define real ab[nv,nx] /global
      @ inspect_extract &1 'inspect%iy' 'i_y' ab
      transpose ab xv%data 21
    endif
    delete /var ab
    !
    let xv%convert[1] &1%convert[i_x]
    let xv%convert[2] &1%convert[i_f]
    greg1\limits inspect%ulimit[1,1] inspect%ulimit[2,1] inspect%ulimit[1,3] inspect%ulimit[2,3]
    !
    greg2\rgdata xv /var
    @ show_plot &1
    !
    greg1\box n o
    if inspect%old then
      if (&1%ptype.ne.0) then
        greg1\limits inspect%ulimit[1,1]/sec inspect%ulimit[2,1]/sec inspect%ulimit[1,3] inspect%ulimit[2,3]
      endif
      greg1\axis xl
    else
      greg1\limits inspect%ulimit[1,1] inspect%ulimit[2,1] inspect%ulimit[1,2] inspect%ulimit[2,2]
      if (box%kindx.eq."A") then
        axis xl /abs
        axis xu /abs
      else
        axis xl /unit 'box%kindx'
        axis xu /unit 'box%kindx'
      endif
    endif
    greg1\limits inspect%ulimit[1,1] inspect%ulimit[2,1] inspect%ulimit[1,3] inspect%ulimit[2,3]
    greg1\label "Velocity (km/s)" /Y
    !
    let numb (inspect%iy-&1%convert[1,i_y])*&1%convert[3,i_y]+&1%convert[2,i_y]
    if (&1%ptype.ne.0) then
      let numb 0.001*nint(1000*numb/sec) 
      greg1\draw text 1 -1 "\gdDec "'numb' 6 0 /CHAR 7
    else
      let numb 0.001*nint(1000*numb) 
      greg1\draw text 1 -1 '&1%unit2'" "'numb' 6 0 /CHAR 7
    endif
  endif
  !
  ! Display the current spectrum
  if (cdo.eq."*") then
    gtvl\change dir <greg
    let ibox 4
    if (.not.inspect%movie) then
       gtvl\create directory 'inspect%cbox[ibox]'
    endif
    gtvl\change directory 'inspect%cbox[ibox]'
    @ 3view_sub_box 'ibox'
    !
    let xspectre[is] (is-&1%convert[1,i_f])*&1%convert[3,i_f]+&1%convert[2,i_f]
    if i_f.eq.3 then
      let yspectre &1[inspect%ix,inspect%iy,]
    else if i_f.eq.2 then
      let yspectre &1[inspect%ix,,inspect%iy]
    else
      let yspectre &1[,inspect%ix,inspect%iy]
    endif
    !
    if (inspect%vrange[1].ne.0).or.(inspect%vrange[2].ne.0) then
      greg1\limits 'inspect%vrange[1]' 'inspect%vrange[2]' *  * /var xspectre yspectre
    else
      greg1\limits /var xspectre yspectre
    endif
    greg1\histogram xspectre yspectre
    !
    if (inspect%jyperk.eq.0) then
      greg1\box
      !! greg1\label "Velocity (km/s)" /X
    else
      greg1\axis xl
      greg1\axis xu
      greg1\axis yl
      lim = = user_ymin/inspect%jyperk user_ymax/inspect%jyperk
      greg1\axis yr /label O
      lim = = user_ymin/inspect%jyperk user_ymax*inspect%jyperk
      greg1\draw text 3.5 0 "Tb (K) " 5 90 /char 6
    endif
    greg1\draw text -3.5 0 "Flux (Jy/beam)" 5 90 /char 4
    !
    @ crosses &1
  endif
  !
  ! Side display
  !
  let inspect%plane inspect%iv
  let inspect%velo  (inspect%plane-&1%convert[1,i_f])*&1%velres+&1%veloff
  let inspect%freq  (inspect%plane-&1%convert[1,i_f])*&1%freqres+&1%restfre
  @ side
  @ p_side_display &1 'inspect%ix' 'inspect%iy' inspect NO
  !
  gtvl\change dir <greg
  !
end procedure re_3view
!
begin procedure loop_3view
 define integer ibox
 for /while .true.
  gtvl\change directory <greg
  greg1\draw relo
  if (cursor_code.eq."Q") then !! .or.(cursor_code.eq."E") then
     return
  else if (cursor_code.eq."E") then
     return all
  else if (cursor_code.eq."H") then
     @ help_3view
  else if (cursor_code.eq."V") then
     @ vmovie &1
  else if (cursor_code.eq."X") then
     @ xmovie &1
  else if (cursor_code.eq."Y") then
     @ ymovie &1
  else if (cursor_code.eq."?") then
     @ input_3view
  else
     let ibox 0
     for i 1 to 4
       if ((x_pen.ge.inspect%boxes[1,i]).and.(x_pen.le.inspect%boxes[2,i])) then
        if ((y_pen.ge.inspect%boxes[3,i]).and.(y_pen.le.inspect%boxes[4,i])) then
          let ibox i
          break 
        endif
       endif
     next
     !
     ! Get the coordinates according to which box
     !
     if (ibox.ge.1.and.ibox.le.3) then
       gtvl\change directory <greg<'inspect%cbox[ibox]'
       greg1\draw relo * *
       if (ibox.eq.1) then  ! Cuts in X and Y
        inspect%ix = (use_curs[1]-&1%convert[2,i_x])/&1%convert[3,i_x]+&1%convert[1,i_x]
        inspect%ix = max(1,inspect%ix)
        inspect%ix = min(&1%dim[i_x],inspect%ix)
        inspect%iy = (use_curs[2]-&1%convert[2,i_y])/&1%convert[3,i_y]+&1%convert[1,i_y]
        inspect%iy = max(1,inspect%iy)
        inspect%iy = min(&1%dim[i_y],inspect%iy)
       else if (ibox.eq.2) then  ! Cuts in V and Y
        inspect%iv = (use_curs[1]-&1%convert[2,i_f])/&1%convert[3,i_f]+&1%convert[1,i_f]
        inspect%iv = max(1,inspect%iv)
        inspect%iv = min(&1%dim[i_f],inspect%iv)        
        inspect%iy = (use_curs[2]-&1%convert[2,i_y])/&1%convert[3,i_y]+&1%convert[1,i_y]
        inspect%iy = max(1,inspect%iy)
        inspect%iy = min(&1%dim[i_y],inspect%iy)
       else if (ibox.eq.3) then  ! Cuts in X and V
        inspect%ix = (use_curs[1]-&1%convert[2,i_x])/&1%convert[3,i_x]+&1%convert[1,i_x]
        inspect%ix = max(1,inspect%ix)
        inspect%ix = min(&1%dim[i_x],inspect%ix)
        inspect%iv = (use_curs[2]-&1%convert[2,i_f])/&1%convert[3,i_f]+&1%convert[1,i_f]
        inspect%iv = max(1,inspect%iv)
        inspect%iv = min(&1%dim[i_f],inspect%iv)        
       end if
       gtvl\change directory <greg
       @ re_3view &1
     endif
  endif
 next
end procedure loop_3view
!
!
begin procedure help_3view
  say " "
  say "Authors: J.Pety & S.Guilloteau (2018)"
  say "Actions:"
  say "   Press E key: EXIT loop"
  say "   Press H key: HELP display"
  say "   Press Q key: QUIT loop"
  say "   Press V key: Velocity movie"
  say "   Press X key: X-axis movie"
  say "   Press Y key: Y-axis movie"
  say "   Press ? key: Get input parameters"
  say " "
end procedure help_3view
!
begin procedure input_3view
  say "INSPECT_3D will cuts along the 3 main directions"
  say " "
  !say "  Display the header     "'ansi%blue'"DO_HEADER"'ansi%none'"   [" 'bold''do_header''norm' "]   "
  say "  Display a color wedge  "'ansi%blue'"DO_WEDGE"'ansi%none'"    [" 'bold''do_wedge''norm' "]     "
  say "  Plot bitmaps           "'ansi%blue'"DO_BIT"'ansi%none'"      [" 'bold''do_bit''norm' "]         "
  !say "  Add the clean beam     "'ansi%blue'"DO_NICE"'ansi%none'"     [" 'bold''do_dirty''norm' "]     "
  !say "  Add the UV coverage    "'ansi%blue'"DO_COVERAGE"'ansi%none'" [" 'bold''do_coverage''norm' "]  "
  !say "  Add the dirty beam     "'ansi%blue'"DO_DIRTY"'ansi%none'"    [" 'bold''do_dirty''norm' "]     "
  !say "  Display the labels     "'ansi%blue'"DO_LABEL"'ansi%none'"    [" 'bold''do_label''norm' "]     "
  say "  Display contour levels "'ansi%blue'"DO_CONTOUR"'ansi%none'"  [" 'bold''do_contour''norm' "] "
  say "  grey-scale contours    "'ansi%blue'"DO_GREY"'ansi%none'"     [" 'bold''do_grey''norm' "] "
  say "  Better marks           "'ansi%blue'"DO_MASK"'ansi%none'"     [" 'bold''do_mask''norm' "]           (Hide image behind channel marks)"
  !
  say " "
  say "  Channel range          "'ansi%blue'"RANGE"'ansi%none'"       [" 'bold''range[1]''norm'  'bold''range[2]''norm' "]         in 3rd axis unit, (0,0) ==> all"
  !say "  Channel label          "'ansi%blue'"MARK"'ansi%none'"        [" 'bold''mark''norm' "]    [VELOCITY, FREQUENCY or CHANNEL]"
  say "  Displayed field size   "'ansi%blue'"SIZE"'ansi%none'"        [" 'bold''size[1]' 'size[2]''norm' "]         in arcsec"
  say "  Field center           "'ansi%blue'"CENTER"'ansi%none'"      [" 'bold''center[1]' 'center[2]''norm' "]         offset in arcsec"
  say "  Cross size at center   "'ansi%blue'"CROSS"'ansi%none'"       [" 'bold''cross''norm' "]           in arcsec, 0 ==> none "
  say "  Colour Scale range     "'ansi%blue'"SCALE"'ansi%none'"       [" 'bold''scale[1]' 'scale[2]''norm' "]         (0,0) ==> all dynamic"
  say "  Contour levels         "'ansi%blue'"SPACING"'ansi%none'"     ["  'bold''spacing[1]'" "'spacing[2]''norm'"] "
  say "                                     [>0 ==> levels equally spaced by the value of SPACING]"
  say "                                     [=0 ==> automatic determination]"
  say "                                     [<0 ==> manually use LEVELS command]"
  say " "
  say "Actions:"
  say "   Press E key: EXIT loop"
  say "   Press H key: HELP display"
  say "   Press Q key: QUIT loop"
  say "   Press V key: Velocity movie"
  say "   Press X key: X-axis movie"
  say "   Press Y key: Y-axis movie"
  say " "
end procedure input_3view
!
begin procedure vmovie
  !
  define integer old_iv
  let old_iv inspect%iv
  let inspect%movie yes
  gtvl\change directory
  gtvl\change directory vy
  define integer ivfirst ivlast
  let ivfirst max((user_xmin-&1%convert[2,3])/&1%convert[3,3]+&1%convert[1,3],1)
  let ivlast  min((user_xmax-&1%convert[2,3])/&1%convert[3,3]+&1%convert[1,3],&1%dim[3])
  for i ivfirst to ivlast
    let inspect%iv i
    @ re_3view &1 V
!    sic wait 1
  next
  let inspect%movie no
  let inspect%iv old_iv
  @ re_3view &1
  !
end procedure vmovie
!
begin procedure xmovie
  !
  define integer old_ix
  let old_ix inspect%ix
  let inspect%movie yes
  gtvl\change directory
  gtvl\change directory xy
  define integer ixfirst ixlast
  let ixfirst max((user_xmin-&1%convert[2,i_x])/&1%convert[3,i_x]+&1%convert[1,i_x],1)
  let ixlast  min((user_xmax-&1%convert[2,i_x])/&1%convert[3,i_x]+&1%convert[1,i_x],&1%dim[i_x])
  for i ixfirst to ixlast
    let inspect%ix i
    @ re_3view &1 X
!    sic wait 1
  next
  let inspect%movie no
  let inspect%ix old_ix
  @ re_3view &1
  !
end procedure xmovie
!
begin procedure ymovie
  !
  define integer old_iy
  let old_iy inspect%iy
  let inspect%movie yes
  gtvl\change directory
  gtvl\change directory xy
  define integer iyfirst iylast
  let iyfirst max((user_ymin-&1%convert[2,i_y])/&1%convert[3,i_y]+&1%convert[1,i_y],1)
  let iylast  min((user_ymax-&1%convert[2,i_y])/&1%convert[3,i_y]+&1%convert[1,i_y],&1%dim[i_y])
  for i iyfirst to iylast
    let inspect%iy i
    @ re_3view &1 Y
!    sic wait 1
  next
  let inspect%movie no
  let inspect%iy old_iy
  @ re_3view &1
  !
end procedure ymovie
!
! First time run
if ("&1".eq."?") then
  @ input_3view
else
  @ help_3view
  @ re_3view &1
  let inspect%init yes
  @ loop_3view &1
endif
dele /var i_x i_y i_f
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
