!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! p_explore_sub.ima
!
! Support for EXPLORE_3D
!
if (&1%dim[3].le.1) then
  message E EXPLORE "Only 2 dimensions"
  return base
endif
let goon pro%narg.eq.1 /new logical
if .not.exist(sflux) then
  define char*32 sflux[2] /global
  let sflux 0
endif
if exist(srange) then
  if (size(stange).eq.2) let span srange
endif
!
! Definitions - to be cleaned up
if (.not.exist(explore)) then
  define structure explore /global
  define character explore%name*128 /global
  define integer explore%ix explore%iy explore%iv explore%plane explore%ib /global
  define logical explore%init explore%mean explore%exist[9] explore%debug /global
  define double explore%ulimit[2,4] explore%freq explore%rx[9] explore%ry[9] /global
  define real explore%boxes[4,9] explore%velo /global
  define char explore%cbox*4[9] /global
  define char*32 explore%cflux[2] /global
  define integer explore%size explore%imin explore%imax /global
  define integer explore%jmin explore%jmax /global
  define integer explore%near[7,9] explore%side[9] /global
  define real explore%offx[9] explore%offy[9] /global
  define double explore%convert[3] /global
  !
  let explore%cbox "S1" "S2" "S3" "S4" "mean" "S6" "S7" "S8" "S9"
  let explore%init  no
  let explore%mean yes
  let explore%debug no
  !
  ! Just for initialization - it is resized later
  define real explore%x[2] explore%y[2,9]  /global
endif
!
if ("&1".eq."?") then
  @ input_explore
  return
endif
!
if (.not.exist(vlsr)) then
  define real vlsr /global
endif
let explore%name &1
let explore%convert &1%convert[3]
!
greg2\rgdata &1 /var
!
if (box_limits.ne." ") then
  define real lim[4]
  symb alim 'box_limits'
  let lim 'alim'
  let lim lim*box%aunit
  let explore%ulimit[1] lim[1] lim[2]
  let explore%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 explore%ulimit[1] user_xmin user_xmax
  let explore%ulimit[2] user_ymin user_ymax
else
  let explore%ulimit[1] '(center[1]+size[1]|2)*box%aunit' '(center[1]-size[1]|2)*box%aunit'
  let explore%ulimit[2] '(center[2]-size[1]|2)*box%aunit' '(center[2]+size[1]|2)*box%aunit'
endif
!
let explore%ulimit[3]   (0.5-&1%convert[1,3])*&1%convert[3,3]+&1%convert[2,3] -
  (&1%dim[3]+0.5-&1%convert[1,3])*&1%convert[3,3]+&1%convert[2,3]
if (explore%ulimit[1,3].gt.explore%ulimit[2,3]) then
  let u explore%ulimit[1,3] /new real
  let explore%ulimit[1,3] explore%ulimit[2,3]
  let explore%ulimit[2,3] u
  dele /var u
endif
!
! Flux scale
if (&1%extrema.ne.0) then
  explore%ulimit[1,4] = &1%min
  explore%ulimit[2,4] = &1%max
else if (&1%blan.eq.0) then
  compute explore%ulimit[1,4] min &1
  compute explore%ulimit[2,4] max &1
else
  compute explore%ulimit[1,4] min &1 /blank &1%blank[1] &1%blank[2]
  compute explore%ulimit[2,4] max &1 /blank &1%blank[1] &1%blank[2]
endif
!
let explore%cflux * *
if (exist(sflux)) then
  if (sflux[1].ne."0".or.sflux[2].ne."0") let explore%cflux 'sflux[1]' 'sflux[2]'
endif
!
!
if exist(popup) delet /var popup
!
if (explore%init) then
  if ("&1".eq."?") then ! Cannot be
    @ input_explore
    return
  else
    let explore%ix min(explore%ix,&1%dim[1])
    let explore%ix max(1,explore%ix)
    let explore%iy min(explore%iy,&1%dim[2])
    let explore%iy max(1,explore%iy)
    let explore%iv min(explore%iv,&1%dim[3])
    let explore%iv max(1,explore%iv)
    @ re_explore &1
    if (goon) @ loop_explore &1
  endif
  return
