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