gsl_histogram__copy.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. * gsl_histogram_copy:
  35. * copy the contents of an histogram into another
  36. */
  37. int
  38. gsl_histogram_memcpy (gsl_histogram * dest, const gsl_histogram * src)
  39. {
  40. size_t n = src->n;
  41. size_t i;
  42. if (dest->n != src->n)
  43. {
  44. GSL_ERROR ("histograms have different sizes, cannot copy",
  45. GSL_EINVAL);
  46. }
  47. for (i = 0; i <= n; i++)
  48. {
  49. dest->range[i] = src->range[i];
  50. }
  51. for (i = 0; i < n; i++)
  52. {
  53. dest->bin[i] = src->bin[i];
  54. }
  55. return GSL_SUCCESS;
  56. }
  57. /*
  58. * gsl_histogram_duplicate:
  59. * duplicate an histogram creating
  60. * an identical new one
  61. */
  62. gsl_histogram *
  63. gsl_histogram_clone (const gsl_histogram * src)
  64. {
  65. size_t n = src->n;
  66. size_t i;
  67. gsl_histogram *h;
  68. h = gsl_histogram_calloc_range (n, src->range);
  69. if (h == 0)
  70. {
  71. GSL_ERROR_VAL ("failed to allocate space for histogram struct",
  72. GSL_ENOMEM, 0);
  73. }
  74. for (i = 0; i < n; i++)
  75. {
  76. h->bin[i] = src->bin[i];
  77. }
  78. return h;
  79. }