else
  let explore%ix 0.5*&1%dim[1]
  let explore%iy 0.5*&1%dim[2]
  let explore%iv 0.5*&1%dim[3]
endif
!
! Reset full image
!
begin procedure explore_box
  ! Select the box position
  ! A central box (number 5) + 8 small boxes around (ordered as Keypad)
!
  define real views[4]  thebox[4]
  define integer ibox
  define real xbounds[6] ybounds[6]
  ! X bounds
  ! [3,9] [12.5,18.5] [22,28]
  let xbounds 3 9 12.5 18.5 22 28
  ! Y bounds
  ! [8.5,13.5] [15.5,20.5] [2,7]
  let ybounds 1.5 6  8.5 13 16 20.5
  ! Nearest available box
  let explore%near[1] 2 4 3 7 6 8 9
  let explore%near[2] 1 3 4 6 8 7 9
  let explore%near[3] 2 6 1 9 4 8 7
  let explore%near[4] 1 7 2 8 6 3 9
  let explore%near[6] 9 3 2 8 4 7 1
  let explore%near[7] 4 8 1 9 2 6 3
  let explore%near[8] 7 9 4 6 2 1 3
  let explore%near[9] 8 6 7 3 4 2 1
  ! Side of box and offsets for arrows
  let explore%side[i] 10-i
  let explore%offx 0.5 0 -0.5 1 0 -1 0.5 0 -0.5
  let explore%offy 0.5 0.5 0.5 0 0 0  -1 -1 -1
  !
  !
  let explore%boxes[1] xbounds[1] xbounds[2] ybounds[1] ybounds[2]
  let explore%boxes[2] xbounds[3] xbounds[4] ybounds[1] ybounds[2]
  let explore%boxes[3] xbounds[5] xbounds[6] ybounds[1] ybounds[2]
  let explore%boxes[4] xbounds[1] xbounds[2] ybounds[3] ybounds[4]
  !
  let explore%boxes[5] 11.5 19.5 11-4 11+4
  !
  let explore%boxes[6] xbounds[5] xbounds[6] ybounds[3] ybounds[4]
  let explore%boxes[7] xbounds[1] xbounds[2] ybounds[5] ybounds[6]
  let explore%boxes[8] xbounds[3] xbounds[4] ybounds[5] ybounds[6]
  let explore%boxes[9] xbounds[5] xbounds[6] ybounds[5] ybounds[6]
  !
  if (ibox.eq.5) then
    let views 0.05 0.95 0.075 0.975
  else
    let views 0 1 0 1
  endif
  !
  let ibox &1
  let thebox[1] explore%boxes[1,ibox]+views[1]*(explore%boxes[2,ibox]-explore%boxes[1,ibox])
  let thebox[2] explore%boxes[1,ibox]+views[2]*(explore%boxes[2,ibox]-explore%boxes[1,ibox])
  let thebox[3] explore%boxes[3,ibox]+views[3]*(explore%boxes[4,ibox]-explore%boxes[3,ibox])
  let thebox[4] explore%boxes[3,ibox]+views[4]*(explore%boxes[4,ibox]-explore%boxes[3,ibox])
  greg1\set box thebox[1] thebox[2] thebox[3] thebox[4]
  !
end procedure explore_box
!
begin procedure pixel_range
  ! @ pixel_range VAR Max Range Result
  define double lrange[2]
  define integer nc miplane[2]
  !
  let lrange &3
  let nc &2
  !
  if (lrange[1].ne.0.or.lrange[2].ne.0) then
    define integer i1 i2
    let i1 1
    let i2 2
    if (lrange[1].gt.lrange[2]) then
      if (&1%convert[3].gt.0) then
        let i1 2
        let i2 1
      endif
    else if (&1%convert[3].lt.0) then
      let i1 2
      let i2 1
    endif
    let miplane[1] (lrange[i1]-&1%convert[2])/&1%convert[3]+&1%convert[1]
    let miplane[2] (lrange[i2]-&1%convert[2])/&1%convert[3]+&1%convert[1]
    let miplane[1] max(1,miplane[1])
    let miplane[2] min(&2,miplane[2])
    !
    ! Protect against bad input ranges
    if miplane[1].gt.miplane[2] then
      message W EXPLORE "Resetting invalid input range " lrange[1] lrange[2]  /format a F13.2 F13.2 a
      let miplane 1 &2
      if (&1%convert[3].gt.0) then
        let lrange (miplane-&1%convert[1])*&1%convert[3]+&1%convert[2]
      else
        let lrange[2] (miplane[1]-&1%convert[1])*&1%convert[3]+&1%convert[2]
        let lrange[1] (miplane[2]-&1%convert[1])*&1%convert[3]+&1%convert[2]
      endif
      let &3 lrange ! Update the global range
    endif
  else
    let miplane 1 &2
  endif
  let &4 miplane[1]
  let &5 miplane[2]
