ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rhinfo.c
Revision: 3.9
Committed: Wed Oct 22 02:06:34 2003 UTC (20 years, 6 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 3.8: +2 -2 lines
Log Message:
Fewer complaints if "platform.h" precedes "standard.h"

File Contents

# User Rev Content
1 gwlarson 3.1 #ifndef lint
2 greg 3.9 static const char RCSid[] = "$Id: rhinfo.c,v 3.8 2003/10/20 16:01:55 greg Exp $";
3 gwlarson 3.1 #endif
4     /*
5     * Get general information on holodeck file
6     */
7    
8 greg 3.9 #include "platform.h"
9 gwlarson 3.1 #include "holo.h"
10    
11     #ifndef NHBINS
12     #define NHBINS 12 /* number of histogram bins to use for stats */
13     #endif
14    
15     char *progname; /* global argv[0] */
16    
17 gwlarson 3.3 long beamtot, samptot; /* total beams and samples */
18 gwlarson 3.1
19 gwlarson 3.3
20 gwlarson 3.1 main(argc, argv)
21     int argc;
22     char *argv[];
23     {
24     int sect;
25    
26     progname = argv[0];
27     if (argc != 2)
28     goto userr;
29     gethdinfo(argv[1], stdout);
30     quit(0);
31     userr:
32     fprintf(stderr, "Usage: %s input.hdk\n", progname);
33     exit(1);
34     }
35    
36    
37     gethdinfo(fname, fout) /* get information on holodeck */
38     char *fname;
39     FILE *fout;
40     {
41     FILE *fp;
42     HOLO *hdsect;
43     int fd;
44 greg 3.7 int32 nextloc;
45 gwlarson 3.1 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 greg 3.8 lseek(fd, (off_t)nextloc, SEEK_SET);
61 gwlarson 3.1 read(fd, (char *)&nextloc, sizeof(nextloc));
62 gwlarson 3.2 fprintf(fout, "Section %d:\n", n);
63 gwlarson 3.1 hdsect = hdinit(fd, NULL); /* load section directory */
64     psectstats(hdsect, fout); /* print section statistics */
65     }
66     nextloc = hdfilen(fd); /* print global statistics */
67 gwlarson 3.3 fputs("=====================================================\n", fout);
68     fprintf(fout, "Total samples/beams: %ld/%ld (%.2f samples/beam)\n",
69     samptot, beamtot, (double)samptot/beamtot);
70 gwlarson 3.1 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 gwlarson 3.4 FVECT vt;
88 gwlarson 3.1 double sqrtmaxp;
89     int bmin, bmax, cnt;
90     register int i;
91    
92 gwlarson 3.4 fcross(vt, hp->xv[0], hp->xv[1]);
93     fprintf(fp, "\tWorld volume: %g\n", fabs(DOT(vt,hp->xv[2])));
94 gwlarson 3.1 fprintf(fp, "\tGrid resolution: %d x %d x %d\n",
95     hp->grid[0], hp->grid[1], hp->grid[2]);
96 gwlarson 3.3 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 gwlarson 3.1 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     }