--- ray/src/hd/rhinfo.c 2010/09/30 14:45:10 3.12 +++ ray/src/hd/rhinfo.c 2023/12/20 23:09:34 3.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rhinfo.c,v 3.12 2010/09/30 14:45:10 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 @@ -49,11 +49,10 @@ gethdinfo( /* get information on holodeck */ FILE *fp; HOLO *hdsect; int fd; - int32 nextloc; - off_t fsiz; + 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); } @@ -65,8 +64,8 @@ gethdinfo( /* get information on holodeck */ 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, SEEK_SET); + 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 */ @@ -89,16 +88,16 @@ gethdinfo( /* get information on holodeck */ static void psectstats( /* print statistical information for section */ - register HOLO *hp, + 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]))); @@ -120,18 +119,18 @@ psectstats( /* print statistical information for sect 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]); } }