!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Plot cumulative flux as a function of the number of components.
! Single Frame plot, totally re-written for IMAGER, but
! in principle backward compatible with Mapping.
!
!   S. Guilloteau
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
greg1\set expand 1.0
@ window_tools.greg
!
gtvl\clear directory
!
if exist(comp) then
  delete /var comp
endif
!
define integer mcomp ncomp nplanes
define integer ucomp jfirst jlast
define logical lut_static
let ucomp &2+1
!
if (.not.exist(CCT_FLUX)) then
  @ p_cct_flux &1
endif
let ncomp size(cct_flux,1)
let nplanes size(cct_flux,2)
exa ncomp
!
! Compute the limit
!
define real comp[ncomp] /global
let comp[i] i-1
@ xy_limits comp cct_flux
!
! 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
!
@ plot_position
@ find_nx_ny 1
@ window_xy 1 1 1 1
greg1\set box box_xmin box_xmax box_ymin box_ymax-2.5
!
! Plot
!
greg1\pencil /col 16
define real n m o
let n size(lut%hue)
let lut%hue[i] i*256./n
let m int((n+1)/2)
let o n/8
let lut%value 1
let lut%value[i] min(1,abs(i-m)/o)
let lut%saturation 1
!
let lut%pen%saturation 1
gtvl\lut
if (.not.lut%static) then
  change lut static
  let lut_static no
else
  let lut_static yes
endif
gtvl\lut /pen
!
for iplane jfirst to jlast
  let lut%pen%value min(abs(iplane-(jfirst+jlast)/2)*8/(jlast-jfirst),1.0)
  let lut%pen%hue  (iplane-jfirst)/(jlast-jfirst)*256
  gtvl\lut /pen
  !
  let mcomp cct_ncomp[iplane]
  if (ucomp.ne.1) then
    let mcomp min(ucomp,mcomp)
  endif
  if (mcomp.gt.1) then
    greg1\connect comp[1:mcomp] cct_flux[1:mcomp,iplane]
  else
    greg1\draw relo 0 0 /user
    greg1\draw line 1 0 /user
  endif
  if lut%pen%saturation[1].ne.1 then
    SAY "W-VIEW, bug after CONNECT "'iplane'" "'mcomp'", reset LUT%PEN%SATURATION"
    let lut%pen%saturation 1
  endif
next
greg1\pencil /colour 0
!
define real vmin vmax
let vmin (jfirst-cct%convert[1,2])*cct%velres+cct%veloff
let vmax (jlast-cct%convert[1,2])*cct%velres+cct%veloff
greg2\wedge top /scaling lin vmin vmax
greg1\draw text 0 2.0 "Velocity (km/s)" 5 0 /box 8
!
greg1\box
greg1\label "Clean component number" /x
greg1\label "Cumulated flux (Jy)"    /y
!
! Make header
!
@ header_position
@ p_header &1
!
! Reset the LUT to Dynamic if needed
if lut_static return
define alias lf lut%static
let lf /status write
let lf NO
delet /var lf ! It is a Global alias


!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