end procedure pixel_range
!
begin procedure expl_plot
  define double numb
  if (do_bit) then
    greg2\plot /scal linear true_scale[1] true_scale[2]  !! &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
  !
  greg1\set expand 0.8
  if (angle_unit.lt.0) then
    greg1\box /abs
    greg1\label "R.A." /X
    greg1\label "Dec." /Y
  else
    greg1\box /unit 'box%bunit'
    greg1\label "R.A. Offset "'box%gunit' /X
    greg1\label "Dec. Offset "'box%gunit' /Y 3
  endif
  if .not.explore%mean then
    let numb 0.001*nint(1000*((explore%iv-&1%convert[1,3])*&1%convert[3,3]+&1%convert[2,3]))
    greg1\draw text 1 -1 "V\\dLSR\\u "'numb' 6 0 /CHAR 7
  endif
  greg1\set expand 1.0
end procedure expl_plot
!
begin procedure expl_spec
  define double uxy[2]
  define integer ib nc
  let ib &1
  let nc 'explore%name'%dim[3]
  greg1\set expand 0.65
  greg1\limits explore%ulimit[1,3] explore%ulimit[2,3]  -
    'explore%cflux[1]' 'explore%cflux[2]' -
    /var explore%x[explore%jmin:explore%jmax] explore%y[explore%jmin:explore%jmax,ib]
  !
  greg1\histogram explore%x explore%y[ib]
  greg1\axis xl
  greg1\axis xu
  greg1\axis yl /label N
  greg1\axis yr /label O
  if ('explore%name'%f_axis.eq.3) then
    if ('explore%name'%unit3.eq."FREQUENCY") then
      greg1\label "Frequency (MHz)" /X
    else
      greg1\label "Velocity (km/s)" /X
    endif
  else
    greg1\label "Channel / Plane number" /X  
  endif
  !
  if .not.explore%mean then
    greg1\pencil 2
    greg1\draw relo explore%velo user_ymin /user
    greg1\draw line explore%velo user_ymax /user
    greg1\pencil 0
  endif
  !
  greg1\set expand 0.85
  greg1\draw text -1 -1 -
    "("'0.01*nint(100*explore%rx[ib]/box%aunit)'","'0.01*nint(100*explore%ry[ib]/box%aunit)'")" -
    4 /char 9
  !
  greg1\set expand 1.5
  ! Get the spectrum position
  gtvl\change dir <greg<'explore%cbox[5]'
  greg1\draw relo explore%rx[ib] explore%ry[ib] /user
  ! Express it in local user units
  gtvl\change dir <greg<'explore%cbox[ib]'
  greg1\draw relo * *
  let uxy use_curs
  ! Draw the arrow
  greg1\draw relo explore%offx[ib] explore%offy[ib] /box explore%side[ib]
  greg1\draw arrow uxy[1] uxy[2] /user
  greg1\set expand 1.0
  gtvl\change dir <greg
