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.32 by greg, Fri Nov 8 05:39:05 2019 UTC vs.
Revision 2.35 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 6 | Line 6 | static const char RCSid[] = "$Id$";
6   */
7  
8   #include <stdlib.h>
9 #include <string.h>
9   #include <ctype.h>
10   #include "platform.h"
11   #include "rtio.h"
# Line 387 | Line 386 | get_input_pos(int r, int c)
386          if (outLevels > 1) {            /* block reordering */
387                  n = get_block_pos(r, c, outArray, outLevels);
388                  if (transpose) {
389 <                        r = n/no_columns;
390 <                        c = n - r*no_columns;
391 <                        n = (long)r*ni_columns + c;
389 >                        r = n/ni_rows;
390 >                        c = n - r*ni_rows;
391 >                        n = (long)c*ni_columns + r;
392                  }
393          } else if (transpose)           /* transpose only */
394                  n = (long)c*ni_columns + r;
# Line 421 | Line 420 | do_reorder(const MEMLOAD *mp)
420          } else if ((ni_rows > 0) & (ni_columns > 0)) {
421                  nrecords = ni_rows*ni_columns;
422                  if (nrecords > mp->len/(n_comp*comp_size)) {
423 <                        fprintf(stderr,
424 <                            "Input too small for specified size and type\n");
423 >                        fputs("Input too small for specified size and type\n",
424 >                                        stderr);
425                          return(0);
426                  }
427          } else
# Line 439 | Line 438 | do_reorder(const MEMLOAD *mp)
438                          no_columns = ni_rows;
439                  if (no_rows <= 0)
440                          no_rows = ni_columns;
441 <                if ((no_rows != ni_columns) | (no_columns != ni_rows))
441 >                if (outLevels <= 1 &&
442 >                                (no_rows != ni_columns) | (no_columns != ni_rows))
443                          goto badspec;
444 +        } else {
445 +                if (no_columns <= 0)
446 +                        no_columns = ni_columns;
447 +                if (no_rows <= 0)
448 +                        no_rows = ni_rows;
449          }
450 +        if (ni_rows*ni_columns != no_rows*no_columns) {
451 +                fputs("Number of input and output records do not match\n",
452 +                                stderr);
453 +                return(0);
454 +        }
455                                                  /* reorder records */
456          for (i = 0; i < no_rows; i++) {
457              for (j = 0; j < no_columns; j++) {
458                  long    n = get_input_pos(i, j);
459 +                if (n >= nrecords) {
460 +                        fputs("Index past end-of-file\n", stderr);
461 +                        return(0);
462 +                }
463                  if (rp != NULL) {               /* ASCII output */
464                          print_record(rp, n);
465                          putc(tabEOL[j >= no_columns-1], stdout);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines