| 5 |
|
* General matrix operations. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
#include <stdio.h> |
| 8 |
|
#include <stdlib.h> |
| 10 |
– |
#include <string.h> |
| 11 |
– |
#include <fcntl.h> |
| 9 |
|
#include <errno.h> |
| 10 |
|
#include "rtio.h" |
| 11 |
|
#include "platform.h" |
| 29 |
|
return(NULL); |
| 30 |
|
dnew->nrows = nr; dnew->ncols = nc; dnew->ncomp = n; |
| 31 |
|
dnew->dtype = DTdouble; |
| 32 |
+ |
dnew->swapin = 0; |
| 33 |
|
dnew->info = NULL; |
| 34 |
|
return(dnew); |
| 35 |
|
} |
| 96 |
|
ip->ncols = atoi(s+6); |
| 97 |
|
return(0); |
| 98 |
|
} |
| 99 |
+ |
if ((i = isbigendian(s)) >= 0) { |
| 100 |
+ |
ip->swapin = (nativebigendian() != i); |
| 101 |
+ |
return(0); |
| 102 |
+ |
} |
| 103 |
|
if (!formatval(fmt, s)) { |
| 104 |
|
rmx_addinfo(ip, s); |
| 105 |
|
return(0); |
| 139 |
|
for (j = 0; j < rm->ncols; j++) { |
| 140 |
|
if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 141 |
|
return(0); |
| 142 |
+ |
if (rm->swapin) |
| 143 |
+ |
swap32((char *)val, rm->ncomp); |
| 144 |
|
for (k = rm->ncomp; k--; ) |
| 145 |
|
rmx_lval(rm,i,j,k) = val[k]; |
| 146 |
|
} |
| 153 |
|
int i, j; |
| 154 |
|
|
| 155 |
|
for (i = 0; i < rm->nrows; i++) |
| 156 |
< |
for (j = 0; j < rm->ncols; j++) |
| 156 |
> |
for (j = 0; j < rm->ncols; j++) { |
| 157 |
|
if (getbinary(&rmx_lval(rm,i,j,0), sizeof(double), rm->ncomp, fp) != rm->ncomp) |
| 158 |
|
return(0); |
| 159 |
+ |
if (rm->swapin) |
| 160 |
+ |
swap64((char *)&rmx_lval(rm,i,j,0), rm->ncomp); |
| 161 |
+ |
} |
| 162 |
|
return(1); |
| 163 |
|
} |
| 164 |
|
|
| 199 |
|
} else if (inspec[0] == '!') { |
| 200 |
|
if (!(fp = popen(inspec+1, "r"))) |
| 201 |
|
return(NULL); |
| 202 |
< |
SET_FILE_BINARY(stdin); |
| 202 |
> |
SET_FILE_BINARY(fp); |
| 203 |
|
} else { |
| 204 |
|
const char *sp = inspec; /* check suffix */ |
| 205 |
|
while (*sp) |
| 224 |
|
#endif |
| 225 |
|
dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0; |
| 226 |
|
dinfo.dtype = DTascii; /* assumed w/o FORMAT */ |
| 227 |
+ |
dinfo.swapin = 0; |
| 228 |
|
dinfo.info = NULL; |
| 229 |
|
if (getheader(fp, get_dminfo, &dinfo) < 0) { |
| 230 |
|
fclose(fp); |
| 251 |
|
dnew->info = dinfo.info; |
| 252 |
|
switch (dinfo.dtype) { |
| 253 |
|
case DTascii: |
| 254 |
< |
SET_FILE_TEXT(stdin); |
| 254 |
> |
SET_FILE_TEXT(fp); |
| 255 |
|
if (!rmx_load_ascii(dnew, fp)) |
| 256 |
|
goto loaderr; |
| 257 |
|
dnew->dtype = DTascii; /* should leave double? */ |
| 258 |
|
break; |
| 259 |
|
case DTfloat: |
| 260 |
+ |
dnew->swapin = dinfo.swapin; |
| 261 |
|
if (!rmx_load_float(dnew, fp)) |
| 262 |
|
goto loaderr; |
| 263 |
|
dnew->dtype = DTfloat; |
| 264 |
|
break; |
| 265 |
|
case DTdouble: |
| 266 |
+ |
dnew->swapin = dinfo.swapin; |
| 267 |
|
if (!rmx_load_double(dnew, fp)) |
| 268 |
|
goto loaderr; |
| 269 |
|
dnew->dtype = DTdouble; |
| 405 |
|
return(0); |
| 406 |
|
rm = mydm; |
| 407 |
|
} |
| 408 |
+ |
if ((dtype == DTfloat) | (dtype == DTdouble)) |
| 409 |
+ |
fputendian(fp); /* important to record */ |
| 410 |
|
fputformat((char *)cm_fmt_id[dtype], fp); |
| 411 |
|
fputc('\n', fp); |
| 412 |
|
switch (dtype) { /* write data */ |
| 580 |
|
rmx_lval(m1,i,j,k) *= rmx_lval(m2,i,j,k); |
| 581 |
|
} |
| 582 |
|
if (zeroDivides) { |
| 583 |
< |
fputs("Divide by zero in rmx_elemult()\n", stderr); |
| 583 |
> |
rmx_addinfo(m1, "WARNING: zero divide(s) corrupted results\n"); |
| 584 |
|
errno = ERANGE; |
| 585 |
|
} |
| 586 |
|
return(1); |
| 652 |
|
return(NULL); |
| 653 |
|
if (msrc->info) { |
| 654 |
|
char buf[128]; |
| 655 |
< |
sprintf(buf, "Applied %dx%d matrix transform\n", |
| 655 |
> |
sprintf(buf, "Applied %dx%d component transform\n", |
| 656 |
|
dnew->ncomp, msrc->ncomp); |
| 657 |
|
rmx_addinfo(dnew, msrc->info); |
| 658 |
|
rmx_addinfo(dnew, buf); |