!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! @ c-old-histo.cube
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Define recovery behavior
on error return base
!
go\oldload 'name'  /syntax hgdf /in aaa1
@ l-old-prange.cube aaa1 center size
@ l-old-vrange.cube aaa1 range true%vrange
@ l-old-corner.cube aaa1
@ l-old-scale.cube aaa1
!
! Compute histogram
!
if exist(true%histo) then
   delete /var true%histo
endif
define structure true%histo /global
define double true%histo%raw[do%nbin,2] /global
define double true%histo%cum[do%nbin,2] /global
define double raw[do%nbin,2]
!
if (aaa1%ndim.le.2) then
   sic\compute true%histo%raw histogram aaa1['true%blc[1]':'true%trc[1]','true%blc[2]':'true%trc[2]'] 'true%scale[1]' 'true%scale[2]'
   sic\compute raw histogram aaa1['true%blc[1]':'true%trc[1]','true%blc[2]':'true%trc[2]'] 
else if (aaa1%ndim.eq.3) then
   @ l-old-vrange.cube aaa1 range true%vrange
   sic\compute true%histo%raw histogram aaa1['true%blc[1]':'true%trc[1]','true%blc[2]':'true%trc[2]','true%blc[3]':'true%trc[3]'] 'true%scale[1]' 'true%scale[2]'
   sic\compute raw histogram aaa1['true%blc[1]':'true%trc[1]','true%blc[2]':'true%trc[2]','true%blc[3]':'true%trc[3]']
else 
   message e histo "Maximum number of dimensions allowed: 3"
   return base
endif
! Convert to field-of-view percentage: normalization does not take blanking values into account on purpose.
define double normalization
sic\compute normalization sum raw[1]
if (normalization.ne.0) then
   let true%histo%raw[1] 100*true%histo%raw[1]/normalization
else
   message e histo "No valid point in histogram"
   return base
endif
! Accumulate
define double cumul
let cumul 0
let true%histo%cum[2] true%histo%raw[2]
for ibin do%nbin to 1 by -1
   let cumul cumul+true%histo%raw[ibin,1]
   let true%histo%cum[ibin,1] cumul
next ibin
delete /var cumul
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
