Debian Codegraph @

external/gsl/gsl_histogram__oper2d.c

raw symbols SCIP
1 /* gsl_histogram2d_oper.c
2 * Copyright (C) 2000 Simone Piccardi
3 *
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.
8 *
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.
13 *
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.
18 */
19 /***************************************************************
20 *
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
31 *
32 * Author: S. Piccardi
33 * Jan. 2000
34 *
35 ***************************************************************/
36 #include "gsl__config.h"
37 #include <stdlib.h>
38 #include "gsl_errno.h"
39 #include "gsl_histogram2d.h"
40
41 /*
42 * gsl_histogram2d_same_binning:
43 * control if two histogram have the
44 * same binning
45 */
46 int
47 gsl_histogram2d_equal_bins_p (const gsl_histogram2d * h1,
48 const gsl_histogram2d * h2)
49 {
50
51 if ((h1->nx != h2->nx) || (h1->ny != h2->ny))
52 {
53 return 0;
54 }
55 {
56 size_t i;
57 /* init ranges */
58 for (i = 0; i <= (h1->nx); i++)
59 {
60 if (h1->xrange[i] != h2->xrange[i])
61 {
62 return 0;
63 }
64 }
65 for (i = 0; i <= (h1->ny); i++)
66 {
67 if (h1->yrange[i] != h2->yrange[i])
68 {
69 return 0;
70 }
71 }
72 }
73 return 1;
74 }
75
76 /*
77 * gsl_histogram2d_add:
78 * add two histogram
79 */
80
81 int
82 gsl_histogram2d_add (gsl_histogram2d * h1, const gsl_histogram2d * h2)
83 {
84 size_t i;
85
86 if (!gsl_histogram2d_equal_bins_p (h1, h2))
87 {
88 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
89 }
90
91 for (i = 0; i < (h1->nx) * (h1->ny); i++)
92 {
93 h1->bin[i] += h2->bin[i];
94 }
95
96 return GSL_SUCCESS;
97 }
98
99 /*
100 * gsl_histogram2d_sub:
101 * subtract two histogram
102 */
103
104 int
105 gsl_histogram2d_sub (gsl_histogram2d * h1, const gsl_histogram2d * h2)
106 {
107 size_t i;
108
109 if (!gsl_histogram2d_equal_bins_p (h1, h2))
110 {
111 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
112 }
113
114 for (i = 0; i < (h1->nx) * (h1->ny); i++)
115 {
116 h1->bin[i] -= h2->bin[i];
117 }
118
119 return GSL_SUCCESS;
120 }
121
122 /*
123 * gsl_histogram2d_mult:
124 * multiply two histogram
125 */
126
127 int
128 gsl_histogram2d_mul (gsl_histogram2d * h1, const gsl_histogram2d * h2)
129 {
130 size_t i;
131
132 if (!gsl_histogram2d_equal_bins_p (h1, h2))
133 {
134 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
135 }
136
137 for (i = 0; i < (h1->nx) * (h1->ny); i++)
138 {
139 h1->bin[i] *= h2->bin[i];
140 }
141
142 return GSL_SUCCESS;
143 }
144
145 /*
146 * gsl_histogram2d_div:
147 * divide two histogram
148 */
149
150 int
151 gsl_histogram2d_div (gsl_histogram2d * h1, const gsl_histogram2d * h2)
152 {
153 size_t i;
154
155 if (!gsl_histogram2d_equal_bins_p (h1, h2))
156 {
157 GSL_ERROR ("histograms have different binning", GSL_EINVAL);
158 }
159
160 for (i = 0; i < (h1->nx) * (h1->ny); i++)
161 {
162 h1->bin[i] /= h2->bin[i];
163 }
164
165 return GSL_SUCCESS;
166 }
167
168 /*
169 * gsl_histogram2d_scale:
170 * scale a histogram by a numeric factor
171 */
172
173 int
174 gsl_histogram2d_scale (gsl_histogram2d * h, double scale)
175 {
176 size_t i;
177
178 for (i = 0; i < (h->nx) * (h->ny); i++)
179 {
180 h->bin[i] *= scale;
181 }
182
183 return GSL_SUCCESS;
184 }
185
186 /*
187 * gsl_histogram2d_shift:
188 * shift a histogram by a numeric offset
189 */
190
191 int
192 gsl_histogram2d_shift (gsl_histogram2d * h, double shift)
193 {
194 size_t i;
195
196 for (i = 0; i < (h->nx) * (h->ny); i++)
197 {
198 h->bin[i] += shift;
199 }
200
201 return GSL_SUCCESS;
202 }
203