!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
begin procedure show-segments-range
  greg1\pencil 3
  greg1\draw relo &1 user_ymin /user
  greg1\draw line &1 user_ymax /user
  greg1\draw relo &2 user_ymin /user
  greg1\draw line &2 user_ymax /user
  greg1\pencil 0
end procedure show-segments-range
!
begin procedure show-segments-log
  greg1\set axis expo y
  set\panel &1
  greg1\limits * * &5 * /xlog /ylog /var &3 &4
  greg1\box n o
  greg1\label "&2" /y 3.5
  greg1\connect &3 &4
  greg1\set axis noexpo y
end procedure show-segments-log
!
begin procedure show-segments-lin
  set\panel &1
  greg1\limits * * &5 * /xlog /var &3 &4
  greg1\box
  greg1\label "&2" /y 3.5
  greg1\connect &3 &4
end procedure show-segments-lin
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
gtvl\clear
set\panel /def /nxy 1 4 /inter 0 0
!
if exist(segments) then
   delete /var segments%i segments%total segments%mean segments%npix
else
   define structure segments /global
   define integer segments%n /global
endif
sic\compute segments%n line energy.dat
define real segments%i[segments%n] segments%total[segments%n] segments%mean[segments%n] segments%npix[segments%n] /global
accept segments%i segments%total segments%mean segments%npix /column energy.dat
!
define real totsnr
define integer iloc[2]
let totsnr 1e3
s\compute iloc location segments%total totsnr
!
define integer first last
if (pro%narg.eq.0) then
   let first 1
   let last segments%n-iloc[1]
else if (pro%narg.eq.2) then
   let first &1
   let last  &2
else
   message e show-segments "only 0 or 2 arguments are accepted"
endif
!
@ show-segments-log 1 "Number of pixels" segments%i segments%npix  1.0
@ show-segments-range 'first' 'last'
@ show-segments-log 2 "Total SNR"        segments%i segments%total 0.1
@ show-segments-range 'first' 'last'
@ show-segments-lin 3  "Mean SNR"        segments%i segments%mean  0.0
@ show-segments-range 'first' 'last'
greg1\pencil 1
greg1\draw relo user_xmin 3 /user
greg1\draw line user_xmax 3 /user
greg1\pencil 0
greg1\label "Segment number" /x
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
