--- ray/src/hd/rhinfo.c 2003/02/22 02:07:25 3.5 +++ ray/src/hd/rhinfo.c 2023/12/20 23:09:34 3.16 @@ -1,10 +1,14 @@ #ifndef lint -static const char RCSid[] = "$Id: rhinfo.c,v 3.5 2003/02/22 02:07:25 greg Exp $"; +static const char RCSid[] = "$Id: rhinfo.c,v 3.16 2023/12/20 23:09:34 greg Exp $"; #endif /* * Get general information on holodeck file */ +#include + +#include "platform.h" +#include "resolu.h" #include "holo.h" #ifndef NHBINS @@ -15,13 +19,16 @@ char *progname; /* global argv[0] */ long beamtot, samptot; /* total beams and samples */ +static void gethdinfo(char *fname, FILE *fout); +static void psectstats(HOLO *hp, FILE *fp); -main(argc, argv) -int argc; -char *argv[]; -{ - int sect; +int +main( + int argc, + char *argv[] +) +{ progname = argv[0]; if (argc != 2) goto userr; @@ -33,18 +40,19 @@ userr: } -gethdinfo(fname, fout) /* get information on holodeck */ -char *fname; -FILE *fout; +static void +gethdinfo( /* get information on holodeck */ + char *fname, + FILE *fout +) { - extern long ftell(); FILE *fp; HOLO *hdsect; int fd; - int4 nextloc; + off_t nextloc, fsiz; int n; /* open holodeck file */ - if ((fp = fopen(fname, "r")) == NULL) { + if ((fp = fopen(fname, "rb")) == NULL) { sprintf(errmsg, "cannot open \"%s\"", fname); error(SYSTEM, errmsg); } @@ -56,20 +64,20 @@ FILE *fout; fd = dup(fileno(fp)); /* dup file handle */ nextloc = ftell(fp); /* get stdio position */ fclose(fp); /* done with stdio */ - for (n = 0; nextloc > 0L; n++) { /* get the section(s) */ - lseek(fd, (off_t)nextloc, 0); + for (n = 0; nextloc > 0; n++) { /* get the section(s) */ + lseek(fd, nextloc, SEEK_SET); read(fd, (char *)&nextloc, sizeof(nextloc)); fprintf(fout, "Section %d:\n", n); hdsect = hdinit(fd, NULL); /* load section directory */ psectstats(hdsect, fout); /* print section statistics */ } - nextloc = hdfilen(fd); /* print global statistics */ + fsiz = hdfilen(fd); /* print global statistics */ fputs("=====================================================\n", fout); fprintf(fout, "Total samples/beams: %ld/%ld (%.2f samples/beam)\n", samptot, beamtot, (double)samptot/beamtot); fprintf(fout, "%.1f Mbyte file, %.1f%% fragmentation\n", - nextloc/(1024.*1024.), - 100.*(nextloc-hdfiluse(fd,1))/nextloc); + fsiz/(1024.*1024.), + 100.*(fsiz-hdfiluse(fd))/fsiz); /* don't bother with cleanup */ #if 0 hddone(NULL); /* free sections */ @@ -78,16 +86,18 @@ FILE *fout; } -psectstats(hp, fp) /* print statistical information for section */ -register HOLO *hp; -FILE *fp; +static void +psectstats( /* print statistical information for section */ + HOLO *hp, + FILE *fp +) { int scount[NHBINS]; int minsamp = 10000, maxsamp = 0; FVECT vt; - double sqrtmaxp; + double sqrtmaxp, median; int bmin, bmax, cnt; - register int i; + int i; fcross(vt, hp->xv[0], hp->xv[1]); fprintf(fp, "\tWorld volume: %g\n", fabs(DOT(vt,hp->xv[2]))); @@ -109,18 +119,18 @@ FILE *fp; for (i = NHBINS; i--; ) scount[i] = 0; for (i = nbeams(hp); i > 0; i--) - scount[(int)(NHBINS*sqrt((double)hp->bi[i].nrd)/sqrtmaxp)]++; - for (cnt = 0, i = 0; i < NHBINS && cnt<<1 < nbeams(hp); i++) + scount[(int)((NHBINS-FTINY)*sqrt((double)hp->bi[i].nrd)/sqrtmaxp)]++; + for (cnt = i = 0; i < NHBINS && cnt<<1 < nbeams(hp); i++) cnt += scount[i]; + median = (i-.5)*(i-.5)*(maxsamp+1)*(1./(NHBINS*NHBINS)); + if (median < minsamp) median = minsamp; fprintf(fp, "\tSamples per beam: [min,med,max]= [%d,%.0f,%d]\n", - minsamp, - (i-.5)*(i-.5)*(maxsamp+1)/(NHBINS*NHBINS), - maxsamp); + minsamp, median, maxsamp); fprintf(fp, "\tHistogram: [minsamp,maxsamp)= #beams\n"); bmax = 0; for (i = 0; i < NHBINS; i++) { bmin = bmax; - bmax = (i+1)*(i+1)*(maxsamp+1)/(NHBINS*NHBINS); + bmax = (i+1)*(i+1)*(maxsamp+1)*(1./(NHBINS*NHBINS)); fprintf(fp, "\t\t[%d,%d)= %d\n", bmin, bmax, scount[i]); } }