--- ray/src/cal/histo.c 2003/02/22 02:07:20 1.1 +++ ray/src/cal/histo.c 2003/07/27 22:12:01 1.3 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: histo.c,v 1.1 2003/02/22 02:07:20 greg Exp $"; +static const char RCSid[] = "$Id: histo.c,v 1.3 2003/07/27 22:12:01 schorsch Exp $"; #endif /* * Compute a histogram from input data @@ -9,6 +9,7 @@ static const char RCSid[] = "$Id: histo.c,v 1.1 2003/0 #include #include +#include #include #include @@ -28,50 +29,9 @@ int ndiv; int ncols; -main(argc, argv) -int argc; -char *argv[]; +static void +readinp(void) /* gather statistics on input */ { - progname = argv[0]; - if (argc > 1 && !strcmp(argv[1], "-c")) { - cumulative++; - argc--; argv++; - } - if (argc < 3) - goto userr; - minv = atof(argv[1]); - maxv = atof(argv[2]); - if (argc == 4) - ndiv = atoi(argv[3]); - else { - if (argc > 4 || !isint(minv) || !isint(maxv)) - goto userr; - maxv += 0.5; - minv -= 0.5; - ndiv = maxv - minv + 0.5; - } - if (minv >= maxv | ndiv <= 0) - goto userr; - if (ndiv > MAXDIV) { - fprintf(stderr, "%s: maximum number of divisions: %d\n", - progname, MAXDIV); - goto userr; - } - readinp(); - if (cumulative) - printcumul(); - else - printhisto(); - exit(0); -userr: - fprintf(stderr, "Usage: %s [-c] min max n\n", progname); - fprintf(stderr, " Or: %s [-c] imin imax\n", progname); - exit(1); -} - - -readinp() /* gather statistics on input */ -{ char buf[16*MAXCOL]; double d; register int c; @@ -95,7 +55,8 @@ readinp() /* gather statistics on input */ } -printcumul() /* print cumulative histogram results */ +static void +printcumul(void) /* print cumulative histogram results */ { long ctot[MAXCOL]; register int i, c; @@ -114,7 +75,8 @@ printcumul() /* print cumulative histogram results * } -printhisto() /* print histogram results */ +static void +printhisto(void) /* print histogram results */ { register int i, c; @@ -125,3 +87,49 @@ printhisto() /* print histogram results */ putchar('\n'); } } + + +int +main( +int argc, +char *argv[] +) +{ + progname = argv[0]; + if (argc > 1 && !strcmp(argv[1], "-c")) { + cumulative++; + argc--; argv++; + } + if (argc < 3) + goto userr; + minv = atof(argv[1]); + maxv = atof(argv[2]); + if (argc == 4) + ndiv = atoi(argv[3]); + else { + if (argc > 4 || !isint(minv) || !isint(maxv)) + goto userr; + maxv += 0.5; + minv -= 0.5; + ndiv = maxv - minv + 0.5; + } + if ((minv >= maxv) | (ndiv <= 0)) + goto userr; + if (ndiv > MAXDIV) { + fprintf(stderr, "%s: maximum number of divisions: %d\n", + progname, MAXDIV); + goto userr; + } + readinp(); + if (cumulative) + printcumul(); + else + printhisto(); + exit(0); +userr: + fprintf(stderr, "Usage: %s [-c] min max n\n", progname); + fprintf(stderr, " Or: %s [-c] imin imax\n", progname); + exit(1); +} + +