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

Comparing ray/src/util/rmatrix.c (file contents):
Revision 2.33 by greg, Mon Aug 12 18:15:44 2019 UTC vs.
Revision 2.37 by greg, Wed Sep 4 00:03:05 2019 UTC

# Line 32 | Line 32 | rmx_alloc(int nr, int nc, int n)
32                  return(NULL);
33          dnew->nrows = nr; dnew->ncols = nc; dnew->ncomp = n;
34          dnew->dtype = DTdouble;
35 +        dnew->swapin = 0;
36          dnew->info = NULL;
37          return(dnew);
38   }
# Line 98 | Line 99 | get_dminfo(char *s, void *p)
99                  ip->ncols = atoi(s+6);
100                  return(0);
101          }
102 +        if ((i = isbigendian(s)) >= 0) {
103 +                ip->swapin = (nativebigendian() != i);
104 +                return(0);
105 +        }
106          if (!formatval(fmt, s)) {
107                  rmx_addinfo(ip, s);
108                  return(0);
# Line 137 | Line 142 | rmx_load_float(RMATRIX *rm, FILE *fp)
142              for (j = 0; j < rm->ncols; j++) {
143                  if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp)
144                      return(0);
145 +                if (rm->swapin)
146 +                    swap32((char *)val, rm->ncomp);
147                  for (k = rm->ncomp; k--; )
148                       rmx_lval(rm,i,j,k) = val[k];
149              }
# Line 149 | Line 156 | rmx_load_double(RMATRIX *rm, FILE *fp)
156          int     i, j;
157  
158          for (i = 0; i < rm->nrows; i++)
159 <            for (j = 0; j < rm->ncols; j++)
159 >            for (j = 0; j < rm->ncols; j++) {
160                  if (getbinary(&rmx_lval(rm,i,j,0), sizeof(double), rm->ncomp, fp) != rm->ncomp)
161                      return(0);
162 +                if (rm->swapin)
163 +                    swap64((char *)&rmx_lval(rm,i,j,0), rm->ncomp);
164 +            }
165          return(1);
166   }
167  
# Line 192 | Line 202 | rmx_load(const char *inspec)
202          } else if (inspec[0] == '!') {
203                  if (!(fp = popen(inspec+1, "r")))
204                          return(NULL);
205 <                SET_FILE_BINARY(stdin);
205 >                SET_FILE_BINARY(fp);
206          } else {
207                  const char      *sp = inspec;   /* check suffix */
208                  while (*sp)
# Line 217 | Line 227 | rmx_load(const char *inspec)
227   #endif
228          dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0;
229          dinfo.dtype = DTascii;                  /* assumed w/o FORMAT */
230 +        dinfo.swapin = 0;
231          dinfo.info = NULL;
232          if (getheader(fp, get_dminfo, &dinfo) < 0) {
233                  fclose(fp);
# Line 243 | Line 254 | rmx_load(const char *inspec)
254          dnew->info = dinfo.info;
255          switch (dinfo.dtype) {
256          case DTascii:
257 <                SET_FILE_TEXT(stdin);
257 >                SET_FILE_TEXT(fp);
258                  if (!rmx_load_ascii(dnew, fp))
259                          goto loaderr;
260                  dnew->dtype = DTascii;          /* should leave double? */
261                  break;
262          case DTfloat:
263 +                dnew->swapin = dinfo.swapin;
264                  if (!rmx_load_float(dnew, fp))
265                          goto loaderr;
266                  dnew->dtype = DTfloat;
267                  break;
268          case DTdouble:
269 +                dnew->swapin = dinfo.swapin;
270                  if (!rmx_load_double(dnew, fp))
271                          goto loaderr;
272                  dnew->dtype = DTdouble;
# Line 395 | Line 408 | rmx_write(const RMATRIX *rm, int dtype, FILE *fp)
408                          return(0);
409                  rm = mydm;
410          }
411 +        if ((dtype == DTfloat) | (dtype == DTdouble))
412 +                fputendian(fp);                 /* important to record */
413          fputformat((char *)cm_fmt_id[dtype], fp);
414          fputc('\n', fp);
415          switch (dtype) {                        /* write data */
# Line 568 | Line 583 | rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide
583                              rmx_lval(m1,i,j,k) *= rmx_lval(m2,i,j,k);
584                  }
585          if (zeroDivides) {
586 <                fputs("Divide by zero in rmx_elemult()\n", stderr);
586 >                rmx_addinfo(m1, "WARNING: zero divide(s) corrupted results\n");
587                  errno = ERANGE;
588          }
589          return(1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines