--- ray/src/util/rmatrix.c 2023/12/06 17:57:34 2.73 +++ ray/src/util/rmatrix.c 2024/02/29 03:11:13 2.78 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rmatrix.c,v 2.73 2023/12/06 17:57:34 greg Exp $"; +static const char RCSid[] = "$Id: rmatrix.c,v 2.78 2024/02/29 03:11:13 greg Exp $"; #endif /* * General matrix operations. @@ -393,8 +393,10 @@ rmx_load(const char *inspec, RMPref rmp) } /* else open it ourselves */ fp = fopen(inspec, "r"); } - if (!fp) + if (!fp) { + fprintf(stderr, "Cannot open for reading: %s\n", inspec); return(NULL); + } #ifdef getc_unlocked flockfile(fp); #endif @@ -499,7 +501,7 @@ rmx_write_spec(const double *dp, int nc, int len, FILE if (nc < 3) return(0); scan = (uby8 *)tempbuffer((nc+1)*len); if (!scan) return(0); - for (j = len; j--; dp += nc) { + for (j = 0; j < len; j++, dp += nc) { for (k = nc; k--; ) scol[k] = dp[k]; scolor2scolr(scan+j*(nc+1), scol, nc); @@ -539,7 +541,9 @@ rmx_write_header(const RMATRIX *rm, int dtype, FILE *f dtype = DTxyze; else if ((dtype == DTxyze) & (rm->dtype == DTrgbe)) dtype = DTrgbe; - if ((dtype == DTspec) & (rm->ncomp < 3)) + if ((dtype < DTspec) & (rm->ncomp > 3)) + dtype = DTspec; + else if ((dtype == DTspec) & (rm->ncomp <= 3)) return(0); if (dtype == DTascii) /* set file type (WINDOWS) */ @@ -560,8 +564,8 @@ rmx_write_header(const RMATRIX *rm, int dtype, FILE *f } if (dtype >= DTspec) { /* # components & split? */ fputncomp(rm->ncomp, fp); - if (dtype == DTspec || (rm->ncomp > 3 && - memcmp(rm->wlpart, WLPART, sizeof(WLPART)))) + if (rm->ncomp > 3 && + memcmp(rm->wlpart, WLPART, sizeof(WLPART))) fputwlsplit(rm->wlpart, fp); } else if ((rm->ncomp != 3) & (rm->ncomp != 1)) return(0); /* wrong # components */ @@ -683,12 +687,16 @@ rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int do rsrc->info = NULL; rsrc->mapped = NULL; rsrc->mtx = NULL; return(1); } +#ifdef MAP_FILE /* just matrix data -- leave metadata */ if (rdst->mapped) - return(0); /* XXX can't handle this case */ - /* just matrix data -- leave metadata */ - if (rdst->mtx) free(rdst->mtx); + munmap(rdst->mapped, mapped_size(rdst)); + else +#endif + if (rdst->mtx) + free(rdst->mtx); + rdst->mapped = rsrc->mapped; rdst->mtx = rsrc->mtx; - rsrc->mtx = NULL; + rsrc->mapped = NULL; rsrc->mtx = NULL; return(1); }