/* img_ship_mask anyfile.img -S > maskedfile.img */ #include "img_predict.h" int main (int argc, char **argv) { short int *x, y; int i, nx, ny, n; char *ufile = NULL, *sfile = NULL; FILE *fp; n = 0; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { switch (argv[i][1]) { case 'S': sfile = &argv[i][2]; break; default: n++; } } else { ufile = argv[i]; } } if (n || (ufile == NULL) || (sfile == NULL) ) { fprintf (stderr, "usage: img_ship_mask -S > maskedfile.img\n"); fprintf (stderr, "\t-S has odd numbers at constraints and even where not constrained.\n"); fprintf (stderr, "\t is any input file, e.g. hipassed_topo.img\n"); fprintf (stderr, "\tOutput is input anyfile with 9999 where is not negative and odd.\n"); exit (-1); } if (check_imgfile_size (sfile, &nx, &ny) ) { fprintf (stderr, "img_ship_mask: 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_mask: FATAL ERROR. Cannot malloc %d bytes\n", 2*n); exit (EXIT_FAILURE); } if ( (fp = fopen(sfile, "r") ) == NULL) { fprintf (stderr, "img_ship_mask: 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_mask: FATAL ERROR reading %s\n", sfile); exit (-1); } fclose (fp); if ( (fp = fopen(ufile, "r") ) == NULL) { fprintf (stderr, "img_ship_mask: 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_mask: FATAL ERROR reading i = %d from %s\n", i, ufile); exit (-1); } if (x[i] < 0 && (abs((int)x[i]))%2 == 1) { /* This point is odd and below zero. */ x[i] = y; } else { x[i] = 9999; } } fclose (fp); if ( (fwrite( (void *)x, (size_t)2, (size_t)n, stdout) ) != n) { fprintf (stderr, "img_ship_mask: FATAL ERROR writing diff to stdout\n"); exit (-1); } free ((void *)x); exit (EXIT_SUCCESS); }