3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <gsl/gsl_errno.h>
23 #include <gsl/gsl_block.h>
24 #include <gsl/gsl_histogram.h>
27 gsl_histogram_fread (FILE * stream, gsl_histogram * h)
29 int status = gsl_block_raw_fread (stream, h->range, h->n + 1, 1);
34 status = gsl_block_raw_fread (stream, h->bin, h->n, 1);
39 gsl_histogram_fwrite (FILE * stream, const gsl_histogram * h)
41 int status = gsl_block_raw_fwrite (stream, h->range, h->n + 1, 1);
46 status = gsl_block_raw_fwrite (stream, h->bin, h->n, 1);
51 gsl_histogram_fprintf (FILE * stream, const gsl_histogram * h,
52 const char *range_format, const char *bin_format)
55 const size_t n = h->n;
57 for (i = 0; i < n; i++)
59 int status = fprintf (stream, range_format, h->range[i]);
63 GSL_ERROR ("fprintf failed", GSL_EFAILED);
66 status = putc (' ', stream);
70 GSL_ERROR ("putc failed", GSL_EFAILED);
73 status = fprintf (stream, range_format, h->range[i + 1]);
77 GSL_ERROR ("fprintf failed", GSL_EFAILED);
80 status = putc (' ', stream);
84 GSL_ERROR ("putc failed", GSL_EFAILED);
87 status = fprintf (stream, bin_format, h->bin[i]);
91 GSL_ERROR ("fprintf failed", GSL_EFAILED);
94 status = putc ('\n', stream);
98 GSL_ERROR ("putc failed", GSL_EFAILED);
106 gsl_histogram_fscanf (FILE * stream, gsl_histogram * h)
109 const size_t n = h->n;
112 for (i = 0; i < n; i++)
114 int status = fscanf (stream,
115 "%lg %lg %lg", h->range + i, &upper,
120 GSL_ERROR ("fscanf failed", GSL_EFAILED);