Blame histogram/copy2d.c

Packit 67cb25
/* gsl_histogram2d_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_histogram2d_copy.c: 
Packit 67cb25
 * Routine to copy a 2D histogram. 
Packit 67cb25
 * Need GSL library and header.
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_histogram2d.h>
Packit 67cb25
Packit 67cb25
/*
Packit 67cb25
 * gsl_histogram2d_copy:
Packit 67cb25
 * copy the contents of an histogram into another
Packit 67cb25
 */
Packit 67cb25
int
Packit 67cb25
gsl_histogram2d_memcpy (gsl_histogram2d * dest, const gsl_histogram2d * src)
Packit 67cb25
{
Packit 67cb25
  size_t nx = src->nx;
Packit 67cb25
  size_t ny = src->ny;
Packit 67cb25
  size_t i;
Packit 67cb25
  if (dest->nx != src->nx || dest->ny != src->ny)
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 <= nx; i++)
Packit 67cb25
    {
Packit 67cb25
      dest->xrange[i] = src->xrange[i];
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  for (i = 0; i <= ny; i++)
Packit 67cb25
    {
Packit 67cb25
      dest->yrange[i] = src->yrange[i];
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  for (i = 0; i < nx * ny; 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_histogram2d_duplicate:
Packit 67cb25
 * duplicate an histogram creating
Packit 67cb25
 * an identical new one
Packit 67cb25
 */
Packit 67cb25
Packit 67cb25
gsl_histogram2d *
Packit 67cb25
gsl_histogram2d_clone (const gsl_histogram2d * src)
Packit 67cb25
{
Packit 67cb25
  size_t nx = src->nx;
Packit 67cb25
  size_t ny = src->ny;
Packit 67cb25
  size_t i;
Packit 67cb25
  gsl_histogram2d *h;
Packit 67cb25
Packit 67cb25
  h = gsl_histogram2d_calloc_range (nx, ny, src->xrange, src->yrange);
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 < nx * ny; i++)
Packit 67cb25
    {
Packit 67cb25
      h->bin[i] = src->bin[i];
Packit 67cb25
    }
Packit 67cb25
Packit 67cb25
  return h;
Packit 67cb25
}