ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cal/histo.c
(Generate patch)

Comparing ray/src/cal/histo.c (file contents):
Revision 1.3 by schorsch, Sun Jul 27 22:12:01 2003 UTC vs.
Revision 1.4 by greg, Sun Dec 14 16:33:37 2003 UTC

# Line 21 | Line 21 | static const char      RCSid[] = "$Id$";
21   char    *progname;
22  
23   int     cumulative = 0;
24 + int     percentile = 0;
25  
26 + long    outrange[MAXCOL][2];
27   long    histo[MAXCOL][MAXDIV];
28 + long    ctotal[MAXCOL];
29   double  minv, maxv;
30   int     ndiv;
31  
# Line 34 | Line 37 | readinp(void)                  /* gather statistics on input */
37   {
38          char    buf[16*MAXCOL];
39          double  d;
40 +        int     i;
41          register int    c;
42          register char   *cp;
43  
# Line 46 | Line 50 | readinp(void)                  /* gather statistics on input */
50                          d = atof(cp);
51                          while (*cp && !isspace(*cp))
52                                  cp++;
53 <                        if (d >= minv && d < maxv)
53 >                        if (d <= minv)
54 >                                outrange[c][0]++;
55 >                        else if (d >= maxv)
56 >                                outrange[c][1]++;
57 >                        else
58                                  histo[c][(int)(ndiv*(d-minv)/(maxv-minv))]++;
59                  }
60                  if (c > ncols)
61                          ncols = c;
62          }
63 +        for (c = 0; c < ncols; c++) {
64 +                ctotal[c] += outrange[c][0] + outrange[c][1];
65 +                for (i = 0; i < ndiv; i++)
66 +                        ctotal[c] += histo[c][i];
67 +        }
68   }
69  
70  
71   static void
72 < printcumul(void)                        /* print cumulative histogram results */
72 > printcumul(                     /* print cumulative histogram results */
73 > int     pctl
74 > )
75   {
76 <        long            ctot[MAXCOL];
76 >        long            csum[MAXCOL];
77          register int    i, c;
78  
79          for (c = ncols; c--; )
80 <                ctot[c] = 0L;
80 >                csum[c] = outrange[c][0];
81  
82 <        for (i = 0; i < ndiv; i++) {
83 <                printf("%g", minv + (maxv-minv)*(i+1)/ndiv);
82 >        for (i = 0; i <= ndiv; i++) {
83 >                printf("%g", minv + (maxv-minv)*i/ndiv);
84                  for (c = 0; c < ncols; c++) {
85 <                        ctot[c] += histo[c][i];
86 <                        printf("\t%ld", ctot[c]);
85 >                        if (pctl)
86 >                                printf("\t%f", 100.*csum[c]/ctotal[c]);
87 >                        else
88 >                                printf("\t%ld", csum[c]);
89 >                        if (i < ndiv)
90 >                                csum[c] += histo[c][i];
91                  }
92                  putchar('\n');
93          }
# Line 76 | Line 95 | printcumul(void)                       /* print cumulative histogram resul
95  
96  
97   static void
98 < printhisto(void)                        /* print histogram results */
98 > printhisto(                     /* print histogram results */
99 > int     pctl
100 > )
101   {
102          register int    i, c;
103  
104          for (i = 0; i < ndiv; i++) {
105                  printf("%g", minv + (maxv-minv)*(i+.5)/ndiv);
106                  for (c = 0; c < ncols; c++)
107 <                        printf("\t%ld", histo[c][i]);
107 >                        if (pctl)
108 >                                printf("\t%f", 100.*histo[c][i]/ctotal[c]);
109 >                        else
110 >                                printf("\t%ld", histo[c][i]);
111                  putchar('\n');
112          }
113   }
# Line 96 | Line 120 | char   *argv[]
120   )
121   {
122          progname = argv[0];
123 <        if (argc > 1 && !strcmp(argv[1], "-c")) {
124 <                cumulative++;
123 >        while (argc > 1 && argv[1][0] == '-') {
124 >                if (argv[1][1] == 'c')
125 >                        cumulative++;
126 >                else if (argv[1][1] == 'p')
127 >                        percentile++;
128 >                else
129 >                        break;
130                  argc--; argv++;
131          }
132          if (argc < 3)
# Line 122 | Line 151 | char   *argv[]
151          }
152          readinp();
153          if (cumulative)
154 <                printcumul();
154 >                printcumul(percentile);
155          else
156 <                printhisto();
156 >                printhisto(percentile);
157          exit(0);
158   userr:
159 <        fprintf(stderr, "Usage: %s [-c] min max n\n", progname);
160 <        fprintf(stderr, "   Or: %s [-c] imin imax\n", progname);
159 >        fprintf(stderr, "Usage: %s [-c][-p] min max n\n", progname);
160 >        fprintf(stderr, "   Or: %s [-c][-p] imin imax\n", progname);
161          exit(1);
162   }
163  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines