Debian Codegraph @

external/gsl/gsl_histogram__file2d.c

raw symbols SCIP
1 /* histogram/file2d.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #include "gsl__config.h"
21 #include <stdio.h>
22 #include "gsl_errno.h"
23 #include "gsl_block.h"
24 #include "gsl_histogram2d.h"
25
26 int
27 gsl_histogram2d_fread (FILE * stream, gsl_histogram2d * h)
28 {
29 int status = gsl_block_raw_fread (stream, h->xrange, h->nx + 1, 1);
30
31 if (status)
32 return status;
33
34 status = gsl_block_raw_fread (stream, h->yrange, h->ny + 1, 1);
35
36 if (status)
37 return status;
38
39 status = gsl_block_raw_fread (stream, h->bin, h->nx * h->ny, 1);
40
41 return status;
42 }
43
44 int
45 gsl_histogram2d_fwrite (FILE * stream, const gsl_histogram2d * h)
46 {
47 int status = gsl_block_raw_fwrite (stream, h->xrange, h->nx + 1, 1);
48
49 if (status)
50 return status;
51
52 status = gsl_block_raw_fwrite (stream, h->yrange, h->ny + 1, 1);
53
54 if (status)
55 return status;
56
57 status = gsl_block_raw_fwrite (stream, h->bin, h->nx * h->ny, 1);
58 return status;
59 }
60
61 int
62 gsl_histogram2d_fprintf (FILE * stream, const gsl_histogram2d * h,
63 const char *range_format, const char *bin_format)
64 {
65 size_t i, j;
66 const size_t nx = h->nx;
67 const size_t ny = h->ny;
68 int status;
69
70 for (i = 0; i < nx; i++)
71 {
72 for (j = 0; j < ny; j++)
73 {
74 status = fprintf (stream, range_format, h->xrange[i]);
75
76 if (status < 0)
77 {
78 GSL_ERROR ("fprintf failed", GSL_EFAILED);
79 }
80
81 status = putc (' ', stream);
82
83 if (status == EOF)
84 {
85 GSL_ERROR ("putc failed", GSL_EFAILED);
86 }
87
88 status = fprintf (stream, range_format, h->xrange[i + 1]);
89
90 if (status < 0)
91 {
92 GSL_ERROR ("fprintf failed", GSL_EFAILED);
93 }
94
95 status = putc (' ', stream);
96
97 if (status == EOF)
98 {
99 GSL_ERROR ("putc failed", GSL_EFAILED);
100 }
101
102 status = fprintf (stream, range_format, h->yrange[j]);
103
104 if (status < 0)
105 {
106 GSL_ERROR ("fprintf failed", GSL_EFAILED);
107 }
108
109 status = putc (' ', stream);
110
111 if (status == EOF)
112 {
113 GSL_ERROR ("putc failed", GSL_EFAILED);
114 }
115
116 status = fprintf (stream, range_format, h->yrange[j + 1]);
117
118 if (status < 0)
119 {
120 GSL_ERROR ("fprintf failed", GSL_EFAILED);
121 }
122
123 status = putc (' ', stream);
124
125 if (status == EOF)
126 {
127 GSL_ERROR ("putc failed", GSL_EFAILED);
128 }
129
130 status = fprintf (stream, bin_format, h->bin[i * ny + j]);
131
132 if (status < 0)
133 {
134 GSL_ERROR ("fprintf failed", GSL_EFAILED);
135 }
136
137 status = putc ('\n', stream);
138
139 if (status == EOF)
140 {
141 GSL_ERROR ("putc failed", GSL_EFAILED);
142 }
143 }
144 status = putc ('\n', stream);
145
146 if (status == EOF)
147 {
148 GSL_ERROR ("putc failed", GSL_EFAILED);
149 }
150 }
151
152 return GSL_SUCCESS;
153 }
154
155 int
156 gsl_histogram2d_fscanf (FILE * stream, gsl_histogram2d * h)
157 {
158 size_t i, j;
159 const size_t nx = h->nx;
160 const size_t ny = h->ny;
161 double xupper, yupper;
162
163 for (i = 0; i < nx; i++)
164 {
165 for (j = 0; j < ny; j++)
166 {
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);
172
173 if (status != 5)
174 {
175 GSL_ERROR ("fscanf failed", GSL_EFAILED);
176 }
177 }
178 h->yrange[ny] = yupper;
179 }
180
181 h->xrange[nx] = xupper;
182
183 return GSL_SUCCESS;
184 }