*
*  HISTBINS.SRC
*    Computes and graphs histogram for a single series
*
*  Note: Must do an ALLOCATE before sourcing in the procedure
*  Syntax:
*   @HIST(option) series
*
*  Option:
*    NBAR=number of "bars" in the histogram
*
procedure histbins series
type series series
option integer nbar 10
local real increment low high minvalue
local series counts value counts tmp
local string nik

/*
**  Figure out the starting value and increment
*/

compute minvalue = %minvalue(series)
compute increment = 1.01 * ( %maxvalue(series) - minvalue ) / nbar
set counts 1 nbar = 0.0
set value 1 nbar = 0.0
disp 'Histogram for series:' %label(series)
disp 'bar   ' '     low   ' '    high  ' '    counts'
do ibar = 1, nbar
    compute low = minvalue + (ibar-1.0) * increment
    compute high = low + increment
 *   disp ibar low high
    set tmp = (series.ge.low .and. series.lt.high)
    stats(noprint) tmp /
    compute value(ibar) = (low + high) / 2.0
    compute counts(ibar) = %mean * %nobs
    disp ## ibar low high  '   ' # counts(ibar)
end do
disp
disp(store=nik) %label(series)
graph(style=bar,key=upr,klabel=||nik||,header='Histogram') 1
# counts / 2
end


* modified, 5 Nov 99, by Nick Kanellopoulos: added series names, display of counts for each bar, bar numbers


