18 |
|
int nsf; /* number of scalars */ |
19 |
|
double cmat[MAXCOMP*MAXCOMP]; /* component transformation */ |
20 |
|
int clen; /* number of coefficients */ |
21 |
< |
int transpose; /* do transpose? (<0 first) */ |
21 |
> |
int transpose; /* do transpose? */ |
22 |
|
int op; /* '*' or '+' */ |
23 |
|
} ROPERAT; /* matrix operation */ |
24 |
|
|
25 |
< |
int outfmt = DTascii; /* output format */ |
25 |
> |
int outfmt = DTfromHeader; /* output format */ |
26 |
|
int verbose = 0; /* verbose reporting? */ |
27 |
|
|
28 |
|
static void |
36 |
|
operate(RMATRIX *mleft, ROPERAT *op, const char *fname) |
37 |
|
{ |
38 |
|
RMATRIX *mright = rmx_load(fname); |
39 |
+ |
RMATRIX *mtmp; |
40 |
|
int i; |
41 |
|
|
42 |
|
if (fname == NULL) |
46 |
|
fputs(": cannot load matrix\n", stderr); |
47 |
|
return(NULL); |
48 |
|
} |
49 |
< |
if (op->transpose < 0) { /* transpose first? */ |
50 |
< |
if (!rmx_transpose(mright)) { |
49 |
> |
if (op->transpose) { /* transpose matrix? */ |
50 |
> |
mtmp = rmx_transpose(mright); |
51 |
> |
if (mtmp == NULL) { |
52 |
|
fputs(fname, stderr); |
53 |
|
fputs(": transpose failed\n", stderr); |
54 |
|
rmx_free(mright); |
58 |
|
fputs(fname, stderr); |
59 |
|
fputs(": transposed rows and columns\n", stderr); |
60 |
|
} |
61 |
+ |
rmx_free(mright); |
62 |
+ |
mright = mtmp; |
63 |
|
} |
64 |
|
if (op->nsf > 0) { /* apply scalar(s) */ |
65 |
|
if (op->clen > 0) { |
92 |
|
} |
93 |
|
} |
94 |
|
if (op->clen > 0) { /* apply transform */ |
91 |
– |
RMATRIX *mtmp; |
95 |
|
if (op->clen % mright->ncomp) { |
96 |
|
fprintf(stderr, "%s: -c must have N x %d coefficients\n", |
97 |
|
fname, mright->ncomp); |
110 |
|
rmx_free(mright); |
111 |
|
mright = mtmp; |
112 |
|
} |
110 |
– |
if (op->transpose > 0) { /* transpose after? */ |
111 |
– |
if (!rmx_transpose(mright)) { |
112 |
– |
fputs(fname, stderr); |
113 |
– |
fputs(": transpose failed\n", stderr); |
114 |
– |
rmx_free(mright); |
115 |
– |
return(NULL); |
116 |
– |
} |
117 |
– |
if (verbose) { |
118 |
– |
fputs(fname, stderr); |
119 |
– |
fputs(": transposed rows and columns\n", stderr); |
120 |
– |
} |
121 |
– |
} |
113 |
|
if (mleft == NULL) /* just one matrix */ |
114 |
|
return(mright); |
115 |
|
if (op->op == '*') { /* concatenate */ |
211 |
|
} |
212 |
|
break; |
213 |
|
case 't': |
214 |
< |
if (!op.nsf & !op.clen) |
224 |
< |
op.transpose = -1; |
225 |
< |
else |
226 |
< |
op.transpose = 1; |
214 |
> |
op.transpose = 1; |
215 |
|
break; |
216 |
|
case 's': |
217 |
|
if (n > MAXCOMP) n = MAXCOMP; |
232 |
|
if (mres == NULL) /* check that we got something */ |
233 |
|
goto userr; |
234 |
|
/* write result to stdout */ |
235 |
+ |
#ifdef getc_unlocked |
236 |
+ |
flockfile(stdout); |
237 |
+ |
#endif |
238 |
+ |
#ifdef _WIN32 |
239 |
+ |
if (outfmt != DTascii) |
240 |
+ |
_setmode(fileno(stdout), _O_BINARY); |
241 |
+ |
#endif |
242 |
|
newheader("RADIANCE", stdout); |
243 |
|
printargs(argc, argv, stdout); |
244 |
|
nbw = rmx_write(mres, outfmt, stdout); |
252 |
|
return(0); |
253 |
|
userr: |
254 |
|
fprintf(stderr, |
255 |
< |
"Usage: %s [-v][-f[adfc][-t][-s sf ..][-c ce ..] m1 [+] .. > mres\n", |
255 |
> |
"Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..] m1 [+] .. > mres\n", |
256 |
|
argv[0]); |
257 |
|
return(1); |
258 |
|
} |