61 |
|
register PACKHEAD *clist; |
62 |
|
int nents; |
63 |
|
{ |
64 |
+ |
int oldnr; |
65 |
|
register int i, n; |
66 |
< |
|
66 |
> |
/* look for common members */ |
67 |
> |
for (n = 0; n < nents; n++) { |
68 |
> |
for (i = 0; i < complen; i++) |
69 |
> |
if (clist[n].bi == complist[i].bi && |
70 |
> |
clist[n].hd == complist[i].hd) { |
71 |
> |
oldnr = complist[i].nr; |
72 |
> |
clist[n].nc = complist[i].nc; |
73 |
> |
switch (op) { |
74 |
> |
case BS_ADD: /* add to count */ |
75 |
> |
complist[i].nr += clist[n].nr; |
76 |
> |
clist[n].nr = 0; |
77 |
> |
break; |
78 |
> |
case BS_ADJ: /* reset count */ |
79 |
> |
complist[i].nr = clist[n].nr; |
80 |
> |
clist[n].nr = 0; |
81 |
> |
break; |
82 |
> |
case BS_DEL: /* delete count */ |
83 |
> |
if (clist[n].nr == 0 || |
84 |
> |
clist[n].nr >= complist[i].nr) |
85 |
> |
complist[i].nr = 0; |
86 |
> |
else |
87 |
> |
complist[i].nr -= clist[n].nr; |
88 |
> |
break; |
89 |
> |
} |
90 |
> |
if (complist[i].nr != oldnr) |
91 |
> |
lastin = -1; /* flag sort */ |
92 |
> |
break; |
93 |
> |
} |
94 |
> |
if (i >= complen) |
95 |
> |
clist[n].nc = bnrays(hdlist[clist[n].hd], clist[n].bi); |
96 |
> |
} |
97 |
> |
/* complete list operations */ |
98 |
|
switch (op) { |
99 |
|
case BS_NEW: /* new computation set */ |
100 |
< |
if (complen) |
100 |
> |
listpos = 0; lastin = -1; |
101 |
> |
if (complen) /* free old list */ |
102 |
|
free((char *)complist); |
103 |
< |
if (nents <= 0) { |
104 |
< |
complist = NULL; |
72 |
< |
listpos = complen = 0; |
73 |
< |
lastin = -1; |
103 |
> |
complist = NULL; |
104 |
> |
if (!(complen = nents)) |
105 |
|
return; |
75 |
– |
} |
106 |
|
complist = (PACKHEAD *)malloc(nents*sizeof(PACKHEAD)); |
107 |
|
if (complist == NULL) |
108 |
|
goto memerr; |
109 |
|
bcopy((char *)clist, (char *)complist, nents*sizeof(PACKHEAD)); |
80 |
– |
complen = nents; /* finish initialization below */ |
110 |
|
break; |
111 |
|
case BS_ADD: /* add to computation set */ |
112 |
|
case BS_ADJ: /* adjust set quantities */ |
113 |
|
if (nents <= 0) |
114 |
|
return; |
115 |
< |
/* 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 */ |
115 |
> |
sortcomplist(); /* sort updated list & new entries */ |
116 |
|
qsort((char *)clist, nents, sizeof(PACKHEAD), beamcmp); |
117 |
|
/* what can't we satisfy? */ |
118 |
|
for (n = 0; n < nents && clist[n].nr > clist[n].nc; n++) |
136 |
|
lastin = complen-1; /* list is now sorted */ |
137 |
|
break; |
138 |
|
case BS_DEL: /* delete from computation set */ |
139 |
< |
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 */ |
139 |
> |
return; /* already done */ |
140 |
|
default: |
141 |
|
error(CONSISTENCY, "bundle_set called with unknown operation"); |
142 |
|
} |
151 |
|
hdloadbeams(hb, nents, dispbeam); |
152 |
|
free((char *)hb); |
153 |
|
} |
162 |
– |
if (op == BS_NEW) { |
163 |
– |
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 |
– |
} |
154 |
|
return; |
155 |
|
memerr: |
156 |
|
error(SYSTEM, "out of memory in bundle_set"); |
229 |
|
frac = 1024.*1024.*16384. / (wtotal*sizeof(RAYVAL)); |
230 |
|
while (k--) |
231 |
|
complist[k].nr = frac * complist[k].nr; |
232 |
< |
listpos = 0; lastin = -1; /* flag initial sort */ |
232 |
> |
listpos = 0; lastin = -1; /* perform initial sort */ |
233 |
> |
sortcomplist(); |
234 |
|
} |
235 |
|
|
236 |
|
|