1 /* gsl_histogram2d_oper.c
2 * Copyright (C) 2000 Simone Piccardi
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
19 /***************************************************************
21 * File gsl_histogram2d_oper.c:
22 * Routine to make operation on 2D histograms.
23 * Need GSL library and header.
24 * Contains the routines:
25 * gsl_histogram2d_same_binning check if two histograms have the same binning
26 * gsl_histogram2d_add add two histogram
27 * gsl_histogram2d_sub subctract two histogram
28 * gsl_histogram2d_mult multiply two histogram
29 * gsl_histogram2d_div divide two histogram
30 * gsl_histogram2d_scale scale histogram contents
35 ***************************************************************/
38 #include <gsl/gsl_errno.h>
39 #include <gsl/gsl_histogram2d.h>
42 * gsl_histogram2d_same_binning:
43 * control if two histogram have the
47 gsl_histogram2d_equal_bins_p (const gsl_histogram2d * h1,
48 const gsl_histogram2d * h2)
51 if ((h1->nx != h2->nx) || (h1->ny != h2->ny))
58 for (i = 0; i <= (h1->nx); i++)
60 if (h1->xrange[i] != h2->xrange[i])
65 for (i = 0; i <= (h1->ny); i++)
67 if (h1->yrange[i] != h2->yrange[i])
77 * gsl_histogram2d_add:
82 gsl_histogram2d_add (gsl_histogram2d * h1, const gsl_histogram2d * h2)
86 if (!gsl_histogram2d_equal_bins_p (h1, h2))
88 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
91 for (i = 0; i < (h1->nx) * (h1->ny); i++)
93 h1->bin[i] += h2->bin[i];
100 * gsl_histogram2d_sub:
101 * subtract two histogram
105 gsl_histogram2d_sub (gsl_histogram2d * h1, const gsl_histogram2d * h2)
109 if (!gsl_histogram2d_equal_bins_p (h1, h2))
111 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
114 for (i = 0; i < (h1->nx) * (h1->ny); i++)
116 h1->bin[i] -= h2->bin[i];
123 * gsl_histogram2d_mult:
124 * multiply two histogram
128 gsl_histogram2d_mul (gsl_histogram2d * h1, const gsl_histogram2d * h2)
132 if (!gsl_histogram2d_equal_bins_p (h1, h2))
134 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
137 for (i = 0; i < (h1->nx) * (h1->ny); i++)
139 h1->bin[i] *= h2->bin[i];
146 * gsl_histogram2d_div:
147 * divide two histogram
151 gsl_histogram2d_div (gsl_histogram2d * h1, const gsl_histogram2d * h2)
155 if (!gsl_histogram2d_equal_bins_p (h1, h2))
157 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
160 for (i = 0; i < (h1->nx) * (h1->ny); i++)
162 h1->bin[i] /= h2->bin[i];
169 * gsl_histogram2d_scale:
170 * scale a histogram by a numeric factor
174 gsl_histogram2d_scale (gsl_histogram2d * h, double scale)
178 for (i = 0; i < (h->nx) * (h->ny); i++)
187 * gsl_histogram2d_shift:
188 * shift a histogram by a numeric offset
192 gsl_histogram2d_shift (gsl_histogram2d * h, double shift)
196 for (i = 0; i < (h->nx) * (h->ny); i++)