/* imgbm_check_sea.c sealevel.bitmask < binary input > binary output * * Program to filter out ocean data within the land mask and eliminate * positive depths. * * Read and write 8-byte binary records consisting of two 4-byte ints; * the first is the index to the img pixel, and the second is the data value. * checks index against sea level mask and removes data in "ocean areas" * */ #include #include #define NX 10800 #define NY 6336 #define NMASK 8553600 /* NX * NY / 8 for bitmask */ struct IMGPAIR { int index; int depth; }; unsigned char mask[NMASK]; static unsigned char maskset[8] = {128, 64, 32, 16, 8, 4, 2, 1}; main(argc, argv) int argc; char **argv; { int i, j, n_in, n_out, n_edit; struct IMGPAIR imgpair; FILE *fp; if (argc <= 1) { fprintf(stderr,"usage: imgbm_check_sea sealevel.bitmask < > \n\n"); exit(-1); } if ( (fp = fopen(argv[1], "r")) == NULL) return(-1); if ( (fread(mask, 1, NMASK, fp)) != NMASK) return(-1); fclose(fp); n_in = 0; n_out = 0; n_edit = 0; while ( (fread((char *)&imgpair, sizeof(struct IMGPAIR), 1, stdin)) == 1) { n_in++; if (imgpair.index < 0 || imgpair.index >= 8*NMASK) { fprintf(stderr,"imgbm_check: bad index %d \n", imgpair.index); n_edit++; continue; } i = imgpair.index; if(!(mask[i/8] & maskset[i%8]) || imgpair.depth > -2 ){ if ( (fwrite((void *)&imgpair, sizeof(struct IMGPAIR), 1, stdout)) != 1) { fprintf(stderr,"imgbm_check: Write error.\n"); exit(-1); } n_out++; } else { /* fprintf(stderr," land area %d %d \n", imgpair.index, imgpair.depth); */ n_edit++; } } fprintf(stderr,"imgbm_check , read, wrote, edited %d %d %d\n", n_in,n_out,n_edit); exit(0); }