Debian Codegraph @

external/gsl/gsl_histogram__copy.c

raw
1 /* gsl_histogram_copy.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_copy.c:
22 * Routine to copy an histogram.
23 * Need GSL library and headers.
24 *
25 * Author: S. Piccardi
26 * Jan. 2000
27 *
28 ***************************************************************/
29 #include "gsl__config.h"
30 #include <stdlib.h>
31 #include "gsl_errno.h"
32 #include "gsl_histogram.h"
33
34 /*
35 * gsl_histogram_copy:
36 * copy the contents of an histogram into another
37 */
38
39 int
40 gsl_histogram_memcpy (gsl_histogram * dest, const gsl_histogram * src)
41 {
42 size_t n = src->n;
43 size_t i;
44
45 if (dest->n != src->n)
46 {
47 GSL_ERROR ("histograms have different sizes, cannot copy",
48 GSL_EINVAL);
49 }
50
51 for (i = 0; i <= n; i++)
52 {
53 dest->range[i] = src->range[i];
54 }
55
56 for (i = 0; i < n; i++)
57 {
58 dest->bin[i] = src->bin[i];
59 }
60
61 return GSL_SUCCESS;
62 }
63
64 /*
65 * gsl_histogram_duplicate:
66 * duplicate an histogram creating
67 * an identical new one
68 */
69
70 gsl_histogram *
71 gsl_histogram_clone (const gsl_histogram * src)
72 {
73 size_t n = src->n;
74 size_t i;
75 gsl_histogram *h;
76
77 h = gsl_histogram_calloc_range (n, src->range);
78
79 if (h == 0)
80 {
81 GSL_ERROR_VAL ("failed to allocate space for histogram struct",
82 GSL_ENOMEM, 0);
83 }
84
85 for (i = 0; i < n; i++)
86 {
87 h->bin[i] = src->bin[i];
88 }
89
90 return h;
91 }