PIPS
matrice_io.c
Go to the documentation of this file.
1 /*
2 
3  $Id: matrice_io.c 1669 2019-06-26 17:24:57Z coelho $
4 
5  Copyright 1989-2016 MINES ParisTech
6 
7  This file is part of Linear/C3 Library.
8 
9  Linear/C3 Library is free software: you can redistribute it and/or modify it
10  under the terms of the GNU Lesser General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  any later version.
13 
14  Linear/C3 Library is distributed in the hope that it will be useful, but WITHOUT ANY
15  WARRANTY; without even the implied warranty of MERCHANTABILITY or
16  FITNESS FOR A PARTICULAR PURPOSE.
17 
18  See the GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with Linear/C3 Library. If not, see <http://www.gnu.org/licenses/>.
22 
23 */
24 
25  /* package matrice */
26 
27 #ifdef HAVE_CONFIG_H
28  #include "config.h"
29 #endif
30 
31 #include <stdlib.h>
32 #include <stdio.h>
33 
34 #include "linear_assert.h"
35 
36 #include "boolean.h"
37 #include "arithmetique.h"
38 
39 #include "matrice.h"
40 
41 /* void pr_quot(FILE * f, int a, int b): print quotient a/b in a sensible way,
42  * i.e. add a space in front of positive number to compensate for the
43  * minus sign of negative number
44  *
45  * FI: a quoi sert le parametre b? A quoi sert la variable d? =>ARGSUSED
46  */
47 static void pr_quot(FILE * f,
48  Value a,
49  Value b __attribute__((unused)))
50 {
51  if (value_pos_p(a))
52  fprintf(f, " ");
53  fprintf(f, " ");
54  fprint_Value(f, a);
55  fprintf(f, " ");
56 }
57 
58 /* void matrice_fprint(File * f, matrice a,n,m): print an (nxm) rational matrix
59  *
60  * Note: the output format is incompatible with matrice_fscan()
61  */
62 void matrice_fprint(f,a,n,m)
63 FILE * f;
64 matrice a;
65 int n; /* column size */
66 int m; /* row size */
67 {
68  int loop1,loop2;
69 
71 
72  (void) fprintf(f,"\n\n");
73 
74  for(loop1=1; loop1<=n; loop1++) {
75  for(loop2=1; loop2<=m; loop2++)
76  pr_quot(f, ACCESS(a,n,loop1,loop2), DENOMINATOR(a));
77  (void) fprintf(f,"\n\n");
78  }
79  (void) fprintf(f," ......denominator = ");
81  fprintf(f, "\n");
82 }
83 
84 /* void matrice_print(matrice a, int n, int m): print an (nxm) rational matrix
85  *
86  * Note: the output format is incompatible with matrice_fscan()
87  * this should be implemented as a macro, but it's a function for
88  * dbx's sake
89  */
90 void matrice_print(a,n,m)
91 matrice a;
92 int n; /* column size */
93 int m; /* row size */
94 {
95  matrice_fprint(stdout,a,n,m);
96 }
97 
98 /* void matrice_fscan(FILE * f, matrice * a, int * n, int * m):
99  * read an (nxm) rational matrix in an ASCII file accessible
100  * via file descriptor f; a is allocated as a function of its number
101  * of columns and rows, n and m.
102  *
103  * Format:
104  *
105  * n m denominator a[1,1] a[1,2] ... a[1,m] a[2,1] ... a[2,m] ... a[n,m]
106  *
107  * After the two dimensions and the global denominator, the matrix as
108  * usually displayed, line by line. Line feed can be used anywhere.
109  * Example for a (2x3) integer matrix:
110  * 2 3
111  * 1
112  * 1 2 3
113  * 4 5 6
114  */
115 void matrice_fscan(f,a,n,m)
116 FILE * f;
117 matrice * a;
118 int * n; /* column size */
119 int * m; /* row size */
120 {
121  int r;
122  int c;
123 
124  /* number of read elements */
125  int n_read;
126 
127  /* read dimensions */
128  n_read = fscanf(f,"%d%d", n, m);
129  assert(n_read==2);
130  assert(1 <= *n && 1 <= *m);
131 
132  /* allocate a */
133  *a = matrice_new(*n,*m);
134 
135  /* read denominator */
136  n_read = fscan_Value(f,&(DENOMINATOR(*a)));
137  assert(n_read == 1);
138  /* necessaires pour eviter les divisions par zero */
140  /* pour "normaliser" un peu les representations */
142 
143  for(r = 1; r <= *n; r++)
144  for(c = 1; c <= *m; c++) {
145  n_read = fscan_Value(f,&ACCESS(*a,*n,r,c));
146  assert(n_read == 1);
147  }
148 }
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
Definition: 3dnow.h:3
#define value_pos_p(val)
#define value_notzero_p(val)
int Value
void fprint_Value(FILE *, Value)
Definition: io.c:42
int fscan_Value(FILE *, Value *)
Definition: io.c:58
loop loop1
tiling_sequence.c
#define DENOMINATOR(matrix)
int DENOMINATEUR(matrix): acces au denominateur global d'une matrice matrix La combinaison *(&()) est...
Definition: matrice-local.h:93
#define ACCESS(matrix, column, i, j)
Macros d'acces aux elements d'une matrice.
Definition: matrice-local.h:86
#define matrice_new(n, m)
Allocation et desallocation d'une matrice.
Definition: matrice-local.h:77
Value * matrice
package matrice
Definition: matrice-local.h:71
static void pr_quot(FILE *f, Value a, Value b __attribute__((unused)))
package matrice
Definition: matrice_io.c:47
void matrice_fscan(FILE *f, matrice *a, int *n, int *m)
void matrice_fscan(FILE * f, matrice * a, int * n, int * m): read an (nxm) rational matrix in an ASCI...
Definition: matrice_io.c:115
void matrice_print(matrice a, int n, int m)
void matrice_print(matrice a, int n, int m): print an (nxm) rational matrix
Definition: matrice_io.c:90
void matrice_fprint(FILE *f, matrice a, int n, int m)
void matrice_fprint(File * f, matrice a,n,m): print an (nxm) rational matrix
Definition: matrice_io.c:62
#define assert(ex)
Definition: newgen_assert.h:41
int f(int off1, int off2, int n, float r[n], float a[n], float b[n])
Definition: offsets.c:15
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...