374 |
|
fp = stdin; |
375 |
|
else if (inspec[0] == '!') |
376 |
|
fp = popen(inspec+1, "r"); |
377 |
< |
else if (rmp != RMPnone) { |
377 |
> |
else { |
378 |
|
const char *sp = inspec; /* check suffix */ |
379 |
|
while (*sp) |
380 |
|
++sp; |
381 |
|
while (sp > inspec && sp[-1] != '.') |
382 |
|
--sp; |
383 |
|
if (!strcasecmp(sp, "XML")) { /* assume it's a BSDF */ |
384 |
< |
CMATRIX *cm = rmp==RMPtrans ? cm_loadBTDF(inspec) : |
384 |
> |
CMATRIX *cm = rmp==RMPnone ? (CMATRIX *)NULL : |
385 |
> |
rmp==RMPtrans ? cm_loadBTDF(inspec) : |
386 |
|
cm_loadBRDF(inspec, rmp==RMPreflB) ; |
387 |
|
if (!cm) |
388 |
|
return(NULL); |
393 |
|
} /* else open it ourselves */ |
394 |
|
fp = fopen(inspec, "r"); |
395 |
|
} |
396 |
< |
if (!fp) |
396 |
> |
if (!fp) { |
397 |
> |
fprintf(stderr, "Cannot open for reading: %s\n", inspec); |
398 |
|
return(NULL); |
399 |
+ |
} |
400 |
|
#ifdef getc_unlocked |
401 |
|
flockfile(fp); |
402 |
|
#endif |
452 |
|
{ |
453 |
|
while (len-- > 0) { |
454 |
|
int k = nc; |
455 |
< |
while (nc-- > 0) |
455 |
> |
while (k-- > 0) |
456 |
|
fprintf(fp, " %.7e", *dp++); |
457 |
|
fputc('\t', fp); |
458 |
|
} |
541 |
|
dtype = DTxyze; |
542 |
|
else if ((dtype == DTxyze) & (rm->dtype == DTrgbe)) |
543 |
|
dtype = DTrgbe; |
544 |
< |
if ((dtype == DTspec) & (rm->ncomp < 3)) |
544 |
> |
if ((dtype < DTspec) & (rm->ncomp > 3)) |
545 |
> |
dtype = DTspec; |
546 |
> |
else if ((dtype == DTspec) & (rm->ncomp <= 3)) |
547 |
|
return(0); |
548 |
|
|
549 |
|
if (dtype == DTascii) /* set file type (WINDOWS) */ |
564 |
|
} |
565 |
|
if (dtype >= DTspec) { /* # components & split? */ |
566 |
|
fputncomp(rm->ncomp, fp); |
567 |
< |
if (dtype == DTspec || (rm->ncomp > 3 && |
568 |
< |
memcmp(rm->wlpart, WLPART, sizeof(WLPART)))) |
567 |
> |
if (rm->ncomp > 3 && |
568 |
> |
memcmp(rm->wlpart, WLPART, sizeof(WLPART))) |
569 |
|
fputwlsplit(rm->wlpart, fp); |
570 |
|
} else if ((rm->ncomp != 3) & (rm->ncomp != 1)) |
571 |
|
return(0); /* wrong # components */ |
670 |
|
copycolor(dnew->cexp, rm->cexp); |
671 |
|
memcpy(dnew->wlpart, rm->wlpart, sizeof(dnew->wlpart)); |
672 |
|
return(dnew); |
673 |
+ |
} |
674 |
+ |
|
675 |
+ |
/* Replace data in first matrix with data from second */ |
676 |
+ |
int |
677 |
+ |
rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int dometa) |
678 |
+ |
{ |
679 |
+ |
if (!rdst | !rsrc || (rdst->nrows != rsrc->nrows) | |
680 |
+ |
(rdst->ncols != rsrc->ncols) | |
681 |
+ |
(rdst->ncomp != rsrc->ncomp)) |
682 |
+ |
return(0); |
683 |
+ |
|
684 |
+ |
if (dometa) { /* transfer everything? */ |
685 |
+ |
rmx_reset(rdst); |
686 |
+ |
*rdst = *rsrc; |
687 |
+ |
rsrc->info = NULL; rsrc->mapped = NULL; rsrc->mtx = NULL; |
688 |
+ |
return(1); |
689 |
+ |
} |
690 |
+ |
#ifdef MAP_FILE /* just matrix data -- leave metadata */ |
691 |
+ |
if (rdst->mapped) |
692 |
+ |
munmap(rdst->mapped, mapped_size(rdst)); |
693 |
+ |
else |
694 |
+ |
#endif |
695 |
+ |
if (rdst->mtx) |
696 |
+ |
free(rdst->mtx); |
697 |
+ |
rdst->mapped = rsrc->mapped; |
698 |
+ |
rdst->mtx = rsrc->mtx; |
699 |
+ |
rsrc->mapped = NULL; rsrc->mtx = NULL; |
700 |
+ |
return(1); |
701 |
|
} |
702 |
|
|
703 |
|
/* Allocate and assign transposed matrix */ |