Added MACS source
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / doc / examples / histogram2d.c
1 #include <stdio.h>
2 #include <gsl/gsl_rng.h>
3 #include <gsl/gsl_histogram2d.h>
4
5 int
6 main (void)
7 {
8   const gsl_rng_type * T;
9   gsl_rng * r;
10
11   gsl_histogram2d * h = gsl_histogram2d_alloc (10, 10);
12
13   gsl_histogram2d_set_ranges_uniform (h, 
14                                       0.0, 1.0,
15                                       0.0, 1.0);
16
17   gsl_histogram2d_accumulate (h, 0.3, 0.3, 1);
18   gsl_histogram2d_accumulate (h, 0.8, 0.1, 5);
19   gsl_histogram2d_accumulate (h, 0.7, 0.9, 0.5);
20
21   gsl_rng_env_setup ();
22   
23   T = gsl_rng_default;
24   r = gsl_rng_alloc (T);
25
26   {
27     int i;
28     gsl_histogram2d_pdf * p 
29       = gsl_histogram2d_pdf_alloc (h->nx, h->ny);
30     
31     gsl_histogram2d_pdf_init (p, h);
32
33     for (i = 0; i < 1000; i++) {
34       double x, y;
35       double u = gsl_rng_uniform (r);
36       double v = gsl_rng_uniform (r);
37        
38       gsl_histogram2d_pdf_sample (p, u, v, &x, &y);
39       
40       printf ("%g %g\n", x, y);
41     }
42
43     gsl_histogram2d_pdf_free (p);
44   }
45
46   gsl_histogram2d_free (h);
47   gsl_rng_free (r);
48
49   return 0;
50 }