ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhinfo.c
Revision: 3.5
Committed: Sat Feb 22 02:07:25 2003 UTC (21 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R5
Changes since 3.4: +2 -5 lines
Log Message:
Changes and check-in for 3.5 release
Includes new source files and modifications not recorded for many years
See ray/doc/notes/ReleaseNotes for notes between 3.1 and 3.5 release

File Contents

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