gsl_histogram__copy2d.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "gsl__config.h"
  30. #include <stdlib.h>
  31. #include "gsl_errno.h"
  32. #include "gsl_histogram2d.h"
  33. /*
  34. * gsl_histogram2d_copy:
  35. * copy the contents of an histogram into another
  36. */
  37. int
  38. gsl_histogram2d_memcpy (gsl_histogram2d * dest, const gsl_histogram2d * src)
  39. {
  40. size_t nx = src->nx;
  41. size_t ny = src->ny;
  42. size_t i;
  43. if (dest->nx != src->nx || dest->ny != src->ny)
  44. {
  45. GSL_ERROR ("histograms have different sizes, cannot copy",
  46. GSL_EINVAL);
  47. }
  48. for (i = 0; i <= nx; i++)
  49. {
  50. dest->xrange[i] = src->xrange[i];
  51. }
  52. for (i = 0; i <= ny; i++)
  53. {
  54. dest->yrange[i] = src->yrange[i];
  55. }
  56. for (i = 0; i < nx * ny; i++)
  57. {
  58. dest->bin[i] = src->bin[i];
  59. }
  60. return GSL_SUCCESS;
  61. }
  62. /*
  63. * gsl_histogram2d_duplicate:
  64. * duplicate an histogram creating
  65. * an identical new one
  66. */
  67. gsl_histogram2d *
  68. gsl_histogram2d_clone (const gsl_histogram2d * src)
  69. {
  70. size_t nx = src->nx;
  71. size_t ny = src->ny;
  72. size_t i;
  73. gsl_histogram2d *h;
  74. h = gsl_histogram2d_calloc_range (nx, ny, src->xrange, src->yrange);
  75. if (h == 0)
  76. {
  77. GSL_ERROR_VAL ("failed to allocate space for histogram struct",
  78. GSL_ENOMEM, 0);
  79. }
  80. for (i = 0; i < nx * ny; i++)
  81. {
  82. h->bin[i] = src->bin[i];
  83. }
  84. return h;
  85. }