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 |
|
20 |
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 |
extern long ftell(); |
42 |
FILE *fp; |
43 |
HOLO *hdsect; |
44 |
int fd; |
45 |
int4 nextloc; |
46 |
int n; |
47 |
/* open holodeck file */ |
48 |
if ((fp = fopen(fname, "r")) == NULL) { |
49 |
sprintf(errmsg, "cannot open \"%s\"", fname); |
50 |
error(SYSTEM, errmsg); |
51 |
} |
52 |
/* check header and magic number */ |
53 |
if (checkheader(fp, HOLOFMT, fout) < 0 || getw(fp) != HOLOMAGIC) { |
54 |
sprintf(errmsg, "file \"%s\" not in holodeck format", fname); |
55 |
error(USER, errmsg); |
56 |
} |
57 |
fd = dup(fileno(fp)); /* dup file handle */ |
58 |
nextloc = ftell(fp); /* get stdio position */ |
59 |
fclose(fp); /* done with stdio */ |
60 |
for (n = 0; nextloc > 0L; n++) { /* get the section(s) */ |
61 |
lseek(fd, (long)nextloc, 0); |
62 |
read(fd, (char *)&nextloc, sizeof(nextloc)); |
63 |
hdsect = hdinit(fd, NULL); /* load section directory */ |
64 |
fprintf(fout,"Section %d:\n",n); |
65 |
psectstats(hdsect, fout); /* print section statistics */ |
66 |
} |
67 |
nextloc = hdfilen(fd); /* print global statistics */ |
68 |
fprintf(fout, "%.1f Mbyte file, %.1f%% fragmentation\n", |
69 |
nextloc/(1024.*1024.), |
70 |
100.*(nextloc-hdfiluse(fd,1))/nextloc); |
71 |
/* don't bother with cleanup */ |
72 |
#if 0 |
73 |
hddone(NULL); /* free sections */ |
74 |
close(fd); /* done with the holodeck */ |
75 |
#endif |
76 |
} |
77 |
|
78 |
|
79 |
psectstats(hp, fp) /* print statistical information for section */ |
80 |
register HOLO *hp; |
81 |
FILE *fp; |
82 |
{ |
83 |
int scount[NHBINS]; |
84 |
int minsamp = 10000, maxsamp = 0; |
85 |
double sqrtmaxp; |
86 |
int bmin, bmax, cnt; |
87 |
register int i; |
88 |
|
89 |
fprintf(fp, "\tGrid resolution: %d x %d x %d\n", |
90 |
hp->grid[0], hp->grid[1], hp->grid[2]); |
91 |
fprintf(fp, "\tNumber of beams: %d\n", nbeams(hp)); |
92 |
fprintf(fp, "\tNumber of ray samples: %d\n", biglob(hp)->nrd); |
93 |
if (biglob(hp)->nrd <= 0) |
94 |
return; /* no samples to stat! */ |
95 |
for (i = nbeams(hp); i > 0; i--) { |
96 |
if (hp->bi[i].nrd < minsamp) |
97 |
minsamp = hp->bi[i].nrd; |
98 |
if (hp->bi[i].nrd > maxsamp) |
99 |
maxsamp = hp->bi[i].nrd; |
100 |
} |
101 |
sqrtmaxp = sqrt(maxsamp+1.0); |
102 |
for (i = NHBINS; i--; ) |
103 |
scount[i] = 0; |
104 |
for (i = nbeams(hp); i > 0; i--) |
105 |
scount[(int)(NHBINS*sqrt((double)hp->bi[i].nrd)/sqrtmaxp)]++; |
106 |
for (cnt = 0, i = 0; i < NHBINS && cnt<<1 < nbeams(hp); i++) |
107 |
cnt += scount[i]; |
108 |
fprintf(fp, "\tSamples per beam: [min,med,max]= [%d,%.0f,%d]\n", |
109 |
minsamp, |
110 |
(i-.5)*(i-.5)*(maxsamp+1)/(NHBINS*NHBINS), |
111 |
maxsamp); |
112 |
fprintf(fp, "\tHistogram: [minsamp,maxsamp)= #beams\n"); |
113 |
bmax = 0; |
114 |
for (i = 0; i < NHBINS; i++) { |
115 |
bmin = bmax; |
116 |
bmax = (i+1)*(i+1)*(maxsamp+1)/(NHBINS*NHBINS); |
117 |
fprintf(fp, "\t\t[%d,%d)= %d\n", bmin, bmax, scount[i]); |
118 |
} |
119 |
} |