--- ray/src/util/rmatrix.c 2015/05/04 20:53:21 2.13 +++ ray/src/util/rmatrix.c 2015/08/27 04:07:05 2.18 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rmatrix.c,v 2.13 2015/05/04 20:53:21 greg Exp $"; +static const char RCSid[] = "$Id: rmatrix.c,v 2.18 2015/08/27 04:07:05 greg Exp $"; #endif /* * General matrix operations. @@ -10,6 +10,7 @@ static const char RCSid[] = "$Id: rmatrix.c,v 2.13 201 #include #include #include "resolu.h" +#include "rtprocess.h" #include "rmatrix.h" static char rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; @@ -46,7 +47,9 @@ rmx_free(RMATRIX *rm) int rmx_newtype(int dtyp1, int dtyp2) { - if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) && dtyp1 != dtyp2) + if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) | + (dtyp2==DTxyze) | (dtyp2==DTrgbe) + && dtyp1 != dtyp2) return(0); if (dtyp1 < dtyp2) return(dtyp1); @@ -108,9 +111,7 @@ static int rmx_load_ascii(RMATRIX *rm, FILE *fp) { int i, j, k; -#ifdef _WIN32 - _setmode(fileno(fp), _O_TEXT); -#endif + for (i = 0; i < rm->nrows; i++) for (j = 0; j < rm->ncols; j++) for (k = 0; k < rm->ncomp; k++) @@ -213,6 +214,7 @@ rmx_load(const char *inspec) return(NULL); dnew = rmx_from_cmatrix(cm); cm_free(cm); + dnew->dtype = DTascii; return(dnew); } /* else open it ourselves */ @@ -250,6 +252,9 @@ rmx_load(const char *inspec) dnew->info = dinfo.info; switch (dinfo.dtype) { case DTascii: +#ifdef _WIN32 + _setmode(fileno(fp), _O_TEXT); +#endif if (!rmx_load_ascii(dnew, fp)) goto loaderr; dnew->dtype = DTascii; /* should leave double? */ @@ -297,9 +302,7 @@ static int rmx_write_ascii(const RMATRIX *rm, FILE *fp) { int i, j, k; -#ifdef _WIN32 - _setmode(fileno(fp), _O_TEXT); -#endif + for (i = 0; i < rm->nrows; i++) { for (j = 0; j < rm->ncols; j++) { for (k = 0; k < rm->ncomp; k++) @@ -382,6 +385,9 @@ rmx_write(const RMATRIX *rm, int dtype, FILE *fp) if ((rm == NULL) | (fp == NULL)) return(0); +#ifdef getc_unlocked + flockfile(fp); +#endif /* complete header */ if (rm->info) fputs(rm->info, fp); @@ -426,6 +432,9 @@ rmx_write(const RMATRIX *rm, int dtype, FILE *fp) return(0); } ok &= (fflush(fp) == 0); +#ifdef getc_unlocked + funlockfile(fp); +#endif rmx_free(mydm); return(ok); } @@ -511,8 +520,7 @@ rmx_multiply(const RMATRIX *m1, const RMATRIX *m2) for (k = mres->ncomp; k--; ) { long double d = 0; for (h = m1->ncols; h--; ) - d += (long double)rmx_lval(m1,i,h,k) * - (long double)rmx_lval(m2,h,j,k); + d += rmx_lval(m1,i,h,k) * rmx_lval(m2,h,j,k); rmx_lval(mres,i,j,k) = (double)d; } return(mres);