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.15 by greg, Mon Aug 12 16:55:24 2019 UTC vs.
Revision 2.18 by greg, Tue Jan 19 23:32:00 2021 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   * General component matrix operations.
6   */
7  
8 #include <stdio.h>
8   #include <stdlib.h>
9   #include <errno.h>
10   #include "rtio.h"
# Line 15 | Line 14 | static const char RCSid[] = "$Id$";
14  
15   #define MAXCOMP         16              /* #components we support */
16  
18 static const char       stdin_name[] = "<stdin>";
19
17   /* unary matrix operation(s) */
18   typedef struct {
19          double          sca[MAXCOMP];           /* scalar coefficients */
# Line 29 | Line 26 | typedef struct {
26   /* matrix input source and requested operation(s) */
27   typedef struct {
28          const char      *inspec;                /* input specification */
29 +        RMPref          rmp;                    /* matrix preference */
30          RUNARYOP        preop;                  /* unary operation(s) */
31          RMATRIX         *mtx;                   /* original matrix if loaded */
32          int             binop;                  /* binary op with next (or 0) */
# Line 43 | Line 41 | loadmatrix(ROPMAT *rop)
41          if (rop->mtx != NULL)
42                  return(0);
43  
44 <        rop->mtx = rmx_load(rop->inspec == stdin_name ?
47 <                                (const char *)NULL : rop->inspec);
44 >        rop->mtx = rmx_load(rop->inspec, rop->rmp);
45          if (rop->mtx == NULL) {
46                  fputs(rop->inspec, stderr);
47                  fputs(": cannot load matrix\n", stderr);
# Line 140 | Line 137 | binaryop(const char *inspec, RMATRIX *mleft, int op, R
137  
138          if ((mleft == NULL) | (mright == NULL))
139                  return(NULL);
143
140          switch (op) {
141          case '.':                       /* concatenate */
142 <                mres = rmx_multiply(mleft, mright);
142 >                if (mleft->ncomp != mright->ncomp) {
143 >                        fputs(inspec, stderr);
144 >                        fputs(": # components do not match\n", stderr);
145 >                } else if (mleft->ncols != mright->nrows) {
146 >                        fputs(inspec, stderr);
147 >                        fputs(": mismatched dimensions\n",
148 >                                        stderr);
149 >                } else
150 >                        mres = rmx_multiply(mleft, mright);
151                  rmx_free(mleft);
152                  rmx_free(mright);
153                  if (mres == NULL) {
154                          fputs(inspec, stderr);
155 <                        if (mleft->ncols != mright->nrows)
152 <                                fputs(": mismatched dimensions for multiply\n",
153 <                                                stderr);
154 <                        else
155 <                                fputs(": concatenation failed\n", stderr);
155 >                        fputs(": concatenation failed\n", stderr);
156                          return(NULL);
157                  }
158                  if (verbose) {
# Line 380 | Line 380 | main(int argc, char *argv[])
380                                          get_factors(mop[nmats].preop.cmat,
381                                                          n, argv+i+1);
382                                  break;
383 +                        case 'r':
384 +                                if (argv[i][2] == 'f')
385 +                                        mop[nmats].rmp = RMPreflF;
386 +                                else if (argv[i][2] == 'b')
387 +                                        mop[nmats].rmp = RMPreflB;
388 +                                else
389 +                                        goto userr;
390 +                                break;
391                          default:
392                                  fprintf(stderr, "%s: unknown operation '%s'\n",
393                                                  argv[0], argv[i]);
# Line 422 | Line 430 | main(int argc, char *argv[])
430          return(0);
431   userr:
432          fprintf(stderr,
433 <        "Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..] m1 [.+*/] .. > mres\n",
433 >        "Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..][-r[fb]] m1 [.+*/] .. > mres\n",
434                          argv[0]);
435          return(1);
436   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines