6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdlib.h> |
9 |
– |
#include <string.h> |
9 |
|
#include <ctype.h> |
10 |
|
#include "platform.h" |
11 |
|
#include "rtio.h" |
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; |
395 |
|
else /* XXX should never happen! */ |
396 |
< |
n = (long)r*ni_columns + c; |
396 |
> |
n = (long)r*no_columns + c; |
397 |
|
return(n); |
398 |
|
} |
399 |
|
|
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 |
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 |
– |
if ((no_rows != ni_rows) | (no_columns != ni_columns)) |
450 |
– |
goto badspec; |
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); |