PIPS
matrix_io.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "linear_assert.h"
#include "boolean.h"
#include "arithmetique.h"
#include "matrix.h"
+ Include dependency graph for matrix_io.c:

Go to the source code of this file.

Functions

void matrix_fprint (FILE *f, Pmatrix a)
 package matrice More...
 
void matrix_print (Pmatrix a)
 void matrix_print(matrice a): print an (nxm) rational matrix More...
 
void matrix_fscan (FILE *f, Pmatrix *a, int *n, int *m)
 void matrix_fscan(FILE * f, matrice * a, int * n, int * m): read an (nxm) rational matrix in an ASCII file accessible via file descriptor f; a is allocated as a function of its number of columns and rows, n and m. More...
 
void matrix_pr_quot (FILE *f, Value a, Value b __attribute__((unused)))
 void matrix_pr_quot(FILE * f, int a, int b): More...
 

Function Documentation

◆ matrix_fprint()

void matrix_fprint ( FILE *  f,
Pmatrix  a 
)

package matrice

matrix_io.c

void matrix_fprint(File * f, matrix a): print a rational matrix

Note: the output format is compatible with matrix_fscan()

Definition at line 44 of file matrix_io.c.

45 {
46  int i, j;
47  int m = MATRIX_NB_LINES(a);
48  int n = MATRIX_NB_COLUMNS(a);
50 
51  (void) fprintf(f, "%d %d\n", m, n);
52  (void) fprint_Value(f, MATRIX_DENOMINATOR(a));
53  (void) fprintf(f, "\n");
54  for(i=1; i<=m; i++) {
55  for(j=1; j<=n; j++) {
56  // matrix_pr_quot(f, MATRIX_ELEM(a,i,j), MATRIX_DENOMINATOR(a));
57  fprint_Value(f, MATRIX_ELEM(a,i,j));
58  fprintf(f, " ");
59  }
60  (void) fprintf(f, "\n");
61  }
62 }
#define VALUE_ZERO
void fprint_Value(FILE *, Value)
Definition: io.c:42
#define MATRIX_NB_LINES(matrix)
Definition: matrix-local.h:87
#define MATRIX_NB_COLUMNS(matrix)
Definition: matrix-local.h:88
#define MATRIX_DENOMINATOR(matrix)
int MATRIX_DENONIMATOR(matrix): acces au denominateur global d'une matrice matrix
Definition: matrix-local.h:86
#define MATRIX_ELEM(matrix, i, j)
Macros d'acces aux elements d'une matrice.
Definition: matrix-local.h:80
#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 ...

References assert, f(), fprint_Value(), fprintf(), MATRIX_DENOMINATOR, MATRIX_ELEM, MATRIX_NB_COLUMNS, MATRIX_NB_LINES, and VALUE_ZERO.

Referenced by main(), make_reindex(), matrix_print(), and prepare_reindexing().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matrix_fscan()

void matrix_fscan ( FILE *  f,
Pmatrix a,
int n,
int m 
)

void matrix_fscan(FILE * f, matrice * a, int * n, int * m): read an (nxm) rational matrix in an ASCII file accessible via file descriptor f; a is allocated as a function of its number of columns and rows, n and m.

Format:

n m denominator a[1,1] a[1,2] ... a[1,m] a[2,1] ... a[2,m] ... a[n,m]

After the two dimensions and the global denominator, the matrix as usually displayed, line by line. Line feed can be used anywhere. Example for a (2x3) integer matrix: 2 3 1 1 2 3 4 5 6 row size

number of read elements

read dimensions

allocate a

read denominator

necessaires pour eviter les divisions par zero

pour "normaliser" un peu les representations

Parameters
mFormat:

n m denominator a[1,1] a[1,2] ... a[1,m] a[2,1] ... a[2,m] ... a[n,m]

After the two dimensions and the global denominator, the matrix as usually displayed, line by line. Line feed can be used anywhere. Example for a (2x3) integer matrix: 2 3 1 1 2 3 4 5 6 column size

Definition at line 93 of file matrix_io.c.

98 {
99  int r;
100  int c;
101 
102  /* number of read elements */
103  int n_read;
104 
105  /* read dimensions */
106  n_read = fscanf(f,"%d%d", n, m);
107  assert(n_read==2);
108  assert(1 <= *n && 1 <= *m);
109 
110  /* allocate a */
111  *a = matrix_new(*n,*m);
112 
113  /* read denominator */
114  n_read = fscan_Value(f,&(MATRIX_DENOMINATOR(*a)));
115  assert(n_read == 1);
116  /* necessaires pour eviter les divisions par zero */
118  /* pour "normaliser" un peu les representations */
120 
121  for(r = 1; r <= *n; r++)
122  for(c = 1; c <= *m; c++) {
123  n_read = fscan_Value(f, &MATRIX_ELEM(*a,r,c));
124  assert(n_read == 1);
125  }
126 }
#define value_pos_p(val)
#define value_notzero_p(val)
int fscan_Value(FILE *, Value *)
Definition: io.c:58
Pmatrix matrix_new(int m, int n)
package matrix
Definition: alloc.c:41

References assert, f(), fscan_Value(), MATRIX_DENOMINATOR, MATRIX_ELEM, matrix_new(), value_notzero_p, and value_pos_p.

Referenced by Hierarchical_tiling(), main(), Tiling2_buffer(), and Tiling_buffer_allocation().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ matrix_pr_quot()

void matrix_pr_quot ( FILE *  f,
Value  a,
Value b   __attribute__(unused) 
)

void matrix_pr_quot(FILE * f, int a, int b):

print quotient a/b in a sensible way, i.e. add a space in front of positive number to compensate for the minus sign of negative number

FI: a quoi sert le parametre b? A quoi sert la variable d? =>ARGSUSED RGSUSED

Definition at line 137 of file matrix_io.c.

138 {
139  if (value_pos_p(a))
140  fprintf(f, " ");
141  fprintf(f, " ");
142  fprint_Value(f, a);
143  fprintf(f, " ");
144 }

References f(), fprint_Value(), fprintf(), and value_pos_p.

+ Here is the call graph for this function:

◆ matrix_print()

void matrix_print ( Pmatrix  a)

void matrix_print(matrice a): print an (nxm) rational matrix

Note: the output format is incompatible with matrix_fscan() this should be implemented as a macro, but it's a function for dbx's sake

Definition at line 70 of file matrix_io.c.

72 {
73  matrix_fprint(stdout,a);
74 }
void matrix_fprint(FILE *f, Pmatrix a)
package matrice
Definition: matrix_io.c:44

References matrix_fprint().

Referenced by Hierarchical_tiling(), matrix_smith(), sc_resol_smith(), smith_int(), and Tiling2_buffer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: