Blame histogram/copy.c

Packit 67cb25
/* gsl_histogram_copy.c
Packit 67cb25
 * Copyright (C) 2000  Simone Piccardi
Packit 67cb25
 *
Packit 67cb25
 * This library is free software; you can redistribute it and/or
Packit 67cb25
 * modify it under the terms of the GNU General Public License as
Packit 67cb25
 * published by the Free Software Foundation; either version 3 of the
Packit 67cb25
 * License, or (at your option) any later version.
Packit 67cb25
 *
Packit 67cb25
 * This program is distributed in the hope that it will be useful,
Packit 67cb25
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 67cb25
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 67cb25
 * General Public License for more details.
Packit 67cb25
 *
Packit 67cb25
 * You should have received a copy of the GNU General Public License along
Packit 67cb25
 * with this library; if not, write to the Free Software Foundation, Inc.,
Packit 67cb25
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 67cb25
 */
Packit 67cb25
/***************************************************************
Packit 67cb25
 *
Packit 67cb25
 * File gsl_histogram_copy.c: 
Packit 67cb25
 * Routine to copy an histogram. 
Packit 67cb25
 * Need GSL library and headers.
Packit 67cb25
 *
Packit 67cb25
 * Author: S. Piccardi
Packit 67cb25
 * Jan. 2000
Packit 67cb25
 *
Packit 67cb25
 ***************************************************************/
Packit 67cb25
#include <config.h>
Packit 67cb25
#include <stdlib.h>
Packit 67cb25
#include <gsl/gsl_errno.h>
Packit 67cb25
#include <gsl/gsl_histogram.h>
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * gsl_histogram_copy:
Packit 67cb25
 * copy the contents of an histogram into another
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
int
Packit 67cb25
gsl_histogram_memcpy (gsl_histogram * dest, const gsl_histogram * src)
Packit 67cb25
{
Packit 67cb25
  size_t n = src->n;
Packit 67cb25
  size_t i;
Packit 67cb25
Packit 67cb25
  if (dest->n != src->n)
Packit 67cb25
    {
Packit 67cb25
      GSL_ERROR ("histograms have different sizes, cannot copy",
Packit 67cb25
                 GSL_EINVAL);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  for (i = 0; i <= n; i++)
Packit 67cb25
    {
Packit 67cb25
      dest->range[i] = src->range[i];
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  for (i = 0; i < n; i++)
Packit 67cb25
    {
Packit 67cb25
      dest->bin[i] = src->bin[i];
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  return GSL_SUCCESS;
Packit 67cb25
}
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * gsl_histogram_duplicate:
Packit 67cb25
 * duplicate an histogram creating
Packit 67cb25
 * an identical new one
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
gsl_histogram *
Packit 67cb25
gsl_histogram_clone (const gsl_histogram * src)
Packit 67cb25
{
Packit 67cb25
  size_t n = src->n;
Packit 67cb25
  size_t i;
Packit 67cb25
  gsl_histogram *h;
Packit 67cb25
Packit 67cb25
  h = gsl_histogram_calloc_range (n, src->range);
Packit 67cb25
Packit 67cb25
  if (h == 0)
Packit 67cb25
    {
Packit 67cb25
      GSL_ERROR_VAL ("failed to allocate space for histogram struct",
Packit 67cb25
                        GSL_ENOMEM, 0);
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  for (i = 0; i < n; i++)
Packit 67cb25
    {
Packit 67cb25
      h->bin[i] = src->bin[i];
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  return h;
Packit 67cb25
}