/* img_ship_diff -U -S -O > pointdiff.dat */ #include "img_predict.h" int main (int argc, char **argv) { short int *x, y; int i, nx, ny, n, ax, goes_out; char *ufile = NULL, *sfile = NULL, *ofile = NULL; FILE *fp; n = 0; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'U': ufile = &argv[i][2]; break; case 'S': sfile = &argv[i][2]; break; case 'O': ofile = &argv[i][2]; break; default: n++; } } else { n++; } } if (n || (ufile == NULL) || (sfile == NULL) || (ofile == NULL) ) { fprintf (stderr, "usage: img_ship_diff -U -S -O > pointdiff.dat\n"); exit (-1); } if (check_imgfile_size (sfile, &nx, &ny) ) { fprintf (stderr, "img_ship_diff: FATAL ERROR. Cannot understand size of %s\n", sfile); exit (EXIT_FAILURE); } n = nx * ny; if ( (x = (short int *) malloc ( (size_t) (2 * n) ) ) == NULL) { fprintf (stderr, "img_ship_diff: FATAL ERROR. Cannot malloc %d bytes\n", 2*n); exit (EXIT_FAILURE); } if ( (fp = fopen(sfile, "r") ) == NULL) { fprintf (stderr, "img_ship_diff: FATAL ERROR. Cannot open r %s\n", sfile); exit (-1); } if ( (fread ( (void *)x, (size_t)2, (size_t)n, fp) ) != n) { fprintf (stderr, "img_ship_diff: FATAL ERROR reading %s\n", sfile); exit (-1); } fclose (fp); if ( (fp = fopen(ufile, "r") ) == NULL) { fprintf (stderr, "img_ship_diff: FATAL ERROR. Cannot open r %s\n", ufile); exit (-1); } for (i = 0; i < n; i++) { if ( (fread ( (void *)&y, (size_t)2, (size_t)1, fp) ) != 1) { fprintf (stderr, "img_ship_diff: FATAL ERROR reading i = %d from %s\n", i, ufile); exit (-1); } goes_out = 0; if (x[i] < 0) { ax = abs((int)x[i]); if (ax%2 == 1) { x[i] -= y; goes_out = 1; } else { x[i] = 0; } } else { x[i] = 0; } if (goes_out) printf ("%d\n", (int)x[i]); } fclose (fp); if ( (fp = fopen(ofile, "w") ) == NULL) { fprintf (stderr, "img_ship_diff: FATAL ERROR. Cannot open w %s\n", ofile); exit (-1); } if ( (fwrite( (void *)x, (size_t)2, (size_t)n, fp) ) != n) { fprintf (stderr, "img_ship_diff: FATAL ERROR writing diff to stdout\n"); exit (-1); } fclose (fp); free ((void *)x); exit (EXIT_SUCCESS); }