7 |
|
|
8 |
|
#include <stdio.h> |
9 |
|
#include <stdlib.h> |
10 |
+ |
#include <errno.h> |
11 |
|
#include "rtio.h" |
12 |
|
#include "resolu.h" |
13 |
|
#include "rmatrix.h" |
30 |
|
op_default(ROPERAT *op) |
31 |
|
{ |
32 |
|
memset(op, 0, sizeof(ROPERAT)); |
33 |
< |
op->op = '*'; |
33 |
> |
op->op = '.'; |
34 |
|
} |
35 |
|
|
36 |
|
static RMATRIX * |
113 |
|
} |
114 |
|
if (mleft == NULL) /* just one matrix */ |
115 |
|
return(mright); |
116 |
< |
if (op->op == '*') { /* concatenate */ |
116 |
> |
if (op->op == '.') { /* concatenate */ |
117 |
|
RMATRIX *mres = rmx_multiply(mleft, mright); |
118 |
|
if (mres == NULL) { |
119 |
|
fputs(fname, stderr); |
144 |
|
fputs(": added in matrix\n", stderr); |
145 |
|
} |
146 |
|
rmx_free(mright); |
147 |
+ |
} else if ((op->op == '*') | (op->op == '/')) { |
148 |
+ |
const char * tnam = (op->op == '/') ? |
149 |
+ |
"division" : "multiplication"; |
150 |
+ |
errno = 0; |
151 |
+ |
if (!rmx_elemult(mleft, mright, (op->op == '/'))) { |
152 |
+ |
fprintf(stderr, "%s: element-wise %s failed\n", |
153 |
+ |
fname, tnam); |
154 |
+ |
rmx_free(mright); |
155 |
+ |
return(NULL); |
156 |
+ |
} |
157 |
+ |
if (errno) |
158 |
+ |
fprintf(stderr, |
159 |
+ |
"%s: warning - error during element-wise %s\n", |
160 |
+ |
fname, tnam); |
161 |
+ |
else if (verbose) |
162 |
+ |
fprintf(stderr, "%s: element-wise %s\n", fname, tnam); |
163 |
+ |
rmx_free(mright); |
164 |
|
} else { |
165 |
|
fprintf(stderr, "%s: unknown operation '%c'\n", fname, op->op); |
166 |
|
rmx_free(mright); |
191 |
|
op_default(&op); |
192 |
|
/* get options and arguments */ |
193 |
|
for (i = 1; i < argc; i++) |
194 |
< |
if (argv[i][0] == '+' && !argv[i][1]) { |
195 |
< |
op.op = '+'; |
194 |
> |
if (argv[i][0] && !argv[i][1] && |
195 |
> |
strchr("+*/", argv[i][0]) != NULL) { |
196 |
> |
op.op = argv[i][0]; |
197 |
|
} else if (argv[i][0] != '-' || !argv[i][1]) { |
198 |
|
char *fname = NULL; /* load matrix */ |
199 |
|
if (argv[i][0] != '-') |
265 |
|
return(0); |
266 |
|
userr: |
267 |
|
fprintf(stderr, |
268 |
< |
"Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..] m1 [+] .. > mres\n", |
268 |
> |
"Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..] m1 [+*/] .. > mres\n", |
269 |
|
argv[0]); |
270 |
|
return(1); |
271 |
|
} |