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_histogram2d.h>
27 gsl_histogram2d_fread (FILE * stream, gsl_histogram2d * h)
29 int status = gsl_block_raw_fread (stream, h->xrange, h->nx + 1, 1);
34 status = gsl_block_raw_fread (stream, h->yrange, h->ny + 1, 1);
39 status = gsl_block_raw_fread (stream, h->bin, h->nx * h->ny, 1);
45 gsl_histogram2d_fwrite (FILE * stream, const gsl_histogram2d * h)
47 int status = gsl_block_raw_fwrite (stream, h->xrange, h->nx + 1, 1);
52 status = gsl_block_raw_fwrite (stream, h->yrange, h->ny + 1, 1);
57 status = gsl_block_raw_fwrite (stream, h->bin, h->nx * h->ny, 1);
62 gsl_histogram2d_fprintf (FILE * stream, const gsl_histogram2d * h,
63 const char *range_format, const char *bin_format)
66 const size_t nx = h->nx;
67 const size_t ny = h->ny;
70 for (i = 0; i < nx; i++)
72 for (j = 0; j < ny; j++)
74 status = fprintf (stream, range_format, h->xrange[i]);
78 GSL_ERROR ("fprintf failed", GSL_EFAILED);
81 status = putc (' ', stream);
85 GSL_ERROR ("putc failed", GSL_EFAILED);
88 status = fprintf (stream, range_format, h->xrange[i + 1]);
92 GSL_ERROR ("fprintf failed", GSL_EFAILED);
95 status = putc (' ', stream);
99 GSL_ERROR ("putc failed", GSL_EFAILED);
102 status = fprintf (stream, range_format, h->yrange[j]);
106 GSL_ERROR ("fprintf failed", GSL_EFAILED);
109 status = putc (' ', stream);
113 GSL_ERROR ("putc failed", GSL_EFAILED);
116 status = fprintf (stream, range_format, h->yrange[j + 1]);
120 GSL_ERROR ("fprintf failed", GSL_EFAILED);
123 status = putc (' ', stream);
127 GSL_ERROR ("putc failed", GSL_EFAILED);
130 status = fprintf (stream, bin_format, h->bin[i * ny + j]);
134 GSL_ERROR ("fprintf failed", GSL_EFAILED);
137 status = putc ('\n', stream);
141 GSL_ERROR ("putc failed", GSL_EFAILED);
144 status = putc ('\n', stream);
148 GSL_ERROR ("putc failed", GSL_EFAILED);
156 gsl_histogram2d_fscanf (FILE * stream, gsl_histogram2d * h)
159 const size_t nx = h->nx;
160 const size_t ny = h->ny;
161 double xupper, yupper;
163 for (i = 0; i < nx; i++)
165 for (j = 0; j < ny; j++)
167 int status = fscanf (stream,
168 "%lg %lg %lg %lg %lg",
169 h->xrange + i, &xupper,
170 h->yrange + j, &yupper,
171 h->bin + i * ny + j);
175 GSL_ERROR ("fscanf failed", GSL_EFAILED);
178 h->yrange[ny] = yupper;
181 h->xrange[nx] = xupper;