/* image_sid.c Program to make an image of the source ID numbers of cruises. The incoming data are the block-medianed SID numbers. The output is a 2-byte integer image of SID numbers with a 0 in areas with no data */ #include #include #include #include #include #include "blockstat.h" /* Used for coordinate system definition */ struct IMGBM_SID { int index; int sid; }; int main (int argc, char **argv) { struct BM_CSYS coords; struct IMGBM_SID indat; double x, y; int coord_choice = -1; int i, j, k; int nerrs = 0; int nwords, val; unsigned short int *sid_image; for (k = 1; k < argc; k++) { if (argv[k][0] == '-') { switch (argv[k][1]) { case 'C': nerrs += ((sscanf(&argv[k][2], "%d", &coord_choice)) != 1); break; default: nerrs++; break; } } else { nerrs++; } } if (init_coords (&coords, coord_choice)) { fprintf (stderr, "You must set a coordinate system choice.\n"); nerrs++; } if (nerrs || (argc == 1) ) { fprintf (stderr, "usage: image_sid -C<#> < sid.bm > sid.img \n\n"); if (argc == 1) exit (EXIT_SUCCESS); fprintf (stderr, "\tUse -C<#> to set the block coordinate system, where <#> is one of:\n"); fprintf (stderr, "\t-C%d to select the SRTM30 (lon/lat, 30 arc sec, to +/- 90, pixel) system.\n", GTOPO30); fprintf (stderr, "\t-C%d to select the IMG1M72 (mercator, 1 arc min, to +/- 72.005977, pixel) system.\n", IMG1M72); fprintf (stderr, "\t-C%d to select the IMG1M81 (mercator, 1 arc min, to +/- 80.738009, pixel) system.\n", IMG1M81); fprintf (stderr, "\t-C%d to select the IMG2M72 (mercator, 2 arc min, to +/- 72.005977, pixel) system.\n", IMG2M72); fprintf (stderr, "\t-C%d to select the IMG2M81 (mercator, 2 arc min, to +/- 80.738009, pixel) system.\n\n", IMG2M81); exit (EXIT_FAILURE); } nwords = coords.ntot; /* All our coordinate systems have ntot elements in an image */ if ( (sid_image = calloc ((size_t)nwords, (size_t)2)) == NULL) { fprintf (stderr, "make_mask: Error. Failed to calloc %d bytes for the image.\n", nwords); exit (EXIT_FAILURE); } /* zero the image array */ for (i = 0, k = 0; i < nwords; i++) { *sid_image = 0; } /* read the sid data and add to image. the last one in wins. */ while (fread ((void *)&indat, 8, 1, stdin) == 1) { *(sid_image+indat.index) = (unsigned short int)indat.sid; } /* write the image */ fwrite ((void *) sid_image, (size_t)2, (size_t)nwords, stdout); free ((void *)sid_image); exit (EXIT_SUCCESS); }