ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhinfo.c
Revision: 3.4
Committed: Wed Feb 3 10:48:06 1999 UTC (25 years, 1 month ago) by gwlarson
Content type: text/plain
Branch: MAIN
Changes since 3.3: +3 -0 lines
Log Message:
added reporting of section volume

File Contents

# User Rev Content
1 gwlarson 3.1 /* Copyright (c) 1998 Silicon Graphics, Inc. */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ SGI";
5     #endif
6    
7     /*
8     * Get general information on holodeck file
9     */
10    
11     #include "holo.h"
12    
13     #ifndef NHBINS
14     #define NHBINS 12 /* number of histogram bins to use for stats */
15     #endif
16    
17     char *progname; /* global argv[0] */
18    
19 gwlarson 3.3 long beamtot, samptot; /* total beams and samples */
20 gwlarson 3.1
21 gwlarson 3.3
22 gwlarson 3.1 main(argc, argv)
23     int argc;
24     char *argv[];
25     {
26     int sect;
27    
28     progname = argv[0];
29     if (argc != 2)
30     goto userr;
31     gethdinfo(argv[1], stdout);
32     quit(0);
33     userr:
34     fprintf(stderr, "Usage: %s input.hdk\n", progname);
35     exit(1);
36     }
37    
38    
39     gethdinfo(fname, fout) /* get information on holodeck */
40     char *fname;
41     FILE *fout;
42     {
43     extern long ftell();
44     FILE *fp;
45     HOLO *hdsect;
46     int fd;
47     int4 nextloc;
48     int n;
49     /* open holodeck file */
50     if ((fp = fopen(fname, "r")) == NULL) {
51     sprintf(errmsg, "cannot open \"%s\"", fname);
52     error(SYSTEM, errmsg);
53     }
54     /* check header and magic number */
55     if (checkheader(fp, HOLOFMT, fout) < 0 || getw(fp) != HOLOMAGIC) {
56     sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
57     error(USER, errmsg);
58     }
59     fd = dup(fileno(fp)); /* dup file handle */
60     nextloc = ftell(fp); /* get stdio position */
61     fclose(fp); /* done with stdio */
62     for (n = 0; nextloc > 0L; n++) { /* get the section(s) */
63     lseek(fd, (long)nextloc, 0);
64     read(fd, (char *)&nextloc, sizeof(nextloc));
65 gwlarson 3.2 fprintf(fout, "Section %d:\n", n);
66 gwlarson 3.1 hdsect = hdinit(fd, NULL); /* load section directory */
67     psectstats(hdsect, fout); /* print section statistics */
68     }
69     nextloc = hdfilen(fd); /* print global statistics */
70 gwlarson 3.3 fputs("=====================================================\n", fout);
71     fprintf(fout, "Total samples/beams: %ld/%ld (%.2f samples/beam)\n",
72     samptot, beamtot, (double)samptot/beamtot);
73 gwlarson 3.1 fprintf(fout, "%.1f Mbyte file, %.1f%% fragmentation\n",
74     nextloc/(1024.*1024.),
75     100.*(nextloc-hdfiluse(fd,1))/nextloc);
76     /* don't bother with cleanup */
77     #if 0
78     hddone(NULL); /* free sections */
79     close(fd); /* done with the holodeck */
80     #endif
81     }
82    
83    
84     psectstats(hp, fp) /* print statistical information for section */
85     register HOLO *hp;
86     FILE *fp;
87     {
88     int scount[NHBINS];
89     int minsamp = 10000, maxsamp = 0;
90 gwlarson 3.4 FVECT vt;
91 gwlarson 3.1 double sqrtmaxp;
92     int bmin, bmax, cnt;
93     register int i;
94    
95 gwlarson 3.4 fcross(vt, hp->xv[0], hp->xv[1]);
96     fprintf(fp, "\tWorld volume: %g\n", fabs(DOT(vt,hp->xv[2])));
97 gwlarson 3.1 fprintf(fp, "\tGrid resolution: %d x %d x %d\n",
98     hp->grid[0], hp->grid[1], hp->grid[2]);
99 gwlarson 3.3 fprintf(fp, "\tNumber of beams: %ld\n", (long)nbeams(hp));
100     beamtot += nbeams(hp);
101     fprintf(fp, "\tNumber of ray samples: %ld\n", (long)biglob(hp)->nrd);
102     samptot += biglob(hp)->nrd;
103 gwlarson 3.1 if (biglob(hp)->nrd <= 0)
104     return; /* no samples to stat! */
105     for (i = nbeams(hp); i > 0; i--) {
106     if (hp->bi[i].nrd < minsamp)
107     minsamp = hp->bi[i].nrd;
108     if (hp->bi[i].nrd > maxsamp)
109     maxsamp = hp->bi[i].nrd;
110     }
111     sqrtmaxp = sqrt(maxsamp+1.0);
112     for (i = NHBINS; i--; )
113     scount[i] = 0;
114     for (i = nbeams(hp); i > 0; i--)
115     scount[(int)(NHBINS*sqrt((double)hp->bi[i].nrd)/sqrtmaxp)]++;
116     for (cnt = 0, i = 0; i < NHBINS && cnt<<1 < nbeams(hp); i++)
117     cnt += scount[i];
118     fprintf(fp, "\tSamples per beam: [min,med,max]= [%d,%.0f,%d]\n",
119     minsamp,
120     (i-.5)*(i-.5)*(maxsamp+1)/(NHBINS*NHBINS),
121     maxsamp);
122     fprintf(fp, "\tHistogram: [minsamp,maxsamp)= #beams\n");
123     bmax = 0;
124     for (i = 0; i < NHBINS; i++) {
125     bmin = bmax;
126     bmax = (i+1)*(i+1)*(maxsamp+1)/(NHBINS*NHBINS);
127     fprintf(fp, "\t\t[%d,%d)= %d\n", bmin, bmax, scount[i]);
128     }
129     }