| 1 |
gwlarson |
3.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 |
gwlarson |
3.3 |
long beamtot, samptot; /* total beams and samples */ |
| 20 |
gwlarson |
3.1 |
|
| 21 |
gwlarson |
3.3 |
|
| 22 |
gwlarson |
3.1 |
main(argc, argv) |
| 23 |
|
|
int argc; |
| 24 |
|
|
char *argv[]; |
| 25 |
|
|
{ |
| 26 |
|
|
int sect; |
| 27 |
|
|
|
| 28 |
|
|
progname = argv[0]; |
| 29 |
|
|
if (argc != 2) |
| 30 |
|
|
goto userr; |
| 31 |
|
|
gethdinfo(argv[1], stdout); |
| 32 |
|
|
quit(0); |
| 33 |
|
|
userr: |
| 34 |
|
|
fprintf(stderr, "Usage: %s input.hdk\n", progname); |
| 35 |
|
|
exit(1); |
| 36 |
|
|
} |
| 37 |
|
|
|
| 38 |
|
|
|
| 39 |
|
|
gethdinfo(fname, fout) /* get information on holodeck */ |
| 40 |
|
|
char *fname; |
| 41 |
|
|
FILE *fout; |
| 42 |
|
|
{ |
| 43 |
|
|
extern long ftell(); |
| 44 |
|
|
FILE *fp; |
| 45 |
|
|
HOLO *hdsect; |
| 46 |
|
|
int fd; |
| 47 |
|
|
int4 nextloc; |
| 48 |
|
|
int n; |
| 49 |
|
|
/* open holodeck file */ |
| 50 |
|
|
if ((fp = fopen(fname, "r")) == NULL) { |
| 51 |
|
|
sprintf(errmsg, "cannot open \"%s\"", fname); |
| 52 |
|
|
error(SYSTEM, errmsg); |
| 53 |
|
|
} |
| 54 |
|
|
/* check header and magic number */ |
| 55 |
|
|
if (checkheader(fp, HOLOFMT, fout) < 0 || getw(fp) != HOLOMAGIC) { |
| 56 |
|
|
sprintf(errmsg, "file \"%s\" not in holodeck format", fname); |
| 57 |
|
|
error(USER, errmsg); |
| 58 |
|
|
} |
| 59 |
|
|
fd = dup(fileno(fp)); /* dup file handle */ |
| 60 |
|
|
nextloc = ftell(fp); /* get stdio position */ |
| 61 |
|
|
fclose(fp); /* done with stdio */ |
| 62 |
|
|
for (n = 0; nextloc > 0L; n++) { /* get the section(s) */ |
| 63 |
|
|
lseek(fd, (long)nextloc, 0); |
| 64 |
|
|
read(fd, (char *)&nextloc, sizeof(nextloc)); |
| 65 |
gwlarson |
3.2 |
fprintf(fout, "Section %d:\n", n); |
| 66 |
gwlarson |
3.1 |
hdsect = hdinit(fd, NULL); /* load section directory */ |
| 67 |
|
|
psectstats(hdsect, fout); /* print section statistics */ |
| 68 |
|
|
} |
| 69 |
|
|
nextloc = hdfilen(fd); /* print global statistics */ |
| 70 |
gwlarson |
3.3 |
fputs("=====================================================\n", fout); |
| 71 |
|
|
fprintf(fout, "Total samples/beams: %ld/%ld (%.2f samples/beam)\n", |
| 72 |
|
|
samptot, beamtot, (double)samptot/beamtot); |
| 73 |
gwlarson |
3.1 |
fprintf(fout, "%.1f Mbyte file, %.1f%% fragmentation\n", |
| 74 |
|
|
nextloc/(1024.*1024.), |
| 75 |
|
|
100.*(nextloc-hdfiluse(fd,1))/nextloc); |
| 76 |
|
|
/* don't bother with cleanup */ |
| 77 |
|
|
#if 0 |
| 78 |
|
|
hddone(NULL); /* free sections */ |
| 79 |
|
|
close(fd); /* done with the holodeck */ |
| 80 |
|
|
#endif |
| 81 |
|
|
} |
| 82 |
|
|
|
| 83 |
|
|
|
| 84 |
|
|
psectstats(hp, fp) /* print statistical information for section */ |
| 85 |
|
|
register HOLO *hp; |
| 86 |
|
|
FILE *fp; |
| 87 |
|
|
{ |
| 88 |
|
|
int scount[NHBINS]; |
| 89 |
|
|
int minsamp = 10000, maxsamp = 0; |
| 90 |
|
|
double sqrtmaxp; |
| 91 |
|
|
int bmin, bmax, cnt; |
| 92 |
|
|
register int i; |
| 93 |
|
|
|
| 94 |
|
|
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 |
|
|
} |