!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Plot Clean components at their positions with markers proportional
! to local flux
! S.Guilloteau - LAB - CNRS/U.Bordeaux
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
if (tcc%dim[1].eq.0) then
  message e "SHOW SOURCES" "No valid Clean Component"
  let mapping_error yes
  return
endif
!
if (tcc%ndim.eq.2) then
  greg1\limits /var tcc[1] tcc[2]
  greg1\set box match
  defin real fmax
  compute fmax max tcc[3]
  !
  gtvl\clear
  greg1\set mark 6 0 .5
  greg1\points tcc[1] tcc[2] /size fmax tcc[3]
  !
  greg1\box /abs
  return
endif
!
@ window_tools.greg
!
gtvl\clear directory
let PopupName "SOURCES"  ! Generic name of GTV sub-directories for POPUP
!
define integer nplanes jfirst jlast
let nplanes tcc%dim[3]
greg1\set marker 6 0 .5
!
! Make header
@ header_position
@ p_header TCC
!
! Define plotting window
!
if first.le.0 then
  let jfirst 1
else
  let jfirst min(first,nplanes)
endif
!
if last.le.0 then
  let jlast max(1,nplanes+last)
else
  let jlast min(last,nplanes)
endif
!
!
! Define the limits
define real tmax rmax
greg2\rgdata tcc /vari ! Just to get the Projection
if ((size[1].ne.0).or.(size[2].ne.0)) then
  if (size[1].eq.0) then
    greg1\limits = = (center[2]-size[2]/2) (center[2]+size[2]/2) seconds
  else if (size[2].eq.0) then
    greg1\limits (center[1]+size[1]/2) (center[1]-size[1]/2) = = seconds
  else
    greg1\limits (center[1]+size[1]/2) (center[1]-size[1]/2) (center[2]-size[2]/2) (center[2]+size[2]/2) seconds
  endif
  for iplane jfirst to jlast
    compute rmax max tcc[3,iplane]
    let tmax max(tmax,rmax)
  next
else
  greg1\limits /var tcc[1,jfirst] tcc[2,jfirst]
  compute tmax max tcc[3,jfirst]
  if (jlast.gt.jfirst) then
    for iplane jfirst+1 to jlast
      greg1\limits < > < > /var tcc[1,iplane] tcc[2,iplane]
      compute rmax max tcc[3,iplane]
      let tmax max(tmax,rmax)
    next
  endif
  limits = = = = /rev x  ! East is on left
endif
!
! Aspect ratio
define real old_aspect ratio
if (aspect_ratio).or.(aspect.eq.0) then
  let ratio abs((user_xmax-user_xmin)/(user_ymax-user_ymin))
else
  let ratio aspect
end if
!
if (ratio.lt.0.1.or.ratio.gt.10) then
   message W SHOW "box aspect ratio > 10: ignored"
   let ratio 1.0
endif
!
! Box positions
!
let old_aspect aspect
let aspect_ratio yes ! Respect aspect ratio
let aspect ratio     ! New value of aspect ratio
let fixed_trc yes    ! Top right corner is fixed
let inter 0.0 0.0    ! No interspace between individual boxes (unit: % of box sizes)
@ plot_position      ! Definition of total available plotting place
@ find_nx_ny 'jlast-jfirst+1'      ! Number of Boxes
@ window_xy 'nx_box' 'ny_box' 1 1  ! Box position
!
if (expand.eq.0) then
  let PopupExpand min(6.0/(nx_box+ny_box),1.) ! Automatic definition
else
  let PopupExpand 'expand'                    ! User defined expansion
endif
greg1\set expand 'PopupExpand'
!
! Plot
!
define integer iplane
define real fluxes['tcc%dim[1]']
!
let iplane jfirst-1
for j 1 to ny_box
  for i 1 to nx_box
    let iplane iplane+1
    if (iplane.le.jlast) then
      gtvl\create dir 'PopupName''iplane'
      gtvl\change dir 'PopupName''iplane'
      @ window_xy 'nx_box' 'ny_box' 'iplane-jfirst+1'
      let fluxes max(0,tcc[3,iplane])
      greg1\points tcc[1,iplane] tcc[2,iplane] /size tmax fluxes /blank 0 0
      greg1\pencil 1
      let fluxes -tcc[3,iplane]
      let fluxes max(fluxes,0)
      greg1\points tcc[1,iplane] tcc[2,iplane] /size tmax fluxes /blank 0 0
      greg1\pencil 0
      !
      if i.eq.1.and.(iplane+nx_box.gt.jlast) then
        @ p_box label TCC
      else
        @ p_box no TCC
      end if
      if (mark.ne."none") then
        if (exist(do_mask)) then
          if (do_mask) then
             @ p_hide 7 0.3 0.15
          end if
        end if
        @ p_mark TCC 'iplane'
      end if
      if do_fields then
        @ p_over_fields
      endif
      gtvl\change dir <greg
    endif
  next
next
!
! Plot the box
gtvl\change dir <greg
!
! Set the legend
greg1\set expand 1.0
@ p_legend X TCC
@ p_legend Y TCC
!
greg1\set expand 1.0
! Restore aspect ratio
let aspect old_aspect
! Set the Popup control
let popup%first jfirst 
let popup%last jlast
let popup%step 1
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
