| 1 |
– |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 2 |
– |
|
| 3 |
– |
#ifndef lint |
| 4 |
– |
static char SCCSid[] = "$SunId$ SGI"; |
| 5 |
– |
#endif |
| 6 |
– |
|
| 1 |
|
/* |
| 2 |
|
* Routines for tracking beam compuatations |
| 3 |
|
*/ |
| 55 |
|
register PACKHEAD *clist; |
| 56 |
|
int nents; |
| 57 |
|
{ |
| 58 |
+ |
int oldnr; |
| 59 |
+ |
register HDBEAMI *hb; |
| 60 |
|
register int i, n; |
| 61 |
< |
|
| 61 |
> |
/* look for common members */ |
| 62 |
> |
for (n = 0; n < nents; n++) { |
| 63 |
> |
for (i = 0; i < complen; i++) |
| 64 |
> |
if (clist[n].bi == complist[i].bi && |
| 65 |
> |
clist[n].hd == complist[i].hd) { |
| 66 |
> |
oldnr = complist[i].nr; |
| 67 |
> |
clist[n].nc = complist[i].nc; |
| 68 |
> |
switch (op) { |
| 69 |
> |
case BS_ADD: /* add to count */ |
| 70 |
> |
complist[i].nr += clist[n].nr; |
| 71 |
> |
clist[n].nr = 0; |
| 72 |
> |
break; |
| 73 |
> |
case BS_ADJ: /* reset count */ |
| 74 |
> |
complist[i].nr = clist[n].nr; |
| 75 |
> |
clist[n].nr = 0; |
| 76 |
> |
break; |
| 77 |
> |
case BS_DEL: /* delete count */ |
| 78 |
> |
if (clist[n].nr == 0 || |
| 79 |
> |
clist[n].nr >= complist[i].nr) |
| 80 |
> |
complist[i].nr = 0; |
| 81 |
> |
else |
| 82 |
> |
complist[i].nr -= clist[n].nr; |
| 83 |
> |
break; |
| 84 |
> |
} |
| 85 |
> |
if (complist[i].nr != oldnr) |
| 86 |
> |
lastin = -1; /* flag sort */ |
| 87 |
> |
break; |
| 88 |
> |
} |
| 89 |
> |
if (i >= complen) |
| 90 |
> |
clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); |
| 91 |
> |
} |
| 92 |
> |
/* complete list operations */ |
| 93 |
|
switch (op) { |
| 94 |
|
case BS_NEW: /* new computation set */ |
| 95 |
< |
if (complen) |
| 95 |
> |
listpos = 0; lastin = -1; |
| 96 |
> |
if (complen) /* free old list */ |
| 97 |
|
free((char *)complist); |
| 98 |
< |
if (nents <= 0) { |
| 99 |
< |
complist = NULL; |
| 72 |
< |
listpos = complen = 0; |
| 73 |
< |
lastin = -1; |
| 98 |
> |
complist = NULL; |
| 99 |
> |
if (!(complen = nents)) |
| 100 |
|
return; |
| 75 |
– |
} |
| 101 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
| 102 |
|
if (complist == NULL) |
| 103 |
|
goto memerr; |
| 104 |
|
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
| 80 |
– |
complen = nents; /* finish initialization below */ |
| 105 |
|
break; |
| 106 |
|
case BS_ADD: /* add to computation set */ |
| 107 |
|
case BS_ADJ: /* adjust set quantities */ |
| 108 |
|
if (nents <= 0) |
| 109 |
|
return; |
| 110 |
< |
/* merge any common members */ |
| 87 |
< |
for (n = 0; n < nents; n++) { |
| 88 |
< |
for (i = 0; i < complen; i++) |
| 89 |
< |
if (clist[n].bi == complist[i].bi && |
| 90 |
< |
clist[n].hd == complist[i].hd) { |
| 91 |
< |
int oldnr = complist[i].nr; |
| 92 |
< |
if (op == BS_ADD) |
| 93 |
< |
complist[i].nr += clist[n].nr; |
| 94 |
< |
else /* op == BS_ADJ */ |
| 95 |
< |
complist[i].nr = clist[n].nr; |
| 96 |
< |
clist[n].nr = 0; |
| 97 |
< |
clist[n].nc = complist[i].nc; |
| 98 |
< |
if (complist[i].nr != oldnr) |
| 99 |
< |
lastin = -1; /* flag sort */ |
| 100 |
< |
break; |
| 101 |
< |
} |
| 102 |
< |
if (i >= complen) |
| 103 |
< |
clist[n].nc = bnrays(hdlist[clist[n].hd], |
| 104 |
< |
clist[n].bi); |
| 105 |
< |
} |
| 106 |
< |
/* sort updated list */ |
| 107 |
< |
sortcomplist(); |
| 108 |
< |
/* sort new entries */ |
| 110 |
> |
sortcomplist(); /* sort updated list & new entries */ |
| 111 |
|
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
| 112 |
|
/* what can't we satisfy? */ |
| 113 |
|
for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) |
| 114 |
|
; |
| 115 |
< |
if (op == BS_ADJ) |
| 116 |
< |
nents = n; |
| 115 |
> |
if (op == BS_ADJ) { /* don't regenerate adjusted beams */ |
| 116 |
> |
for (i = n; i < nents && clist[i].nr > 0; i++) |
| 117 |
> |
; |
| 118 |
> |
nents = i; |
| 119 |
> |
} |
| 120 |
|
if (n) { /* allocate space for merged list */ |
| 121 |
|
PACKHEAD *newlist; |
| 122 |
|
newlist = (PACKHEAD *)malloc( |
| 134 |
|
lastin = complen-1; /* list is now sorted */ |
| 135 |
|
break; |
| 136 |
|
case BS_DEL: /* delete from computation set */ |
| 137 |
< |
if (nents <= 0) |
| 133 |
< |
return; |
| 134 |
< |
/* find each member */ |
| 135 |
< |
for (i = 0; i < complen; i++) |
| 136 |
< |
for (n = 0; n < nents; n++) |
| 137 |
< |
if (clist[n].bi == complist[i].bi && |
| 138 |
< |
clist[n].hd == complist[i].hd) { |
| 139 |
< |
if (clist[n].nr == 0 || |
| 140 |
< |
clist[n].nr >= complist[i].nr) |
| 141 |
< |
complist[i].nr = 0; |
| 142 |
< |
else |
| 143 |
< |
complist[i].nr -= clist[n].nr; |
| 144 |
< |
lastin = -1; /* flag full sort */ |
| 145 |
< |
break; |
| 146 |
< |
} |
| 147 |
< |
return; /* no display */ |
| 137 |
> |
return; /* already done */ |
| 138 |
|
default: |
| 139 |
|
error(CONSISTENCY, "bundle_set called with unknown operation"); |
| 140 |
|
} |
| 141 |
< |
if (outdev != NULL) { /* load and display beams we have */ |
| 142 |
< |
register HDBEAMI *hb; |
| 143 |
< |
|
| 144 |
< |
hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); |
| 145 |
< |
for (i = 0; i < nents; i++) { |
| 146 |
< |
hb[i].h = hdlist[clist[i].hd]; |
| 147 |
< |
hb[i].b = clist[i].bi; |
| 158 |
< |
} |
| 159 |
< |
hdloadbeams(hb, nents, dispbeam); |
| 160 |
< |
free((char *)hb); |
| 141 |
> |
if (outdev == NULL) /* nothing to display? */ |
| 142 |
> |
return; |
| 143 |
> |
/* load and display beams we have */ |
| 144 |
> |
hb = (HDBEAMI *)malloc(nents*sizeof(HDBEAMI)); |
| 145 |
> |
for (i = 0; i < nents; i++) { |
| 146 |
> |
hb[i].h = hdlist[clist[i].hd]; |
| 147 |
> |
hb[i].b = clist[i].bi; |
| 148 |
|
} |
| 149 |
< |
if (op == BS_NEW) { |
| 150 |
< |
done_packets(flush_queue()); /* empty queue, so we can... */ |
| 164 |
< |
for (i = 0; i < complen; i++) /* ...get number computed */ |
| 165 |
< |
complist[i].nc = bnrays(hdlist[complist[i].hd], |
| 166 |
< |
complist[i].bi); |
| 167 |
< |
listpos = 0; |
| 168 |
< |
lastin = -1; /* flag for initial sort */ |
| 169 |
< |
} |
| 149 |
> |
hdloadbeams(hb, nents, dispbeam); |
| 150 |
> |
free((char *)hb); |
| 151 |
|
return; |
| 152 |
|
memerr: |
| 153 |
|
error(SYSTEM, "out of memory in bundle_set"); |
| 193 |
|
double frac; |
| 194 |
|
int i; |
| 195 |
|
register int j, k; |
| 196 |
< |
/* free old list */ |
| 197 |
< |
if (complen > 0) |
| 196 |
> |
/* free old list and empty queue */ |
| 197 |
> |
if (complen > 0) { |
| 198 |
|
free((char *)complist); |
| 199 |
+ |
done_packets(flush_queue()); |
| 200 |
+ |
} |
| 201 |
|
/* allocate beam list */ |
| 202 |
|
complen = 0; |
| 203 |
|
for (j = 0; hdlist[j] != NULL; j++) |
| 208 |
|
/* compute beam weights */ |
| 209 |
|
k = 0; |
| 210 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
| 211 |
< |
frac = 512. * hdlist[j]->wg[0] * |
| 212 |
< |
hdlist[j]->wg[1] * hdlist[j]->wg[2]; |
| 213 |
< |
if (frac < 0.) frac = -frac; |
| 211 |
> |
frac = 512. * VLEN(hdlist[j]->wg[0]) * |
| 212 |
> |
VLEN(hdlist[j]->wg[1]) * |
| 213 |
> |
VLEN(hdlist[j]->wg[2]); |
| 214 |
|
for (i = nbeams(hdlist[j]); i > 0; i--) { |
| 215 |
|
complist[k].hd = j; |
| 216 |
|
complist[k].bi = i; |
| 217 |
|
complist[k].nr = frac*beamvolume(hdlist[j], i) + 0.5; |
| 218 |
+ |
complist[k].nc = bnrays(hdlist[j], i); |
| 219 |
|
wtotal += complist[k++].nr; |
| 220 |
|
} |
| 221 |
|
} |
| 226 |
|
frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); |
| 227 |
|
while (k--) |
| 228 |
|
complist[k].nr = frac * complist[k].nr; |
| 229 |
< |
listpos = 0; lastin = -1; /* flag initial sort */ |
| 229 |
> |
listpos = 0; lastin = -1; /* perform initial sort */ |
| 230 |
> |
sortcomplist(); |
| 231 |
|
} |
| 232 |
|
|
| 233 |
|
|