| 307 |
|
rmx_load_header(RMATRIX *rm, FILE *fp) |
| 308 |
|
{ |
| 309 |
|
if (!rm | !fp) |
| 310 |
< |
return(-1); |
| 310 |
> |
return(0); |
| 311 |
|
if (rm->info) { /* clear state */ |
| 312 |
|
free(rm->info); |
| 313 |
|
rm->info = NULL; |
| 327 |
|
rm->ncomp = 3; |
| 328 |
|
setcolor(rm->cexp, 1.f, 1.f, 1.f); |
| 329 |
|
memcpy(rm->wlpart, WLPART, sizeof(rm->wlpart)); |
| 330 |
+ |
rm->swapin = 0; |
| 331 |
|
} |
| 332 |
|
SET_FILE_BINARY(fp); |
| 333 |
|
rm->dtype = DTascii; /* assumed w/o FORMAT */ |
| 334 |
|
if (getheader(fp, get_dminfo, rm) < 0) { |
| 335 |
|
fputs("Unrecognized matrix format\n", stderr); |
| 336 |
< |
return(-1); |
| 336 |
> |
return(0); |
| 337 |
|
} |
| 338 |
|
/* resolution string? */ |
| 339 |
|
if ((rm->nrows <= 0) | (rm->ncols <= 0)) { |
| 340 |
|
if (!fscnresolu(&rm->ncols, &rm->nrows, fp)) |
| 341 |
< |
return(-1); |
| 341 |
> |
return(0); |
| 342 |
|
if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) && |
| 343 |
|
rm->ncomp != 3) |
| 344 |
< |
return(-1); |
| 344 |
> |
return(0); |
| 345 |
|
} |
| 346 |
< |
return(rm->dtype); |
| 346 |
> |
return(1); |
| 347 |
|
} |
| 348 |
|
|
| 349 |
|
/* Allocate & load post-header data from stream given type set in rm->dtype */ |
| 409 |
|
flockfile(fp); |
| 410 |
|
#endif |
| 411 |
|
/* load header info */ |
| 412 |
< |
if (rmx_load_header(dnew = rmx_new(0,0,3), fp) < 0) { |
| 412 |
> |
if (!rmx_load_header(dnew = rmx_new(0,0,3), fp)) { |
| 413 |
|
fprintf(stderr, "Bad header in: %s\n", inspec); |
| 414 |
|
if (inspec[0] == '!') pclose(fp); |
| 415 |
|
else fclose(fp); |
| 587 |
|
#ifdef getc_unlocked |
| 588 |
|
flockfile(fp); |
| 589 |
|
#endif |
| 590 |
< |
/* complete header */ |
| 590 |
< |
if (rm->info) |
| 590 |
> |
if (rm->info) /* complete header */ |
| 591 |
|
fputs(rm->info, fp); |
| 592 |
|
if (dtype == DTfromHeader) |
| 593 |
|
dtype = rm->dtype; |
| 603 |
|
else if (rm->cexp[GRN] != 1.f) |
| 604 |
|
fputexpos(rm->cexp[GRN], fp); |
| 605 |
|
if ((dtype != DTrgbe) & (dtype != DTxyze)) { |
| 606 |
< |
if (dtype == DTspec) { |
| 607 |
< |
if (rm->ncomp < 3) |
| 608 |
< |
return(0); /* bad # components */ |
| 609 |
< |
fputwlsplit(rm->wlpart, fp); |
| 610 |
< |
} else { |
| 606 |
> |
if (dtype != DTspec) { |
| 607 |
|
fprintf(fp, "NROWS=%d\n", rm->nrows); |
| 608 |
|
fprintf(fp, "NCOLS=%d\n", rm->ncols); |
| 609 |
< |
} |
| 609 |
> |
} else if (rm->ncomp < 3) |
| 610 |
> |
return(0); /* bad # components */ |
| 611 |
|
fputncomp(rm->ncomp, fp); |
| 612 |
+ |
if (dtype == DTspec || (rm->ncomp > 3 && |
| 613 |
+ |
memcmp(rm->wlpart, WLPART, sizeof(WLPART)))) |
| 614 |
+ |
fputwlsplit(rm->wlpart, fp); |
| 615 |
|
} else if ((rm->ncomp != 3) & (rm->ncomp != 1)) |
| 616 |
|
return(0); /* wrong # components */ |
| 617 |
|
if ((dtype == DTfloat) | (dtype == DTdouble)) |
| 618 |
|
fputendian(fp); /* important to record */ |
| 619 |
|
fputformat(cm_fmt_id[dtype], fp); |
| 620 |
< |
fputc('\n', fp); |
| 620 |
> |
fputc('\n', fp); /* end of header */ |
| 621 |
|
switch (dtype) { /* write data */ |
| 622 |
|
case DTascii: |
| 623 |
|
ok = rmx_write_ascii(rm, fp); |