ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhinfo.c
Revision: 3.7
Committed: Fri Jun 20 00:25:49 2003 UTC (20 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.6: +2 -2 lines
Log Message:
Changed instances of "int4" to "int32" and "int2" to "int16"

File Contents

# User Rev Content
1 gwlarson 3.1 #ifndef lint
2 greg 3.7 static const char RCSid[] = "$Id: rhinfo.c,v 3.6 2003/05/29 16:26:22 greg Exp $";
3 gwlarson 3.1 #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 gwlarson 3.3 long beamtot, samptot; /* total beams and samples */
17 gwlarson 3.1
18 gwlarson 3.3
19 gwlarson 3.1 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     FILE *fp;
41     HOLO *hdsect;
42     int fd;
43 greg 3.7 int32 nextloc;
44 gwlarson 3.1 int n;
45     /* open holodeck file */
46     if ((fp = fopen(fname, "r")) == NULL) {
47     sprintf(errmsg, "cannot open \"%s\"", fname);
48     error(SYSTEM, errmsg);
49     }
50     /* check header and magic number */
51     if (checkheader(fp, HOLOFMT, fout) < 0 || getw(fp) != HOLOMAGIC) {
52     sprintf(errmsg, "file \"%s\" not in holodeck format", fname);
53     error(USER, errmsg);
54     }
55     fd = dup(fileno(fp)); /* dup file handle */
56     nextloc = ftell(fp); /* get stdio position */
57     fclose(fp); /* done with stdio */
58     for (n = 0; nextloc > 0L; n++) { /* get the section(s) */
59 greg 3.5 lseek(fd, (off_t)nextloc, 0);
60 gwlarson 3.1 read(fd, (char *)&nextloc, sizeof(nextloc));
61 gwlarson 3.2 fprintf(fout, "Section %d:\n", n);
62 gwlarson 3.1 hdsect = hdinit(fd, NULL); /* load section directory */
63     psectstats(hdsect, fout); /* print section statistics */
64     }
65     nextloc = hdfilen(fd); /* print global statistics */
66 gwlarson 3.3 fputs("=====================================================\n", fout);
67     fprintf(fout, "Total samples/beams: %ld/%ld (%.2f samples/beam)\n",
68     samptot, beamtot, (double)samptot/beamtot);
69 gwlarson 3.1 fprintf(fout, "%.1f Mbyte file, %.1f%% fragmentation\n",
70     nextloc/(1024.*1024.),
71     100.*(nextloc-hdfiluse(fd,1))/nextloc);
72     /* don't bother with cleanup */
73     #if 0
74     hddone(NULL); /* free sections */
75     close(fd); /* done with the holodeck */
76     #endif
77     }
78    
79    
80     psectstats(hp, fp) /* print statistical information for section */
81     register HOLO *hp;
82     FILE *fp;
83     {
84     int scount[NHBINS];
85     int minsamp = 10000, maxsamp = 0;
86 gwlarson 3.4 FVECT vt;
87 gwlarson 3.1 double sqrtmaxp;
88     int bmin, bmax, cnt;
89     register int i;
90    
91 gwlarson 3.4 fcross(vt, hp->xv[0], hp->xv[1]);
92     fprintf(fp, "\tWorld volume: %g\n", fabs(DOT(vt,hp->xv[2])));
93 gwlarson 3.1 fprintf(fp, "\tGrid resolution: %d x %d x %d\n",
94     hp->grid[0], hp->grid[1], hp->grid[2]);
95 gwlarson 3.3 fprintf(fp, "\tNumber of beams: %ld\n", (long)nbeams(hp));
96     beamtot += nbeams(hp);
97     fprintf(fp, "\tNumber of ray samples: %ld\n", (long)biglob(hp)->nrd);
98     samptot += biglob(hp)->nrd;
99 gwlarson 3.1 if (biglob(hp)->nrd <= 0)
100     return; /* no samples to stat! */
101     for (i = nbeams(hp); i > 0; i--) {
102     if (hp->bi[i].nrd < minsamp)
103     minsamp = hp->bi[i].nrd;
104     if (hp->bi[i].nrd > maxsamp)
105     maxsamp = hp->bi[i].nrd;
106     }
107     sqrtmaxp = sqrt(maxsamp+1.0);
108     for (i = NHBINS; i--; )
109     scount[i] = 0;
110     for (i = nbeams(hp); i > 0; i--)
111     scount[(int)(NHBINS*sqrt((double)hp->bi[i].nrd)/sqrtmaxp)]++;
112     for (cnt = 0, i = 0; i < NHBINS && cnt<<1 < nbeams(hp); i++)
113     cnt += scount[i];
114     fprintf(fp, "\tSamples per beam: [min,med,max]= [%d,%.0f,%d]\n",
115     minsamp,
116     (i-.5)*(i-.5)*(maxsamp+1)/(NHBINS*NHBINS),
117     maxsamp);
118     fprintf(fp, "\tHistogram: [minsamp,maxsamp)= #beams\n");
119     bmax = 0;
120     for (i = 0; i < NHBINS; i++) {
121     bmin = bmax;
122     bmax = (i+1)*(i+1)*(maxsamp+1)/(NHBINS*NHBINS);
123     fprintf(fp, "\t\t[%d,%d)= %d\n", bmin, bmax, scount[i]);
124     }
125     }