1 /* PSPP - computes sample statistics.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by John Darrington <john@darrington.wattle.id.au>
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include <gsl/gsl_histogram.h>
24 #include "histogram.h"
25 #include "chart-geometry.h"
29 histogram_create(double bins, double x_min, double x_max)
34 double upper_limit, lower_limit;
36 gsl_histogram *hist = gsl_histogram_alloc(bins);
38 bin_width = chart_rounded_tick((x_max - x_min)/ bins);
39 bin_width_2 = bin_width / 2.0;
41 n = ceil( x_max / (bin_width_2) ) ;
42 if ( ! (n % 2 ) ) n++;
43 upper_limit = n * bin_width_2;
45 n = floor( x_min / (bin_width_2) ) ;
46 if ( ! (n % 2 ) ) n--;
47 lower_limit = n * bin_width_2;
49 gsl_histogram_set_ranges_uniform(hist, lower_limit, upper_limit);