6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdlib.h> |
9 |
– |
#include <string.h> |
9 |
|
#include <ctype.h> |
10 |
|
#include "platform.h" |
11 |
|
#include "rtio.h" |
293 |
|
int o_header = 1; /* output header? */ |
294 |
|
int outArray[MAXLEVELS][2]; /* output block nesting */ |
295 |
|
int outLevels = 0; /* number of blocking levels */ |
296 |
+ |
int check = 0; /* force data check? */ |
297 |
|
|
298 |
|
/* parse RxCx... string */ |
299 |
|
static int |
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; |
408 |
|
int i, j; |
409 |
|
/* propogate sizes */ |
410 |
|
if (ni_rows <= 0) |
411 |
< |
ni_rows = no_columns; |
411 |
> |
ni_rows = transpose ? no_columns : no_rows; |
412 |
|
if (ni_columns <= 0) |
413 |
< |
ni_columns = no_rows; |
413 |
> |
ni_columns = transpose ? no_rows : no_columns; |
414 |
|
/* get # records (& index) */ |
415 |
|
if (!comp_size) { |
416 |
|
if ((rp = index_records(mp, n_comp)) == NULL) |
430 |
|
/* check sizes */ |
431 |
|
if ((ni_rows <= 0) & (ni_columns > 0)) |
432 |
|
ni_rows = nrecords/ni_columns; |
433 |
< |
if ((ni_columns <= 0) & (ni_rows > 0)) |
433 |
> |
else if ((ni_columns <= 0) & (ni_rows > 0)) |
434 |
|
ni_columns = nrecords/ni_rows; |
435 |
|
if (nrecords != ni_rows*ni_columns) |
436 |
|
goto badspec; |
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) |
453 |
|
stderr); |
454 |
|
return(0); |
455 |
|
} |
456 |
+ |
if (o_header) { /* finish header? */ |
457 |
+ |
printf("NROWS=%d\n", no_rows); |
458 |
+ |
printf("NCOLS=%d\n", no_columns); |
459 |
+ |
fputc('\n', stdout); |
460 |
+ |
} |
461 |
|
/* reorder records */ |
462 |
|
for (i = 0; i < no_rows; i++) { |
463 |
|
for (j = 0; j < no_columns; j++) { |
494 |
|
long records2go = ni_rows*ni_columns; |
495 |
|
int columns2go = no_columns; |
496 |
|
char word[256]; |
497 |
+ |
|
498 |
+ |
if (o_header) { /* finish header? */ |
499 |
+ |
if (no_rows > 0) |
500 |
+ |
printf("NROWS=%d\n", no_rows); |
501 |
+ |
if (no_columns > 0) |
502 |
+ |
printf("NCOLS=%d\n", no_columns); |
503 |
+ |
fputc('\n', stdout); |
504 |
+ |
} |
505 |
|
/* sanity checks */ |
506 |
< |
if (comp_size || (no_columns == ni_columns) & (no_rows == ni_rows)) |
506 |
> |
if (comp_size || !check & |
507 |
> |
(no_columns == ni_columns) & (no_rows == ni_rows)) |
508 |
|
return(output_stream(fp)); /* no-op -- just copy */ |
509 |
|
if (no_columns <= 0) { |
510 |
|
fprintf(stderr, "Missing -oc specification\n"); |
514 |
|
records2go = no_rows*no_columns; |
515 |
|
else if (no_rows*no_columns != records2go) { |
516 |
|
fprintf(stderr, |
517 |
< |
"Input and output data sizes disagree (%dx%d != %dx%d)\n", |
517 |
> |
"Number of input and output records disagree (%dx%d != %dx%d)\n", |
518 |
|
ni_rows, ni_columns, no_rows, no_columns); |
519 |
|
return(0); |
520 |
|
} |
681 |
|
case 'w': /* warnings on/off */ |
682 |
|
warnings = !warnings; |
683 |
|
break; |
684 |
+ |
case 'c': /* force check operation */ |
685 |
+ |
check = 1; |
686 |
+ |
break; |
687 |
|
default: |
688 |
|
goto userr; |
689 |
|
} |
703 |
|
SET_FILE_BINARY(stdout); |
704 |
|
} |
705 |
|
/* check for no-op */ |
706 |
< |
if (!transpose & (outLevels <= 1) & (i_header == o_header) && |
706 |
> |
if (!transpose & !check & (outLevels <= 1) & (i_header == o_header) && |
707 |
|
(no_columns == ni_columns) & (no_rows == ni_rows)) { |
708 |
|
if (warnings) |
709 |
|
fprintf(stderr, "%s: no-op -- copying input verbatim\n", |
727 |
|
if (!i_header) |
728 |
|
newheader("RADIANCE", stdout); |
729 |
|
printargs(a, argv, stdout); |
712 |
– |
if (no_rows > 0) |
713 |
– |
printf("NROWS=%d\n", no_rows); |
714 |
– |
if (no_columns > 0) |
715 |
– |
printf("NCOLS=%d\n", no_columns); |
730 |
|
printf("NCOMP=%d\n", n_comp); |
731 |
|
fputformat(fmtid, stdout); |
718 |
– |
fputc('\n', stdout); /* finish new header */ |
732 |
|
} |
733 |
< |
if (transpose | (outLevels > 1)) { /* moving stuff around? */ |
733 |
> |
if (transpose | check | (outLevels > 1) || (o_header && no_rows <= 0)) { |
734 |
|
MEMLOAD myMem; /* need to map into memory */ |
735 |
|
if (a == argc-1) { |
736 |
|
if (load_file(&myMem, stdin) <= 0) { |
746 |
|
if (!do_reorder(&myMem)) |
747 |
|
return(1); |
748 |
|
/* free_load(&myMem); about to exit, so don't bother */ |
749 |
< |
} else if (!do_resize(stdin)) /* reshaping input */ |
749 |
> |
} else if (!do_resize(stdin)) /* just reshaping input */ |
750 |
|
return(1); |
751 |
|
return(0); |
752 |
|
userr: |
753 |
|
fprintf(stderr, |
754 |
< |
"Usage: %s [-h[io]][-w][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row][-o RxC[xR1xC1..]] [input.dat]\n", |
754 |
> |
"Usage: %s [-h[io]][-w][-c][-f[afdb][N]][-t][-ic in_col][-ir in_row][-oc out_col][-or out_row][-o RxC[xR1xC1..]] [input.dat]\n", |
755 |
|
argv[0]); |
756 |
|
return(1); |
757 |
|
} |