ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/cmatrix.c
(Generate patch)

Comparing ray/src/util/cmatrix.c (file contents):
Revision 2.31 by greg, Fri Jan 15 18:31:38 2021 UTC vs.
Revision 2.35 by greg, Wed Apr 27 01:31:56 2022 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
15   #include "paths.h"
16   #include "resolu.h"
17  
18 + const char      stdin_name[] = "<stdin>";
19 +
20   const char      *cm_fmt_id[] = {
21                          "unknown", COLRFMT, CIEFMT,
22                          "float", "ascii", "double"
# Line 212 | Line 214 | CMATRIX *
214   cm_load(const char *inspec, int nrows, int ncols, int dtype)
215   {
216          const int       ROWINC = 2048;
217 <        FILE            *fp = stdin;
217 >        int             rowsOK = (dtype == DTascii) | (nrows > 0);
218          int             swap = 0;
219 +        FILE            *fp;
220          COLOR           scale;
221          CMATRIX         *cm;
222  
223          if (!inspec)
224 <                inspec = "<stdin>";
225 <        else if (inspec[0] == '!') {
224 >                inspec = stdin_name;
225 >        else if (!*inspec)
226 >                return(NULL);
227 >        if (inspec == stdin_name) {             /* reading from stdin? */
228 >                fp = stdin;
229 >        } else if (inspec[0] == '!') {
230                  fp = popen(inspec+1, "r");
231                  if (!fp) {
232                          sprintf(errmsg, "cannot start command '%s'", inspec);
# Line 234 | Line 241 | cm_load(const char *inspec, int nrows, int ncols, int
241   #endif
242          if (dtype != DTascii)
243                  SET_FILE_BINARY(fp);            /* doesn't really work */
244 <        if (!dtype | !ncols) {                  /* expecting header? */
244 >        if (!dtype | !rowsOK | !ncols) {        /* expecting header? */
245                  char    *err = cm_getheader(&dtype, &nrows, &ncols, &swap, scale, fp);
246                  if (err)
247                          error(USER, err);
248 +                rowsOK = (nrows > 0);
249          }
250 <        if (ncols <= 0 && !fscnresolu(&ncols, &nrows, fp))
251 <                error(USER, "unspecified number of columns");
250 >        if (!rowsOK | !ncols && !fscnresolu(&ncols, &nrows, fp))
251 >                error(USER, "unspecified matrix size");
252          switch (dtype) {
253          case DTascii:
254          case DTfloat:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines