!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Plot cumulative flux as a function of the number of components.
! Single Frame plot
! S. Guilloteau & J. Pety
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
@ window_tools.greg
!
gtvl\clear directory
!
if exist(comp) then
  delete /var comp
endif
if exist(cflux) then
  delete /var cflux
endif
define integer ncomp nplanes
define integer ucomp jfirst jlast
let ucomp &3+0
!
if (&2%unit2.eq."COMPONENT") then
  let ncomp &2%dim[2]
  let nplanes &2%dim[3]
  SAY 'Nplanes'" planes with "'ncomp'" components"
  define real comp[ncomp] cflux[ncomp,nplanes] /global
  define real cvalue[ncomp,nplanes]
  define integer k
  !
  for iplane 1 to nplanes
    let cvalue[iplane] &2[3,,iplane]
    sic\compute cflux[iplane] integral cvalue[iplane]
  next
else
  let ncomp &2%dim[3]
  let nplanes &2%dim[2]
  define real comp[ncomp] cflux[ncomp,nplanes] /global
  define real cvalue[ncomp,nplanes]
  define integer k
  !
  for iplane 1 to nplanes
    let cvalue[iplane] &2[3,iplane,]
    sic\compute cflux[iplane] integral cvalue[iplane]
  next
endif
!
if ucomp.eq.0 then
  define real lcomp[ncomp]
  for iplane 1 to nplanes
    let lcomp[icomp] icomp
    let lcomp 0 /where cvalue[iplane].eq.0
    let comp max(comp,lcomp)
  next
else
  let comp ucomp
  let comp[1] 1
endif
!
! Compute the limit
!
@ xy_limits comp cflux
!
! 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
!
! Plot
!
define real mcomp
for iplane jfirst to jlast
  let comp[icomp] icomp
  let comp 0 /where cvalue[iplane].eq.0
  sic\compute mcomp max comp
  if (ucomp.ne.0) then
    let mcomp min(ucomp,mcomp)
  endif
  if (mcomp.gt.0) then
    greg1\connect comp[1:mcomp] cflux[1:mcomp,iplane]
  endif
next
greg1\box
greg1\label "Clean component number" /x
greg1\label "Cumulated flux (Jy)"    /y
!
! Make header
!
@ header_position
@ p_header.greg &2
!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
