/* imghisteq.c * * Program to read a masked or unmasked v7.2 img file and dump cumulative * histogram in 5 mGal steps between -100 and +100 mGal. * * MODIFIED 9 July 1996 to comment out the track encoding. Also added * test for itest < 0, and shifted cumulative backward by 0.5 * * W. H. F. Smith, 30 January 1996 * */ #include #include #define NXIN 10800 /* Number of pixels in a v7.2 row (360x30) */ #define NY72 6336 /* Number of rows in a v7.2 file */ #define NHIST 41 /* Number of cells for histogram of 5 mGal steps */ short buffline[NXIN]; int hist[NHIST]; main(argc, argv) int argc; char **argv; { FILE *fp; int i, j, k, itest, ntot; if (argc != 2 || (fp = fopen(argv[1], "r")) == NULL) { fprintf(stderr,"usage: imghisteq .\n"); exit(-1); } for (i = 0; i < NHIST; i++) hist[i] = 0; ntot = 0; for (j = 0; j < NY72; j++) { if ( (fread(buffline, 2, NXIN, fp)) != NXIN) { fprintf(stderr,"imghisteq: READ ERROR. j = %d\n", j); exit(-1); } for (i = 0; i < NXIN; i++) { if (buffline[i] == 32767) continue; ntot++; /* if (buffline[i]%2) buffline[i] --; */ itest = ceil((double)(buffline[i] + 1000)/(double)50); if (itest < 0) itest = 0; for (k = itest; k < NHIST; k++) hist[k]++; } } fclose(fp); for (k = 0; k < NHIST; k++) { printf("%d\t%.8lg\n", 5*k - 100, ((double)hist[k]-0.5)/(double)ntot); } exit(0); }