summaryrefslogtreecommitdiff
path: root/gsl-1.9/doc/examples/histogram.c
diff options
context:
space:
mode:
Diffstat (limited to 'gsl-1.9/doc/examples/histogram.c')
-rw-r--r--gsl-1.9/doc/examples/histogram.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/gsl-1.9/doc/examples/histogram.c b/gsl-1.9/doc/examples/histogram.c
new file mode 100644
index 0000000..a3c5150
--- /dev/null
+++ b/gsl-1.9/doc/examples/histogram.c
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <gsl/gsl_histogram.h>
+
+int
+main (int argc, char **argv)
+{
+ double a, b;
+ size_t n;
+
+ if (argc != 4)
+ {
+ printf ("Usage: gsl-histogram xmin xmax n\n"
+ "Computes a histogram of the data "
+ "on stdin using n bins from xmin "
+ "to xmax\n");
+ exit (0);
+ }
+
+ a = atof (argv[1]);
+ b = atof (argv[2]);
+ n = atoi (argv[3]);
+
+ {
+ double x;
+ gsl_histogram * h = gsl_histogram_alloc (n);
+ gsl_histogram_set_ranges_uniform (h, a, b);
+
+ while (fscanf (stdin, "%lg", &x) == 1)
+ {
+ gsl_histogram_increment (h, x);
+ }
+ gsl_histogram_fprintf (stdout, h, "%g", "%g");
+ gsl_histogram_free (h);
+ }
+ exit (0);
+}