292 |
|
fputs("Unrecognized matrix format\n", stderr); |
293 |
|
return(0); |
294 |
|
} |
295 |
< |
/* resolution string? */ |
296 |
< |
if ((rm->nrows <= 0) | (rm->ncols <= 0)) { |
297 |
< |
if (!fscnresolu(&rm->ncols, &rm->nrows, fp)) |
298 |
< |
return(0); |
299 |
< |
if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) && |
300 |
< |
rm->ncomp != 3) |
301 |
< |
return(0); |
302 |
< |
} |
303 |
< |
if (rm->dtype == DTascii) /* set input type (WINDOWS) */ |
295 |
> |
if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) && |
296 |
> |
rm->ncomp != 3) |
297 |
> |
return(0); |
298 |
> |
if (rm->ncols <= 0 && /* resolution string? */ |
299 |
> |
!fscnresolu(&rm->ncols, &rm->nrows, fp)) |
300 |
> |
return(0); |
301 |
> |
if (rm->dtype == DTascii) /* set file type (WINDOWS) */ |
302 |
|
SET_FILE_TEXT(fp); |
303 |
|
else |
304 |
|
SET_FILE_BINARY(fp); |
525 |
|
int |
526 |
|
rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp) |
527 |
|
{ |
528 |
< |
if (!rm | !fp || !rm->mtx) |
528 |
> |
if (!rm | !fp || !rm->mtx | (rm->ncols <= 0)) |
529 |
|
return(0); |
530 |
|
if (rm->info) |
531 |
|
fputs(rm->info, fp); |
536 |
|
dtype = DTxyze; |
537 |
|
else if ((dtype == DTxyze) & (rm->dtype == DTrgbe)) |
538 |
|
dtype = DTrgbe; |
539 |
+ |
if ((dtype == DTspec) & (rm->ncomp < 3)) |
540 |
+ |
return(0); |
541 |
|
|
542 |
< |
if (dtype == DTascii) /* set output type (WINDOWS) */ |
542 |
> |
if (dtype == DTascii) /* set file type (WINDOWS) */ |
543 |
|
SET_FILE_TEXT(fp); |
544 |
|
else |
545 |
|
SET_FILE_BINARY(fp); |
549 |
|
fputcolcor(rm->cexp, fp); |
550 |
|
else if (rm->cexp[GRN] != 1.f) |
551 |
|
fputexpos(rm->cexp[GRN], fp); |
552 |
< |
if ((dtype != DTrgbe) & (dtype != DTxyze)) { |
553 |
< |
if (dtype != DTspec) { |
552 |
> |
/* matrix size? */ |
553 |
> |
if ((dtype > DTspec) | (rm->nrows <= 0)) { |
554 |
> |
if (rm->nrows > 0) |
555 |
|
fprintf(fp, "NROWS=%d\n", rm->nrows); |
556 |
< |
fprintf(fp, "NCOLS=%d\n", rm->ncols); |
557 |
< |
} else if (rm->ncomp < 3) |
558 |
< |
return(0); /* bad # components */ |
556 |
> |
fprintf(fp, "NCOLS=%d\n", rm->ncols); |
557 |
> |
} |
558 |
> |
if (dtype >= DTspec) { /* # components & split? */ |
559 |
|
fputncomp(rm->ncomp, fp); |
560 |
|
if (dtype == DTspec || (rm->ncomp > 3 && |
561 |
|
memcmp(rm->wlpart, WLPART, sizeof(WLPART)))) |
566 |
|
fputendian(fp); /* important to record */ |
567 |
|
fputformat(cm_fmt_id[dtype], fp); |
568 |
|
fputc('\n', fp); /* end of header */ |
569 |
< |
if (dtype <= DTspec) |
569 |
> |
if ((dtype <= DTspec) & (rm->nrows > 0)) |
570 |
|
fprtresolu(rm->ncols, rm->nrows, fp); |
571 |
|
return(dtype); |
572 |
|
} |