end procedure expl_spec
!
begin procedure add_spectrum
  ! @ add_spectrum Ux Uy [Box]
  define char ac*128
  define integer ix iy ib
  define double ux uy
  let ac 'explore%name'
  !
  let ux &1*box%aunit
  let uy &2*box%aunit
  ix = (ux-'ac'%convert[2,1])/'ac'%convert[3,1]+'ac'%convert[1,1]
  iy = (uy-'ac'%convert[2,2])/'ac'%convert[3,2]+'ac'%convert[1,2]
  !
  if (ix.lt.1).or.(ix.gt.'ac'%dim[1]).or.(iy.lt.1).or.(iy.gt.'ac'%dim[2]) return
  !
  let ib 0
  if (pro%narg.eq.3) then
    let ib &3
    if (ib.lt.1).or.(ib.gt.9).or.(ib.eq.5) return
  else
    !
    ! Find the box
    gtvl\change dir <greg<'explore%cbox[5]'
    greg1\draw relo ux uy /user
    @ explore_find_box 'phy_curs[1]' 'phy_curs[2]' explore%ib YES
    ib = explore%ib
  endif
  if (ib.eq.0) return
  !
  gtvl\change dir <greg
  gtvl\gtv search 'explore%cbox[ib]'
  if (.not.gtv%exist) then
    gtvl\create directory 'explore%cbox[ib]'
  else
    gtvl\clear directory 'explore%cbox[ib]'
  endif
  gtvl\change directory 'explore%cbox[ib]'
  let explore%y[ib] 'ac'[ix,iy,]
  let explore%rx[ib] ux
  let explore%ry[ib] uy
  let explore%exist[ib] yes
  !
  @ explore_box 'ib'
  @ expl_spec 'ib'
end procedure add_spectrum
!
begin procedure re_explore
  !
  ! RE_EXPLORE is called at the first time before LOOP_EXPLORE
  define chara cdo*4
  !
  ! Define the Integrated area ranges
  @ pixel_range explore '&1%dim[3]' range explore%imin explore%imax
  ! Define the displayed Spectral range
  @ pixel_range explore '&1%dim[3]' span explore%jmin explore%jmax
  if (span[1].ne.0.or.span[2].ne.0) then
    let explore%ulimit[1,3] max(explore%ulimit[1,3],span[1])
    let explore%ulimit[2,3] min(explore%ulimit[2,3],span[2])
  endif
  !
  if (pro%narg.ne.2) then
    let cdo "*"
  else
    let cdo &2
  endif
  if (explore%debug) say "Doing "'cdo'
  gtvl\change directory <greg
  !
  define integer nx ny nv ibox imin imax
  let nx &1%dim[1]
  let ny &1%dim[2]
  let nv &1%dim[3]
  define structure xy
  define structure vy
  define structure xv
  define real xy%data[nx,ny]
  define double xy%convert[3,2] vy%convert[3,2] xv%convert[3,2]
  !
  if (nv.ne.explore%size) then
    delete /var explore%x explore%y
    define real explore%x[nv] explore%y[nv,9]  /global
    let explore%size nv
  endif
  !
  let explore%x[is] (is-&1%convert[1,3])*&1%convert[3,3]+&1%convert[2,3]
  !
  ! Plot the current plane or Mean image
  if (cdo.eq."*".or.cdo.eq."I") then
    gtvl\change directory <greg
    let ibox 5
    gtvl\gtv search 'explore%cbox[ibox]'
    if (.not.gtv%exist) then
      gtvl\create directory 'explore%cbox[ibox]'
    else
      gtvl\clear directory 'explore%cbox[ibox]'
    endif
    gtvl\change directory 'explore%cbox[ibox]'
    @ explore_box 'ibox'
    !
    if (explore%mean) then
      let imin explore%imin
      let imax explore%imax
      !
      if (exist(exp_a)) delete /var exp_a
      define image exp_a * real /like &1[1] /global
      if (exist(MAP_VERSION)) then
        ! In IMAGER, there is an appropriate command
        clean\map_integrate &1 imin imax channel exp_a
      else
        ! Otherwise, use basic SIC to do the job to some reasonable extent
        let ndata imax-imin+1 /new integer
        let rval abs(&1%convert[3,3]) /new real
        COMPUTE EXP_A SUM &1[IMIN:IMAX]
        let exp_a exp_a*abs(&1%velres)
        let exp_a% &1%
        let exp_a%velres abs(exp_a%velres)*ndata
        let exp_a%freqres abs(exp_a%freqres)*ndata
        let exp_a%noise exp_a%noise*rval*sqrt(ndata)
        COMPUTE EXP_A%MIN MIN EXP_A
        COMPUTE EXP_A%MAX MAX EXP_A
      endif
      @ p_scale exp_a
      @ p_level exp_a
      let xy%data exp_a
    else
      if (cdo.eq."*") then
        @ p_scale &1
        @ p_level &1
      endif
      let xy%data &1[explore%iv]
    endif
    let xy%convert[1] &1%convert[1]
    let xy%convert[2] &1%convert[2]
    greg1\limits explore%ulimit[1,1] explore%ulimit[2,1] explore%ulimit[1,2] explore%ulimit[2,2]
    !
    greg2\rgdata xy /var
    @ expl_plot &1
  endif
  !
  ! Plot the various spectra
  if (cdo.eq."*".or.cdo.eq."S") then
    gtvl\change directory <greg
    for j 1 2 3 4 6 7 8 9
      if (explore%exist[j]) then
        gtvl\gtv search 'explore%cbox[j]'
        if (.not.gtv%exist) then
          gtvl\create directory 'explore%cbox[j]'
        else
          gtvl\clear directory 'explore%cbox[j]'
        endif
        gtvl\change directory 'explore%cbox[j]'
        @ explore_box 'j'
        !
        @ expl_spec 'j'
      endif
      !
      ! Plot here the positions
    next
  endif
  !
  ! Side display
  !
  let explore%plane max(1,min(explore%iv,&1%dim[3]))
  @ side
  @ p_side_display &1 'explore%ix' 'explore%iy' explore NO
  !
  gtvl\change dir <greg
  !
