| 107 |
|
return(i); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
+ |
/* adjust matrix dimensions according to user size(s) */ |
| 111 |
+ |
static int |
| 112 |
+ |
alt_dim(CMATRIX *cm, int nr, int nc) |
| 113 |
+ |
{ |
| 114 |
+ |
if ((nr <= 0) & (nc <= 0)) |
| 115 |
+ |
return(0); |
| 116 |
+ |
if ((nr == cm->nrows) & (nc == cm->ncols)) |
| 117 |
+ |
return(0); |
| 118 |
+ |
if (nr > 0) { |
| 119 |
+ |
if (nc <= 0) |
| 120 |
+ |
nc = cm->nrows*cm->ncols/nr; |
| 121 |
+ |
if (nr*nc != cm->nrows*cm->ncols) { |
| 122 |
+ |
fprintf(stderr, "Bad dimensions: %dx%d != %dx%d\n", |
| 123 |
+ |
nr, nc, cm->nrows, cm->ncols); |
| 124 |
+ |
return(-1); |
| 125 |
+ |
} |
| 126 |
+ |
} else /* nc > 0 */ { |
| 127 |
+ |
nr = cm->nrows*cm->ncols/nc; |
| 128 |
+ |
if (nc*nr != cm->nrows*cm->ncols) { |
| 129 |
+ |
fprintf(stderr, "Bad dimensions: %d does not divide %dx%d evenly\n", |
| 130 |
+ |
nc, cm->nrows, cm->ncols); |
| 131 |
+ |
return(-1); |
| 132 |
+ |
} |
| 133 |
+ |
} |
| 134 |
+ |
cm->nrows = nr; |
| 135 |
+ |
cm->ncols = nc; |
| 136 |
+ |
return(1); |
| 137 |
+ |
} |
| 138 |
+ |
|
| 139 |
|
/* check to see if a string contains a %d or %o specification */ |
| 140 |
|
static int |
| 141 |
|
hasNumberFormat(const char *s) |
| 325 |
|
const char *wtype = (outfmt==DTascii) ? "w" : "wb"; |
| 326 |
|
for (i = 0; i < nsteps; i++) { |
| 327 |
|
CMATRIX *rvec = cm_column(rmtx, i); |
| 328 |
< |
if (yres > 0) { |
| 329 |
< |
if (xres <= 0) |
| 301 |
< |
xres = rvec->nrows/yres; |
| 302 |
< |
if (xres*yres != rvec->nrows) { |
| 303 |
< |
fprintf(stderr, "Bad resolution: %d != %dx%d\n", |
| 304 |
< |
rvec->nrows, xres, yres); |
| 305 |
< |
return(1); |
| 306 |
< |
} |
| 307 |
< |
rvec->nrows = yres; |
| 308 |
< |
rvec->ncols = xres; |
| 309 |
< |
} else if (xres > 0) { |
| 310 |
< |
yres = rvec->nrows/xres; |
| 311 |
< |
if (xres*yres != rvec->nrows) { |
| 312 |
< |
fprintf(stderr, |
| 313 |
< |
"Bad resolution: %d does not divide %d evenly\n", |
| 314 |
< |
xres, rvec->nrows); |
| 315 |
< |
return(1); |
| 316 |
< |
} |
| 317 |
< |
rvec->nrows = yres; |
| 318 |
< |
rvec->ncols = xres; |
| 319 |
< |
} |
| 328 |
> |
if (alt_dim(rvec, yres, xres) < 0) |
| 329 |
> |
return(1); |
| 330 |
|
sprintf(fnbuf, ofspec, i); |
| 331 |
|
if ((ofp = fopen(fnbuf, wtype)) == NULL) { |
| 332 |
|
fprintf(stderr, |
| 368 |
|
#endif |
| 369 |
|
if (outfmt != DTascii) |
| 370 |
|
SET_FILE_BINARY(ofp); |
| 371 |
+ |
if (alt_dim(rmtx, yres, xres) < 0) |
| 372 |
+ |
return(1); |
| 373 |
|
if (headout) { /* header output */ |
| 374 |
|
newheader("RADIANCE", ofp); |
| 375 |
|
printargs(argc, argv, ofp); |