Debian Codegraph @

imagery/i.ortho.photo/lib/m_add.c

raw symbols SCIP
1 #include <stdio.h>
2 #include "mat.h"
3 #include "matrixdefs.h"
4 #include "local_proto.h"
5
6 /*
7 * m_add: matrix addition (returns c = a + b)
8 */
9 int m_add(MATRIX *a, MATRIX *b, MATRIX *c)
10 {
11 register int nr, nc;
12 char message[256];
13 register double *ap, *bp, *mp;
14 static MATRIX m;
15
16 if (a->nrows == 0)
17 return error("+: arg1 not defined\n");
18 else if (b->nrows == 0)
19 return error("+: arg2 not defined\n");
20
21 /* check for conformity */
22 if ((a->nrows != b->nrows) || (a->ncols != b->ncols)) {
23 snprintf(message, sizeof(message),
24 "+: matrices not conformable, %d x %d + %d x %d\n", a->nrows,
25 a->ncols, b->nrows, b->ncols);
26 return error(message);
27 }
28
29 nr = a->nrows;
30 while (nr--) {
31 nc = a->ncols;
32 ap = &(a->x[nr][0]);
33 bp = &(b->x[nr][0]);
34 mp = &(m.x[nr][0]);
35 while (nc--)
36 *mp++ = *ap++ + *bp++;
37 }
38 m.nrows = a->nrows;
39 m.ncols = a->ncols;
40 m_copy(c, &m);
41 return 1;
42 }