ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhinfo.c
Revision: 3.12
Committed: Thu Sep 30 14:45:10 2010 UTC (13 years, 7 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.11: +5 -4 lines
Log Message:
Fixed bug in reporting for large files

File Contents

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