end procedure re_explore
!
begin procedure loop_explore
  define integer ibox old_iv ikx iky
  for /while .true.
    gtvl\change directory <greg
    greg1\draw relo
    ibox = 0
    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_explore
    else if (cursor_code.eq."V") then
      if (explore%mean) then
        explore%mean = no
        cursor_code = "*"
      else
        cursor_code = "I"
      endif
      ibox = 5
    else if (cursor_code.eq."M") then
      explore%mean = yes
      ibox = 5
      cursor_code = "I"
    else
      let ibox 0
      for i 1 to 9
        if ((x_pen.ge.explore%boxes[1,i]).and.(x_pen.le.explore%boxes[2,i])) then
          if ((y_pen.ge.explore%boxes[3,i]).and.(y_pen.le.explore%boxes[4,i])) then
            let ibox i
          endif
        endif
      next
      !
      ! Get the coordinates according to which box
      if (ibox.eq.5) then
        gtvl\change directory <greg<'explore%cbox[ibox]'
        greg1\draw relo * *
        !
        explore%ix = (use_curs[1]-&1%convert[2,1])/&1%convert[3,1]+&1%convert[1,1]
        ikx  = max(1,min(explore%ix,&1%dim[1]))
        explore%iy = (use_curs[2]-&1%convert[2,2])/&1%convert[3,2]+&1%convert[1,2]
        iky = max(1,min(explore%iy,&1%dim[2]))
        if (ikx.ne.explore%ix) let cursor_code "A"
        if (iky.ne.explore%iy) let cursor_code "A"
        explore%ix = ikx
        explore%iy = iky
        !
        ! Figure out the nearest box
        if (cursor_code.eq."S") then
          @ explore_find_box 'phy_curs[1]' 'phy_curs[2]' explore%ib YES
          if (explore%ib.ne.0) then
            let explore%y[explore%ib] &1[explore%ix,explore%iy,]
            let explore%rx[explore%ib] use_curs[1]
            let explore%ry[explore%ib] use_curs[2]
          else
            let cursor_code "."
          endif
        endif
      else if (ibox.ne.0) then
        if (explore%exist[ibox]) then
          if (cursor_code.eq."D") then
            explore%exist[ibox] = NO
            gtvl\clear directory <greg<'explore%cbox[ibox]'
          else
            gtvl\change directory <greg<'explore%cbox[ibox]'
            greg1\draw relo * *
            old_iv = explore%iv
            explore%iv = (use_curs[1]-&1%convert[2,3])/&1%convert[3,3]+&1%convert[1,3]
            let explore%iv max(1,explore%iv)
            let explore%iv min(explore%iv,&1%dim[3])
            let explore%velo  (explore%iv-&1%convert[1,3])*&1%velres+&1%veloff
            let explore%freq  (explore%iv-&1%convert[1,3])*&1%freqres+&1%restfre
            if (.not.explore%mean) then
              if (old_iv.ne.explore%iv) let cursor_code "*"
            endif
          endif
        else
          ibox = 0
        endif
      end if
      !
    endif
    !
    if (ibox.ne.0) then
      ! Something happened - re-draw as needed
      gtvl\change directory <greg
      @ re_explore &1 'cursor_code'
    endif
  next
