ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rmtxop.c
(Generate patch)

Comparing ray/src/util/rmtxop.c (file contents):
Revision 2.1 by greg, Sat May 31 05:02:37 2014 UTC vs.
Revision 2.6 by greg, Tue Dec 16 20:21:46 2014 UTC

# Line 18 | Line 18 | typedef struct {
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
# Line 36 | Line 36 | static RMATRIX *
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)
# Line 45 | Line 46 | operate(RMATRIX *mleft, ROPERAT *op, const char *fname
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);
# Line 56 | Line 58 | operate(RMATRIX *mleft, ROPERAT *op, const char *fname
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) {
# Line 88 | Line 92 | operate(RMATRIX *mleft, ROPERAT *op, const char *fname
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);
# Line 107 | Line 110 | operate(RMATRIX *mleft, ROPERAT *op, const char *fname
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 */
# Line 176 | Line 167 | main(int argc, char *argv[])
167   {
168          RMATRIX *mres = NULL;
169          ROPERAT op;
179        long    nbw;
170          int     i;
171                                          /* initialize */
172          op_default(&op);
# Line 220 | Line 210 | main(int argc, char *argv[])
210                                  }
211                                  break;
212                          case 't':
213 <                                if (!op.nsf & !op.clen)
224 <                                        op.transpose = -1;
225 <                                else
226 <                                        op.transpose = 1;
213 >                                op.transpose = 1;
214                                  break;
215                          case 's':
216                                  if (n > MAXCOMP) n = MAXCOMP;
# Line 244 | Line 231 | main(int argc, char *argv[])
231          if (mres == NULL)               /* check that we got something */
232                  goto userr;
233                                          /* write result to stdout */
234 + #ifdef getc_unlocked
235 +        flockfile(stdout);
236 + #endif
237 +        if (outfmt == DTfromHeader)
238 +                outfmt = mres->dtype;
239 + #ifdef _WIN32
240 +        if (outfmt != DTascii)
241 +                _setmode(fileno(stdout), _O_BINARY);
242 + #endif
243          newheader("RADIANCE", stdout);
244          printargs(argc, argv, stdout);
245 <        nbw = rmx_write(mres, outfmt, stdout);
250 <        /* rmx_free(mres); mres = NULL; */
251 <        if (nbw <= 0) {
245 >        if (!rmx_write(mres, outfmt, stdout)) {
246                  fprintf(stderr, "%s: error writing result matrix\n", argv[0]);
247                  return(1);
248          }
249 <        if (verbose)
256 <                fprintf(stderr, "%s: %ld bytes written\n", argv[0], nbw);
249 >        /* rmx_free(mres); mres = NULL; */
250          return(0);
251   userr:
252          fprintf(stderr,
253 <        "Usage: %s [-v][-f[adfc][-t][-s sf ..][-c ce ..] m1 [+] .. > mres\n",
253 >        "Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..] m1 [+] .. > mres\n",
254                          argv[0]);
255          return(1);
256   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines