| 13 |
|
#include "holo.h" |
| 14 |
|
|
| 15 |
|
#ifndef BKBSIZE |
| 16 |
< |
#define BKBSIZE 64 /* beam clump size (kilobytes) */ |
| 16 |
> |
#define BKBSIZE 256 /* beam clump size (kilobytes) */ |
| 17 |
|
#endif |
| 18 |
|
|
| 19 |
+ |
#define flgop(p,i,op) ((p)[(i)>>5] op (1L<<((i)&0x1f))) |
| 20 |
+ |
#define isset(p,i) flgop(p,i,&) |
| 21 |
+ |
#define setfl(p,i) flgop(p,i,|=) |
| 22 |
+ |
#define clrfl(p,i) flgop(p,i,&=~) |
| 23 |
|
|
| 24 |
|
char *progname; |
| 25 |
|
|
| 153 |
|
GCOORD *gc; |
| 154 |
|
{ |
| 155 |
|
GCOORD gci0; |
| 156 |
< |
int i, j; |
| 156 |
> |
register int i, j; |
| 157 |
|
|
| 158 |
|
for (i = 3; i--; ) { |
| 159 |
|
copystruct(&gci0, gc); |
| 160 |
|
gcshifti(&gci0, 0, i-1, hp); |
| 161 |
|
for (j = 3; j--; ) { |
| 162 |
|
copystruct(ng+(3*i+j), &gci0); |
| 163 |
< |
gcshifti(ng+(3*i+j), 1, j-1, hp); |
| 163 |
> |
gcshifti(ng+(3*i+j), gci0.w==gc->w, j-1, hp); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
} |
| 187 |
|
for (j = 9; j--; ) { |
| 188 |
|
if (i == 4 & j == 4) |
| 189 |
|
continue; |
| 190 |
+ |
if (wg0[i].w == wg1[j].w) |
| 191 |
+ |
continue; |
| 192 |
|
copystruct(bgc, wg0+i); |
| 193 |
|
copystruct(bgc+1, wg1+j); |
| 194 |
|
bneighlist[bneighrem++] = hdbindex(hp, bgc); |
| 195 |
+ |
#ifdef DEBUG |
| 196 |
+ |
if (bneighlist[bneighrem-1] <= 0) |
| 197 |
+ |
error(CONSISTENCY, "bad beam in firstneigh"); |
| 198 |
+ |
#endif |
| 199 |
|
} |
| 200 |
|
return(nextneigh()); |
| 201 |
|
} |
| 202 |
|
|
| 203 |
|
|
| 204 |
+ |
BEAMI *beamdir; |
| 205 |
+ |
|
| 206 |
+ |
int |
| 207 |
+ |
bpcmp(b1p, b2p) /* compare beam positions on disk */ |
| 208 |
+ |
int *b1p, *b2p; |
| 209 |
+ |
{ |
| 210 |
+ |
register long pdif = beamdir[*b1p].fo - beamdir[*b2p].fo; |
| 211 |
+ |
|
| 212 |
+ |
if (pdif > 0) return(1); |
| 213 |
+ |
if (pdif < 0) return(-1); |
| 214 |
+ |
return(0); |
| 215 |
+ |
} |
| 216 |
+ |
|
| 217 |
+ |
|
| 218 |
|
copysect(ifd, ofd) /* copy holodeck section from ifd to ofd */ |
| 219 |
|
int ifd, ofd; |
| 220 |
|
{ |
| 197 |
– |
#define beamdone(b) (!hinp->bi[b].nrd || bnrays(hout,b)) |
| 221 |
|
static short primes[] = {9431,6803,4177,2659,1609,887,587,251,47,1}; |
| 222 |
< |
register HOLO *hinp, *hout; |
| 222 |
> |
register HOLO *hinp; |
| 223 |
> |
HOLO *hout; |
| 224 |
|
register BEAM *bp; |
| 225 |
+ |
unsigned int4 *bflags; |
| 226 |
|
int *bqueue; |
| 227 |
|
int bqlen; |
| 228 |
|
int4 bqtotal; |
| 229 |
< |
int bc, bci, bqc, bnc, myprime; |
| 229 |
> |
int bc, bci, bqc, myprime; |
| 230 |
|
register int i; |
| 231 |
|
/* load input section directory */ |
| 232 |
|
hinp = hdinit(ifd, NULL); |
| 233 |
|
/* create output section directory */ |
| 234 |
|
hout = hdinit(ofd, (HDGRID *)hinp); |
| 235 |
|
/* allocate beam queue */ |
| 236 |
< |
if ((bqueue = (int *)malloc(nbeams(hinp)*sizeof(int))) == NULL) |
| 236 |
> |
bqueue = (int *)malloc(nbeams(hinp)*sizeof(int)); |
| 237 |
> |
bflags = (int4 *)calloc((nbeams(hinp)>>3)+1, sizeof(int4)); |
| 238 |
> |
if (bqueue == NULL | bflags == NULL) |
| 239 |
|
error(SYSTEM, "out of memory in copysect"); |
| 240 |
+ |
/* mark empty beams as done */ |
| 241 |
+ |
for (i = nbeams(hinp); i-- > 0; ) |
| 242 |
+ |
if (!hinp->bi[i].nrd) |
| 243 |
+ |
setfl(bflags, i); |
| 244 |
|
/* pick a good prime step size */ |
| 245 |
|
for (i = 0; primes[i]<<5 >= nbeams(hinp); i++) |
| 246 |
|
; |
| 250 |
|
/* add each input beam and neighbors */ |
| 251 |
|
for (bc = bci = nbeams(hinp); bc > 0; bc--, |
| 252 |
|
bci += bci>myprime ? -myprime : nbeams(hinp)-myprime) { |
| 253 |
< |
if (beamdone(bci)) |
| 253 |
> |
if (isset(bflags, bci)) |
| 254 |
|
continue; |
| 255 |
|
bqueue[0] = bci; /* initialize queue */ |
| 256 |
|
bqlen = 1; |
| 257 |
|
bqtotal = bnrays(hinp, bci); |
| 258 |
+ |
setfl(bflags, bci); |
| 259 |
|
/* run through growing queue */ |
| 260 |
|
for (bqc = 0; bqc < bqlen; bqc++) { |
| 261 |
< |
/* transfer the beam */ |
| 262 |
< |
bp = hdgetbeam(hinp, bqueue[bqc]); |
| 263 |
< |
bcopy((char *)hdbray(bp), |
| 264 |
< |
(char *)hdnewrays(hout,bqueue[bqc],bp->nrm), |
| 233 |
< |
bp->nrm*sizeof(RAYVAL)); |
| 234 |
< |
hdfreebeam(hinp, bqueue[bqc]); |
| 235 |
< |
/* check queue size */ |
| 236 |
< |
if (bqtotal >= BKBSIZE*1024/sizeof(RAYVAL)) |
| 237 |
< |
continue; |
| 238 |
< |
/* add neighbors to queue */ |
| 239 |
< |
for (bnc = firstneigh(hinp,bqueue[bqc]); bnc > 0; |
| 240 |
< |
bnc = nextneigh()) { |
| 241 |
< |
if (beamdone(bnc)) /* see if valid */ |
| 261 |
> |
/* add neighbors until full */ |
| 262 |
> |
for (i = firstneigh(hinp,bqueue[bqc]); i > 0; |
| 263 |
> |
i = nextneigh()) { |
| 264 |
> |
if (isset(bflags, i)) /* done already? */ |
| 265 |
|
continue; |
| 266 |
< |
for (i = bqlen; i--; ) |
| 267 |
< |
if (bqueue[i] == bnc) break; |
| 268 |
< |
if (i >= 0) |
| 246 |
< |
continue; |
| 247 |
< |
bqueue[bqlen++] = bnc; /* add it */ |
| 248 |
< |
bqtotal += bnrays(hinp, bnc); |
| 266 |
> |
bqueue[bqlen++] = i; /* add it */ |
| 267 |
> |
bqtotal += bnrays(hinp, i); |
| 268 |
> |
setfl(bflags, i); |
| 269 |
|
if (bqtotal >= BKBSIZE*1024/sizeof(RAYVAL)) |
| 270 |
|
break; /* queue full */ |
| 271 |
|
} |
| 272 |
+ |
if (i > 0) |
| 273 |
+ |
break; |
| 274 |
|
} |
| 275 |
+ |
beamdir = hinp->bi; /* sort queue */ |
| 276 |
+ |
qsort((char *)bqueue, bqlen, sizeof(*bqueue), bpcmp); |
| 277 |
+ |
/* transfer each beam */ |
| 278 |
+ |
for (i = 0; i < bqlen; i++) { |
| 279 |
+ |
bp = hdgetbeam(hinp, bqueue[i]); |
| 280 |
+ |
bcopy((char *)hdbray(bp), |
| 281 |
+ |
(char *)hdnewrays(hout,bqueue[i],bp->nrm), |
| 282 |
+ |
bp->nrm*sizeof(RAYVAL)); |
| 283 |
+ |
hdfreebeam(hinp, bqueue[i]); |
| 284 |
+ |
} |
| 285 |
|
hdfreebeam(hout, 0); /* flush output block */ |
| 286 |
+ |
#ifdef DEBUG |
| 287 |
+ |
hdsync(hout, 0); |
| 288 |
+ |
#endif |
| 289 |
|
} |
| 290 |
|
/* we're done -- clean up */ |
| 291 |
|
free((char *)bqueue); |
| 292 |
+ |
free((char *)bflags); |
| 293 |
|
hddone(hinp); |
| 294 |
|
hddone(hout); |
| 259 |
– |
#undef beamdone |
| 295 |
|
} |
| 296 |
|
|
| 297 |
|
|