end procedure loop_explore
!
begin procedure explore_find_box
  !
  ! Figure out sector
  !
  define integer ib jb kb
  define real ux uy dx dy dp dm dd ds
  let dp 0.65
  let dm 1.0-dp
  let ux &1-explore%boxes[1,5]
  let uy &2-explore%boxes[3,5]
  let dy explore%boxes[4,5]-explore%boxes[3,5]
  let dx explore%boxes[2,5]-explore%boxes[1,5]
  !
  let ib 0
  let ds 0.15
  let dd ds
  !
  for i 1 to 5
    let dp 0.5+dd
    let dm 0.5-dd
    let dd dd*2*ds
    ! Divide in 9 regions of approximately same size
    ! and go-on if in the central "region"
    if (uy.gt.dp*dy) then ! 7, 8 or 9
      if (ux.gt.dp*dx) then
        ib = 9
      else if (ux.lt.dm*dx) then
        ib = 7
      else
        ib = 8
      endif
    else if (uy.lt.dm*dy) then ! 1,3 or 9
      if (ux.gt.dp*dx) then
        ib = 3
      else if (ux.lt.dm*dx) then
        ib = 1
      else
        ib = 2
      endif
    else ! 4 or 6
      if (ux.gt.dp*dx) then
        ib = 6
      else if (ux.lt.dm*dx) then
        ib = 4
      else ! Center
        ib = 0
      endif
    endif
    if (ib.ne.0) break
  next
  !
  if (ib.eq.0) then
    ! Center : No obvious box - Take an arbitrary empty one,
    ! with preferences given according to quadrant
    define integer best[8]
    if (uy.gt.0) then
      if (ux.gt.0) then
        let best 8 6 4 2 9 7 3 1
      else
        let best 6 8 2 4 7 9 1 3
      endif
    else
      if (ux.gt.0) then
        let best 4 2 1 6  3 7 8 9
      else
        let best 6 2 3 4  9 1 8 7
      endif
    endif
    for lb /in best
      if .not.explore%exist[lb] then
        ib = lb
        break
      endif
    next
  else if explore%exist[ib]
    ! Box already occupied, find nearest empty one
    kb = 0
    for lb 1 to 7
      let jb explore%near[lb,ib]
      if (kb.ne.0) then
        continue
      else if (.not.explore%exist[jb]) then
        kb = jb
      endif
    next
    ib = kb
  endif
  !
  let &3 ib ! Return value
  if ib.ne.0 let explore%exist[ib] &4
end procedure explore_find_box
!
begin procedure help_explore
  say " "
  say "Authors: S.Guilloteau (2020)"
  say "Actions:"
  say "   Press E key: EXIT loop"
  say "   Press H key: HELP display"
  say "   Press Q key: QUIT loop"
  say "   Press V key: Plot current velocity plane"
  say "   Press M key: Plot integrated area image"
  say "   Press S key: Extract and display spectrum at position"
  say "   Press D key: Delete spectrum at position"
  say "   Press ? key: Get input parameters"
  say " "
end procedure help_explore
!
begin procedure input_explore
  @ i_explore
  @ help_explore
end procedure input_explore
!
! First time run
if ("&1".eq."?") then
  @ input_explore
else
  @ help_explore
  @ re_explore &1
  let explore%init yes
  if (goon) @ loop_explore &1
endif
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
