Just cut and paste this kumac:
This kumac is also on neutrino in /work/fdufour/paw-tools/rebin.kumac
macro HREBIN 1='?' 2='0' 3='1' 4=' '
if [1]='?' then
message '* HREBIN ID1 ID2 [ BIN_FACTOR OPTION ]'
message ' (An ALIAS HREBIN EXE HISTOREBIN was previously defined)'
message
message ' ID1 C ''Histogram Identifier'''
message ' ID2 C ''Result histogram Identifier'''
message ' BIN_FACTOR I ''Binning factor for ID1'' D=1'
message ' OPTION C ''Option'' D='' '''
message
message ' Possible OPTION values are:'
message
message ' '' '''
message ' N Do not normalize values in Y'
message
message ' The specified channels of the 1-Dim histogram ID1 are
cumulated (rebinned)'
message ' into new bins of 1-Dim histogram ID2.'
message ' The final contents of the new bin is the average of the
original bins by '
message ' default. If the option N is given, the final contents of
the new bin is'
message ' the sum of the original bins.'
message ' Allow to combine 2, 3 or more bins into one.'
message
message ' E.g.: HREBIN 110 111 3'
message ' HREBIN 110(11:20) 111 5'
message ' HREBIN 100.slix.4 110 2 n'
message ' HREBIN 100(10.:) 100 3'
message
exitm
endif
if $hexist(1000000)=1 then
h/del 1000000
endif
H/COPY [1] 1000000
if $hexist(1000000)=0 then
message '***** ERROR in HREBIN : Histogram '//[1]//' does not exist.'
exitm -1
endif
if $hinfo(1000000,'1dhisto').ne.1 then
message '***** ERROR in HREBIN : Histogram '//[1]//' is not a 1D
Histogram.'
exitm -1
endif
XBINS=$HINFO(1000000,'XBINS')
XMIN=$HINFO(1000000,'XMIN')
XMAX=$HINFO(1000000,'XMAX')
STEPBIN=([XMAX]-[XMIN])/[XBINS]
htitle=$htitle(1000000)
BINFACT=[3]
if [binfact].le.0. then
message '***** ERROR in HREBIN : Binning factor should be greater
than 0.'
binfact=1
exitm -1
endif
if int([binfact]).ne.[binfact] then
message '***** ERROR in HREBIN : Binning factor should be an
integer.'
binfact=1
exitm -1
endif
newhist=[2]
if [newhist]=0 then
newhist=1000000
read newhist 'Result histogram Identifier'
endif
XBINS=INT([XBINS]/[BINFACT])
if [xbins].le.0 then
xbins=1
endif
ILAST=INT([XBINS]*[BINFACT])
XMAX = [XMIN]+[XBINS]*[BINFACT]*[STEPBIN]
vnum=0
repeat
vnum=[vnum]+1
rebinx='rbx'//[vnum]
rebiny='rby'//[vnum]
rebinex='rbex'//[vnum]
rebiney='rbey'//[vnum]
until
(($vexist([rebinx]).eq.0).and.($vexist([rebiny]).eq.0).and.($vexist([rebinex]).eq.0).and.($vexist([rebiney]).eq.0))
ve/create [rebinx]([xbins]) r
ve/create [rebiny]([xbins]) r
ve/create [rebinex]([xbins]) r
ve/create [rebiney]([xbins]) r
HISTO/GET/REBIN 1000000 [REBINX] [REBINY] [REBINEX] [REBINEY] [XBINS] 1
[ILAST] [4]
h/del 1000000
HISTO/CREATE/1DHISTO [NEWHIST] [HTITLE] [XBINS] [XMIN] [XMAX]
HISTO/PUT/CONTENT [NEWHIST] [REBINY]
HISTO/PUT/ERRORS [NEWHIST] [REBINEY]
vector/delete [rebinx]
vector/delete [rebiny]
vector/delete [rebinex]
vector/delete [rebiney]
return