| 1 | /* gsl_histogram_calloc_range.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_histogram_calloc_range.c: |
| 22 | * Routine to create a variable binning histogram providing |
| 23 | * an input range vector. Need GSL library and header. |
| 24 | * Do range check and allocate the histogram data. |
| 25 | * |
| 26 | * Author: S. Piccardi |
| 27 | * Jan. 2000 |
| 28 | * |
| 29 | ***************************************************************/ |
| 30 | #include "gsl__config.h"cxx . . $ `<file>/external/gsl/gsl__config.h`/ |
| 31 | #include <stdlib.h> |
| 32 | #include "gsl_errno.h"cxx . . $ `<file>/external/gsl/gsl_errno.h`/ |
| 33 | #include "gsl_histogram.h"cxx . . $ `<file>/external/gsl/gsl_histogram.h`/ |
| 34 | |
| 35 | gsl_histogramcxx . . $ gsl_histogram# * |
| 36 | gsl_histogram_calloc_rangecxx . . $ gsl_histogram_calloc_range(98e2faa2470dfbe3). (size_t n, double *range) |
| 37 | { |
| 38 | size_t i; |
| 39 | gsl_histogramcxx . . $ gsl_histogram# *h; |
| 40 | |
| 41 | /* check arguments */ |
| 42 | |
| 43 | if (n == 0) |
| 44 | { |
| 45 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("histogram length n must be positive integer", |
| 46 | GSL_EDOM, 0); |
| 47 | } |
| 48 | |
| 49 | /* check ranges */ |
| 50 | |
| 51 | for (i = 0; i < n; i++) |
| 52 | { |
| 53 | if (range[i] >= range[i + 1]) |
| 54 | { |
| 55 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("histogram bin extremes must be " |
| 56 | "in increasing order", GSL_EDOM, 0); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /* Allocate histogram */ |
| 61 | |
| 62 | h = (gsl_histogramcxx . . $ gsl_histogram# *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (sizeof (gsl_histogramcxx . . $ gsl_histogram#)); |
| 63 | |
| 64 | if (h == 0) |
| 65 | { |
| 66 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram struct", |
| 67 | GSL_ENOMEM, 0); |
| 68 | } |
| 69 | |
| 70 | h->rangecxx . . $ $anonymous_type_62a17a7d119001a7_0#range. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). ((n + 1) * sizeof (double)); |
| 71 | |
| 72 | if (h->rangecxx . . $ $anonymous_type_62a17a7d119001a7_0#range. == 0) |
| 73 | { |
| 74 | /* exception in constructor, avoid memory leak */ |
| 75 | freecxx . . $ free(5d22bdacc48458e8). (h); |
| 76 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram ranges", |
| 77 | GSL_ENOMEM, 0); |
| 78 | } |
| 79 | |
| 80 | h->bincxx . . $ $anonymous_type_62a17a7d119001a7_0#bin. = (double *) malloccxx . . $ malloc(bfcfa4d6b7f7ef64). (n * sizeof (double)); |
| 81 | |
| 82 | if (h->bincxx . . $ $anonymous_type_62a17a7d119001a7_0#bin. == 0) |
| 83 | { |
| 84 | /* exception in constructor, avoid memory leak */ |
| 85 | freecxx . . $ free(5d22bdacc48458e8). (h->rangecxx . . $ $anonymous_type_62a17a7d119001a7_0#range.); |
| 86 | freecxx . . $ free(5d22bdacc48458e8). (h); |
| 87 | GSL_ERROR_VALcxx . . $ `external/gsl/gsl_errno.h:112:9`! ("failed to allocate space for histogram bins", |
| 88 | GSL_ENOMEM, 0); |
| 89 | } |
| 90 | |
| 91 | /* initialize ranges */ |
| 92 | |
| 93 | for (i = 0; i <= n; i++) |
| 94 | { |
| 95 | h->rangecxx . . $ $anonymous_type_62a17a7d119001a7_0#range.[i] = range[i]; |
| 96 | } |
| 97 | |
| 98 | /* clear contents */ |
| 99 | |
| 100 | for (i = 0; i < n; i++) |
| 101 | { |
| 102 | h->bincxx . . $ $anonymous_type_62a17a7d119001a7_0#bin.[i] = 0; |
| 103 | } |
| 104 | |
| 105 | h->ncxx . . $ $anonymous_type_62a17a7d119001a7_0#n. = n; |
| 106 | |
| 107 | return h; |
| 108 | } |