| 1 | /* histogram/init2d.c |
| 2 | * |
| 3 | * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 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. |
| 14 | * |
| 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 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/ |
| 21 | #include <stdlib.h> |
| 22 | #include <math.h> |
| 23 | #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/ |
| 24 | #include "gsl_histogram2d.h"cxx . . $ `<file>/external/gsl/gsl_histogram2d.h`/ |
| 25 | |
| 26 | gsl_histogram2dcxx . . $ gsl_histogram2d# * |
| 27 | gsl_histogram2d_alloccxx . . $ gsl_histogram2d_alloc(c873030ca940698f). (const size_t nx, const size_t ny) |
| 28 | { |
| 29 | gsl_histogram2dcxx . . $ gsl_histogram2d# *h; |
| 30 | |
| 31 | if (nx == 0) |
| 32 | { |
| 33 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("histogram2d length nx must be positive integer", |
| 34 | GSL_EDOM, 0); |
| 35 | } |
| 36 | |
| 37 | if (ny == 0) |
| 38 | { |
| 39 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("histogram2d length ny must be positive integer", |
| 40 | GSL_EDOM, 0); |
| 41 | } |
| 42 | |
| 43 | h = (gsl_histogram2dcxx . . $ gsl_histogram2d# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_histogram2dcxx . . $ gsl_histogram2d#)); |
| 44 | |
| 45 | if (h == 0) |
| 46 | { |
| 47 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram2d struct", |
| 48 | GSL_ENOMEM, 0); |
| 49 | } |
| 50 | |
| 51 | h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). ((nx + 1) * sizeof (double)); |
| 52 | |
| 53 | if (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange. == 0) |
| 54 | { |
| 55 | freecxx . . $ free(5d22bdacc48458e8). (h); /* exception in constructor, avoid memory leak */ |
| 56 | |
| 57 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram2d x ranges", |
| 58 | GSL_ENOMEM, 0); |
| 59 | } |
| 60 | |
| 61 | h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). ((ny + 1) * sizeof (double)); |
| 62 | |
| 63 | if (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange. == 0) |
| 64 | { |
| 65 | freecxx . . $ free(5d22bdacc48458e8). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.); |
| 66 | freecxx . . $ free(5d22bdacc48458e8). (h); /* exception in constructor, avoid memory leak */ |
| 67 | |
| 68 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram2d y ranges", |
| 69 | GSL_ENOMEM, 0); |
| 70 | } |
| 71 | |
| 72 | h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (nx * ny * sizeof (double)); |
| 73 | |
| 74 | if (h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin. == 0) |
| 75 | { |
| 76 | freecxx . . $ free(5d22bdacc48458e8). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.); |
| 77 | freecxx . . $ free(5d22bdacc48458e8). (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange.); |
| 78 | freecxx . . $ free(5d22bdacc48458e8). (h); /* exception in constructor, avoid memory leak */ |
| 79 | |
| 80 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram bins", |
| 81 | GSL_ENOMEM, 0); |
| 82 | } |
| 83 | |
| 84 | h->nxcxx . . $ $anonymous_type_2826d176da817e9d_0#nx. = nx; |
| 85 | h->nycxx . . $ $anonymous_type_2826d176da817e9d_0#ny. = ny; |
| 86 | |
| 87 | return h; |
| 88 | } |
| 89 | |
| 90 | static void |
| 91 | make_uniformcxx . . $ make_uniform(9cecc1b96ff38a8f). (double range[], size_t n, double xmin, double xmax) |
| 92 | { |
| 93 | size_t i; |
| 94 | |
| 95 | for (i = 0; i <= n; i++) |
| 96 | { |
| 97 | double f1 = ((double) (n-i) / (double) n); |
| 98 | double f2 = ((double) i / (double) n); |
| 99 | range[i] = f1 * xmin + f2 * xmax; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | gsl_histogram2dcxx . . $ gsl_histogram2d# * |
| 104 | gsl_histogram2d_calloc_uniformcxx . . $ gsl_histogram2d_calloc_uniform(c426dc57931aea72). (const size_t nx, const size_t ny, |
| 105 | const double xmin, const double xmax, |
| 106 | const double ymin, const double ymax) |
| 107 | { |
| 108 | gsl_histogram2dcxx . . $ gsl_histogram2d# *h; |
| 109 | |
| 110 | if (xmin >= xmax) |
| 111 | { |
| 112 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("xmin must be less than xmax", GSL_EINVAL, 0); |
| 113 | } |
| 114 | |
| 115 | if (ymin >= ymax) |
| 116 | { |
| 117 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("ymin must be less than ymax", GSL_EINVAL, 0); |
| 118 | } |
| 119 | |
| 120 | h = gsl_histogram2d_calloccxx . . $ gsl_histogram2d_calloc(c873030ca940698f). (nx, ny); |
| 121 | |
| 122 | if (h == 0) |
| 123 | { |
| 124 | return h; |
| 125 | } |
| 126 | |
| 127 | make_uniformcxx . . $ make_uniform(9cecc1b96ff38a8f). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange., nx, xmin, xmax); |
| 128 | make_uniformcxx . . $ make_uniform(9cecc1b96ff38a8f). (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange., ny, ymin, ymax); |
| 129 | |
| 130 | return h; |
| 131 | } |
| 132 | |
| 133 | gsl_histogram2dcxx . . $ gsl_histogram2d# * |
| 134 | gsl_histogram2d_calloccxx . . $ gsl_histogram2d_calloc(c873030ca940698f). (const size_t nx, const size_t ny) |
| 135 | { |
| 136 | gsl_histogram2dcxx . . $ gsl_histogram2d# *h; |
| 137 | |
| 138 | if (nx == 0) |
| 139 | { |
| 140 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("histogram2d length nx must be positive integer", |
| 141 | GSL_EDOM, 0); |
| 142 | } |
| 143 | |
| 144 | if (ny == 0) |
| 145 | { |
| 146 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("histogram2d length ny must be positive integer", |
| 147 | GSL_EDOM, 0); |
| 148 | } |
| 149 | |
| 150 | h = (gsl_histogram2dcxx . . $ gsl_histogram2d# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_histogram2dcxx . . $ gsl_histogram2d#)); |
| 151 | |
| 152 | if (h == 0) |
| 153 | { |
| 154 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram2d struct", |
| 155 | GSL_ENOMEM, 0); |
| 156 | } |
| 157 | |
| 158 | h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). ((nx + 1) * sizeof (double)); |
| 159 | |
| 160 | if (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange. == 0) |
| 161 | { |
| 162 | freecxx . . $ free(5d22bdacc48458e8). (h); /* exception in constructor, avoid memory leak */ |
| 163 | |
| 164 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram2d x ranges", |
| 165 | GSL_ENOMEM, 0); |
| 166 | } |
| 167 | |
| 168 | h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). ((ny + 1) * sizeof (double)); |
| 169 | |
| 170 | if (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange. == 0) |
| 171 | { |
| 172 | freecxx . . $ free(5d22bdacc48458e8). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.); |
| 173 | freecxx . . $ free(5d22bdacc48458e8). (h); /* exception in constructor, avoid memory leak */ |
| 174 | |
| 175 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram2d y ranges", |
| 176 | GSL_ENOMEM, 0); |
| 177 | } |
| 178 | |
| 179 | h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (nx * ny * sizeof (double)); |
| 180 | |
| 181 | if (h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin. == 0) |
| 182 | { |
| 183 | freecxx . . $ free(5d22bdacc48458e8). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.); |
| 184 | freecxx . . $ free(5d22bdacc48458e8). (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange.); |
| 185 | freecxx . . $ free(5d22bdacc48458e8). (h); /* exception in constructor, avoid memory leak */ |
| 186 | |
| 187 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram bins", |
| 188 | GSL_ENOMEM, 0); |
| 189 | } |
| 190 | |
| 191 | { |
| 192 | size_t i; |
| 193 | |
| 194 | for (i = 0; i < nx + 1; i++) |
| 195 | { |
| 196 | h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.[i] = i; |
| 197 | } |
| 198 | |
| 199 | for (i = 0; i < ny + 1; i++) |
| 200 | { |
| 201 | h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange.[i] = i; |
| 202 | } |
| 203 | |
| 204 | for (i = 0; i < nx * ny; i++) |
| 205 | { |
| 206 | h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin.[i] = 0; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | h->nxcxx . . $ $anonymous_type_2826d176da817e9d_0#nx. = nx; |
| 211 | h->nycxx . . $ $anonymous_type_2826d176da817e9d_0#ny. = ny; |
| 212 | |
| 213 | return h; |
| 214 | } |
| 215 | |
| 216 | |
| 217 | void |
| 218 | gsl_histogram2d_freecxx . . $ gsl_histogram2d_free(7679315a85183d5d). (gsl_histogram2dcxx . . $ gsl_histogram2d# * h) |
| 219 | { |
| 220 | freecxx . . $ free(5d22bdacc48458e8). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.); |
| 221 | freecxx . . $ free(5d22bdacc48458e8). (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange.); |
| 222 | freecxx . . $ free(5d22bdacc48458e8). (h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin.); |
| 223 | freecxx . . $ free(5d22bdacc48458e8). (h); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | int |
| 228 | gsl_histogram2d_set_ranges_uniformcxx . . $ gsl_histogram2d_set_ranges_uniform(8f9a5772f76d81a5). (gsl_histogram2dcxx . . $ gsl_histogram2d# * h, |
| 229 | double xmin, double xmax, |
| 230 | double ymin, double ymax) |
| 231 | { |
| 232 | size_t i; |
| 233 | const size_t nx = h->nxcxx . . $ $anonymous_type_2826d176da817e9d_0#nx., ny = h->nycxx . . $ $anonymous_type_2826d176da817e9d_0#ny.; |
| 234 | |
| 235 | if (xmin >= xmax) |
| 236 | { |
| 237 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("xmin must be less than xmax", GSL_EINVAL, 0); |
| 238 | } |
| 239 | |
| 240 | if (ymin >= ymax) |
| 241 | { |
| 242 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("ymin must be less than ymax", GSL_EINVAL, 0); |
| 243 | } |
| 244 | |
| 245 | /* initialize ranges */ |
| 246 | |
| 247 | make_uniformcxx . . $ make_uniform(9cecc1b96ff38a8f). (h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange., nx, xmin, xmax); |
| 248 | make_uniformcxx . . $ make_uniform(9cecc1b96ff38a8f). (h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange., ny, ymin, ymax); |
| 249 | |
| 250 | /* clear contents */ |
| 251 | |
| 252 | for (i = 0; i < nx * ny; i++) |
| 253 | { |
| 254 | h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin.[i] = 0; |
| 255 | } |
| 256 | |
| 257 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 258 | } |
| 259 | |
| 260 | int |
| 261 | gsl_histogram2d_set_rangescxx . . $ gsl_histogram2d_set_ranges(3dbb1d52ffa9e1ab). (gsl_histogram2dcxx . . $ gsl_histogram2d# * h, |
| 262 | const double xrange[], size_t xsize, |
| 263 | const double yrange[], size_t ysize) |
| 264 | { |
| 265 | size_t i; |
| 266 | const size_t nx = h->nxcxx . . $ $anonymous_type_2826d176da817e9d_0#nx., ny = h->nycxx . . $ $anonymous_type_2826d176da817e9d_0#ny.; |
| 267 | |
| 268 | if (xsize != (nx + 1)) |
| 269 | { |
| 270 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("size of xrange must match size of histogram", |
| 271 | GSL_EINVAL, 0); |
| 272 | } |
| 273 | |
| 274 | if (ysize != (ny + 1)) |
| 275 | { |
| 276 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("size of yrange must match size of histogram", |
| 277 | GSL_EINVAL, 0); |
| 278 | } |
| 279 | |
| 280 | /* initialize ranges */ |
| 281 | |
| 282 | for (i = 0; i <= nx; i++) |
| 283 | { |
| 284 | h->xrangecxx . . $ $anonymous_type_2826d176da817e9d_0#xrange.[i] = xrange[i]; |
| 285 | } |
| 286 | |
| 287 | for (i = 0; i <= ny; i++) |
| 288 | { |
| 289 | h->yrangecxx . . $ $anonymous_type_2826d176da817e9d_0#yrange.[i] = yrange[i]; |
| 290 | } |
| 291 | |
| 292 | /* clear contents */ |
| 293 | |
| 294 | for (i = 0; i < nx * ny; i++) |
| 295 | { |
| 296 | h->bincxx . . $ $anonymous_type_2826d176da817e9d_0#bin.[i] = 0; |
| 297 | } |
| 298 | |
| 299 | return GSL_SUCCESScxx . . $ GSL_SUCCESS.; |
| 300 | } |