15 |
|
#define sgn(x) ((x) > 0 ? 1 : (x) < 0 ? -1 : 0) |
16 |
|
|
17 |
|
|
18 |
< |
static PACKHEAD *complist; /* list of beams to compute */ |
19 |
< |
static int complen; /* length of complist */ |
20 |
< |
static int listpos; /* current list position for next_packet */ |
21 |
< |
static int lastin = -1; /* last ordered position in list */ |
18 |
> |
static PACKHEAD *complist=NULL; /* list of beams to compute */ |
19 |
> |
static int complen=0; /* length of complist */ |
20 |
> |
static int listpos=0; /* current list position for next_packet */ |
21 |
> |
static int lastin= -1; /* last ordered position in list */ |
22 |
|
|
23 |
|
|
24 |
|
int |
110 |
|
lastin = -1; /* flag full sort */ |
111 |
|
break; |
112 |
|
} |
113 |
– |
/* sort updated list */ |
114 |
– |
sortcomplist(); |
113 |
|
return; /* no display */ |
114 |
|
default: |
115 |
|
error(CONSISTENCY, "bundle_set called with unknown operation"); |
116 |
|
} |
117 |
< |
n = 0; /* allocate packet holder */ |
117 |
> |
if (outdev == NULL) |
118 |
> |
return; |
119 |
> |
n = 8*RPACKSIZ; /* allocate packet holder */ |
120 |
> |
p = (PACKHEAD *)malloc(packsiz(n)); |
121 |
> |
if (p == NULL) |
122 |
> |
goto memerr; |
123 |
> |
/* display what we have */ |
124 |
|
for (i = 0; i < nents; i++) |
125 |
< |
if (clist[i].nr > n) |
126 |
< |
n = clist[i].nr; |
127 |
< |
p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL)); |
128 |
< |
/* now, display what we can */ |
129 |
< |
for (i = 0; i < nents; i++) |
130 |
< |
if (clist[i].nr > 0 && |
131 |
< |
(b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { |
132 |
< |
bcopy((char *)hdbray(b), (char *)(p+1), |
125 |
> |
if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { |
126 |
> |
if (b->nrm > n) { |
127 |
> |
n = b->nrm; |
128 |
> |
p = (PACKHEAD *)realloc((char *)p, packsiz(n)); |
129 |
> |
if (p == NULL) |
130 |
> |
goto memerr; |
131 |
> |
} |
132 |
> |
bcopy((char *)hdbray(b), (char *)packra(p), |
133 |
|
(p->nr=b->nrm)*sizeof(RAYVAL)); |
134 |
< |
disp_packet((PACKET *)p); |
134 |
> |
p->hd = clist[i].hd; |
135 |
> |
p->bi = clist[i].bi; |
136 |
> |
disp_packet(p); |
137 |
|
} |
138 |
|
free((char *)p); /* clean up */ |
139 |
|
return; |
210 |
|
int lseg[2][3]; |
211 |
|
double frac; |
212 |
|
register int k; |
213 |
+ |
/* free old list */ |
214 |
+ |
if (complen > 0) |
215 |
+ |
free((char *)complist); |
216 |
|
/* allocate beam list */ |
217 |
|
complen = 0; |
218 |
|
for (j = 0; hdlist[j] != NULL; j++) |
241 |
|
while (k--) |
242 |
|
complist[k].nr = frac * complist[k].nr; |
243 |
|
} |
244 |
< |
listpos = 0; lastin = -1; |
244 |
> |
listpos = 0; lastin = -1; /* flag initial sort */ |
245 |
|
} |
246 |
|
|
247 |
|
|
275 |
|
|
276 |
|
/* empty queue */ |
277 |
|
done_packets(flush_queue()); |
278 |
< |
if (complen <= 0) /* check to see if there even is a list */ |
278 |
> |
if (complen <= 0) /* check to see if there is even a list */ |
279 |
|
return; |
280 |
< |
if (lastin < 0) /* flag to sort entire list */ |
280 |
> |
if (lastin < 0 || listpos*4 >= complen*3) |
281 |
|
qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); |
282 |
|
else if (listpos) { /* else sort and merge sublist */ |
283 |
|
list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); |
289 |
|
complist+listpos, complen-listpos); |
290 |
|
free((char *)list2); |
291 |
|
} |
283 |
– |
/* check for all finished */ |
284 |
– |
if (complist[0].nr <= bnrays(hdlist[complist[0].hd],complist[0].bi)) { |
285 |
– |
free((char *)complist); |
286 |
– |
complist = NULL; |
287 |
– |
complen = 0; |
288 |
– |
} |
292 |
|
/* drop satisfied requests */ |
293 |
|
for (i = complen; i-- && complist[i].nr <= |
294 |
|
bnrays(hdlist[complist[i].hd],complist[i].bi); ) |
295 |
|
; |
296 |
< |
if (i < complen-1) { |
296 |
> |
if (i < 0) { |
297 |
> |
free((char *)complist); |
298 |
> |
complist = NULL; |
299 |
> |
complen = 0; |
300 |
> |
} else if (i < complen-1) { |
301 |
|
list2 = (PACKHEAD *)realloc((char *)complist, |
302 |
|
(i+1)*sizeof(PACKHEAD)); |
303 |
|
if (list2 != NULL) { |
328 |
|
int ncomp; |
329 |
|
register int i; |
330 |
|
|
324 |
– |
if (complen <= 0) |
325 |
– |
return(0); |
331 |
|
if (listpos > lastin) /* time to sort the list */ |
332 |
|
sortcomplist(); |
333 |
+ |
if (complen <= 0) |
334 |
+ |
return(0); |
335 |
|
p->hd = complist[listpos].hd; |
336 |
|
p->bi = complist[listpos].bi; |
337 |
|
ncomp = bnrays(hdlist[p->hd],p->bi); |