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

Comparing ray/src/util/rcollate.c (file contents):
Revision 2.31 by greg, Fri Nov 8 02:10:38 2019 UTC vs.
Revision 2.34 by greg, Fri Nov 8 22:12:33 2019 UTC

# Line 387 | Line 387 | get_input_pos(int r, int c)
387          if (outLevels > 1) {            /* block reordering */
388                  n = get_block_pos(r, c, outArray, outLevels);
389                  if (transpose) {
390 <                        r = n/no_columns;
391 <                        c = n - r*no_columns;
392 <                        n = (long)r*ni_columns + c;
390 >                        r = n/ni_rows;
391 >                        c = n - r*ni_rows;
392 >                        n = (long)c*ni_columns + r;
393                  }
394          } else if (transpose)           /* transpose only */
395                  n = (long)c*ni_columns + r;
396          else                            /* XXX should never happen! */
397 <                n = (long)r*ni_columns + c;
397 >                n = (long)r*no_columns + c;
398          return(n);
399   }
400  
# Line 421 | Line 421 | do_reorder(const MEMLOAD *mp)
421          } else if ((ni_rows > 0) & (ni_columns > 0)) {
422                  nrecords = ni_rows*ni_columns;
423                  if (nrecords > mp->len/(n_comp*comp_size)) {
424 <                        fprintf(stderr,
425 <                            "Input too small for specified size and type\n");
424 >                        fputs("Input too small for specified size and type\n",
425 >                                        stderr);
426                          return(0);
427                  }
428          } else
# Line 439 | Line 439 | do_reorder(const MEMLOAD *mp)
439                          no_columns = ni_rows;
440                  if (no_rows <= 0)
441                          no_rows = ni_columns;
442 <                if ((no_rows != ni_columns) | (no_columns != ni_rows))
442 >                if (outLevels <= 1 &&
443 >                                (no_rows != ni_columns) | (no_columns != ni_rows))
444                          goto badspec;
445          } else {
446                  if (no_columns <= 0)
447                          no_columns = ni_columns;
448                  if (no_rows <= 0)
449                          no_rows = ni_rows;
449                if ((no_rows != ni_rows) | (no_columns != ni_columns))
450                        goto badspec;
450          }
451 +        if (ni_rows*ni_columns != no_rows*no_columns) {
452 +                fputs("Number of input and output records do not match\n",
453 +                                stderr);
454 +                return(0);
455 +        }
456                                                  /* reorder records */
457          for (i = 0; i < no_rows; i++) {
458              for (j = 0; j < no_columns; j++) {
459                  long    n = get_input_pos(i, j);
460 +                if (n >= nrecords) {
461 +                        fputs("Index past end-of-file\n", stderr);
462 +                        return(0);
463 +                }
464                  if (rp != NULL) {               /* ASCII output */
465                          print_record(rp, n);
466                          putc(tabEOL[j >= no_columns-1], stdout);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines