--- ray/src/util/rcollate.c 2014/05/30 16:50:43 2.10 +++ ray/src/util/rcollate.c 2014/05/30 18:10:20 2.12 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcollate.c,v 2.10 2014/05/30 16:50:43 greg Exp $"; +static const char RCSid[] = "$Id: rcollate.c,v 2.12 2014/05/30 18:10:20 greg Exp $"; #endif /* * Utility to re-order records in a binary or ASCII data file (matrix) @@ -276,7 +276,7 @@ int no_columns = 0; /* number of output columns */ int no_rows = 0; /* number of output rows */ /* check settings and assign defaults */ -static void +static int check_sizes() { if (fmtid == NULL) { @@ -288,9 +288,14 @@ check_sizes() comp_size = sizeof(double); else if (!strcmp(fmtid, "byte")) comp_size = 1; + else { + fprintf(stderr, "Unsupported format: %s\n", fmtid); + return(0); + } } if (n_comp <= 0) n_comp = 3; + return(1); } /* output transposed ASCII or binary data from memory */ @@ -367,10 +372,8 @@ do_resize(FILE *fp) int columns2go = no_columns; char word[256]; /* sanity checks */ - if (comp_size) { - fputs("Bad call to do_resize (binary input)\n", stderr); - return(0); - } + if (comp_size) + return(output_stream(fp)); /* binary data -- just copy */ if (no_columns <= 0) { fprintf(stderr, "Missing -oc specification\n"); return(0); @@ -561,7 +564,7 @@ main(int argc, char *argv[]) SET_FILE_BINARY(stdout); } /* check for no-op */ - if (!transpose && (comp_size || + if (!transpose & (i_header == o_header) && (comp_size || (no_columns == ni_columns) & (no_rows == ni_rows))) { if (warnings) fprintf(stderr, "%s: no-op -- copying input verbatim\n", @@ -573,13 +576,14 @@ main(int argc, char *argv[]) if (i_header) { /* read header */ if (getheader(stdin, &headline, NULL) < 0) return(1); - check_sizes(); + if (!check_sizes()) + return(1); if (comp_size) { /* a little late... */ SET_FILE_BINARY(stdin); SET_FILE_BINARY(stdout); } - } else - check_sizes(); + } else if (!check_sizes()) + return(1); if (o_header) { /* write header */ printargs(argc, argv, stdout); if (transpose && (no_rows <= 0) & (no_columns <= 0)) {