Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / histogram / copy2d.c
1 /* gsl_histogram2d_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_histogram2d_copy.c: 
22  * Routine to copy a 2D histogram. 
23  * Need GSL library and header.
24  *
25  * Author: S. Piccardi
26  * Jan. 2000
27  *
28  ***************************************************************/
29 #include <config.h>
30 #include <stdlib.h>
31 #include <gsl/gsl_errno.h>
32 #include <gsl/gsl_histogram2d.h>
33
34 /*
35  * gsl_histogram2d_copy:
36  * copy the contents of an histogram into another
37  */
38 int
39 gsl_histogram2d_memcpy (gsl_histogram2d * dest, const gsl_histogram2d * src)
40 {
41   size_t nx = src->nx;
42   size_t ny = src->ny;
43   size_t i;
44   if (dest->nx != src->nx || dest->ny != src->ny)
45     {
46       GSL_ERROR ("histograms have different sizes, cannot copy",
47                  GSL_EINVAL);
48     }
49   
50   for (i = 0; i <= nx; i++)
51     {
52       dest->xrange[i] = src->xrange[i];
53     }
54
55   for (i = 0; i <= ny; i++)
56     {
57       dest->yrange[i] = src->yrange[i];
58     }
59
60   for (i = 0; i < nx * ny; i++)
61     {
62       dest->bin[i] = src->bin[i];
63     }
64
65   return GSL_SUCCESS;
66 }
67
68 /*
69  * gsl_histogram2d_duplicate:
70  * duplicate an histogram creating
71  * an identical new one
72  */
73
74 gsl_histogram2d *
75 gsl_histogram2d_clone (const gsl_histogram2d * src)
76 {
77   size_t nx = src->nx;
78   size_t ny = src->ny;
79   size_t i;
80   gsl_histogram2d *h;
81
82   h = gsl_histogram2d_calloc_range (nx, ny, src->xrange, src->yrange);
83
84   if (h == 0)
85     {
86       GSL_ERROR_VAL ("failed to allocate space for histogram struct",
87                         GSL_ENOMEM, 0);
88     }
89
90   for (i = 0; i < nx * ny; i++)
91     {
92       h->bin[i] = src->bin[i];
93     }
94
95   return h;
96 }