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

Comparing ray/src/util/cmatrix.c (file contents):
Revision 2.21 by greg, Mon Aug 12 18:28:37 2019 UTC vs.
Revision 2.22 by greg, Wed Aug 14 18:20:02 2019 UTC

# Line 81 | Line 81 | cm_resize(CMATRIX *cm, int nrows)
81  
82   typedef struct {
83          int     dtype;          /* data type */
84 +        int     need2swap;      /* need byte swap? */
85          int     nrows, ncols;   /* matrix size */
86          char    *err;           /* error message */
87   } CMINFO;               /* header info record */
# Line 104 | Line 105 | get_cminfo(char *s, void *p)
105                  ip->ncols = atoi(s+6);
106                  return(0);
107          }
108 +        if ((i = isbigendian(s)) >= 0) {
109 +                ip->need2swap = (nativebigendian() != i);
110 +                return(0);
111 +        }
112          if (!formatval(fmt, s))
113                  return(0);
114          for (i = 1; i < DTend; i++)
# Line 114 | Line 119 | get_cminfo(char *s, void *p)
119  
120   /* Load header to obtain/check data type and number of columns */
121   char *
122 < cm_getheader(int *dt, int *nr, int *nc, FILE *fp)
122 > cm_getheader(int *dt, int *nr, int *nc, int *swp, FILE *fp)
123   {
124          CMINFO  cmi;
125                                                  /* read header */
126          cmi.dtype = DTfromHeader;
127 +        cmi.need2swap = 0;
128          cmi.nrows = cmi.ncols = 0;
129          cmi.err = "unexpected EOF in header";
130          if (getheader(fp, get_cminfo, &cmi) < 0)
# Line 144 | Line 150 | cm_getheader(int *dt, int *nr, int *nc, FILE *fp)
150                  else if ((cmi.ncols > 0) & (*nc != cmi.ncols))
151                          return("unexpected column count in header");
152          }
153 +        if (swp)                                /* get/check swap? */
154 +                *swp = cmi.need2swap;
155          return(NULL);
156   }
157  
# Line 153 | Line 161 | cm_load(const char *inspec, int nrows, int ncols, int
161   {
162          const int       ROWINC = 2048;
163          FILE            *fp = stdin;
164 +        int             swap = 0;
165          CMATRIX         *cm;
166  
167          if (!inspec)
# Line 173 | Line 182 | cm_load(const char *inspec, int nrows, int ncols, int
182          if (dtype != DTascii)
183                  SET_FILE_BINARY(fp);            /* doesn't really work */
184          if (!dtype | !ncols) {                  /* expecting header? */
185 <                char    *err = cm_getheader(&dtype, &nrows, &ncols, fp);
185 >                char    *err = cm_getheader(&dtype, &nrows, &ncols, &swap, fp);
186                  if (err)
187                          error(USER, err);
188                  if (ncols <= 0)
# Line 296 | Line 305 | cm_load(const char *inspec, int nrows, int ncols, int
305                                                  inspec);
306                                  error(WARNING, errmsg);
307                  }
308 +        }
309 +        if (swap) {
310 +                if (dtype == DTfloat)
311 +                        swap32((char *)cm->cmem, 3*cm->nrows*cm->ncols);
312 +                else if (dtype == DTdouble)
313 +                        swap64((char *)cm->cmem, 3*cm->nrows*cm->ncols);
314          }
315          if (fp != stdin) {
316                  if (inspec[0] != '!')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines