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 |
120 |
|
for (i = 0; i < nents; i++) |
121 |
|
if (clist[i].nr > n) |
122 |
|
n = clist[i].nr; |
123 |
< |
p = (PACKHEAD *)malloc(sizeof(PACKHEAD) + n*sizeof(RAYVAL)); |
123 |
> |
p = (PACKHEAD *)malloc(packsiz(n)); |
124 |
|
if (p == NULL) |
125 |
|
goto memerr; |
126 |
|
/* display what we have */ |
127 |
|
for (i = 0; i < nents; i++) |
128 |
|
if ((b = hdgetbeam(hdlist[clist[i].hd], clist[i].bi)) != NULL) { |
129 |
< |
bcopy((char *)hdbray(b), (char *)(p+1), |
129 |
> |
bcopy((char *)hdbray(b), (char *)packra(p), |
130 |
|
(p->nr=b->nrm)*sizeof(RAYVAL)); |
131 |
< |
disp_packet((PACKET *)p); |
131 |
> |
disp_packet(p); |
132 |
|
} |
133 |
|
free((char *)p); /* clean up */ |
134 |
|
return; |
236 |
|
while (k--) |
237 |
|
complist[k].nr = frac * complist[k].nr; |
238 |
|
} |
239 |
< |
listpos = 0; lastin = -1; |
239 |
> |
listpos = 0; lastin = -1; /* flag initial sort */ |
240 |
|
} |
241 |
|
|
242 |
|
|
272 |
|
done_packets(flush_queue()); |
273 |
|
if (complen <= 0) /* check to see if there is even a list */ |
274 |
|
return; |
275 |
< |
if (lastin < 0) /* flag to sort entire list */ |
275 |
> |
if (lastin < 0 || listpos*4 >= complen*3) |
276 |
|
qsort((char *)complist, complen, sizeof(PACKHEAD), beamcmp); |
277 |
|
else if (listpos) { /* else sort and merge sublist */ |
278 |
|
list2 = (PACKHEAD *)malloc(listpos*sizeof(PACKHEAD)); |
294 |
|
for (i = complen; i-- && complist[i].nr <= |
295 |
|
bnrays(hdlist[complist[i].hd],complist[i].bi); ) |
296 |
|
; |
297 |
< |
if (i < complen-1) { |
297 |
> |
if (i < 0) { |
298 |
> |
free((char *)complist); |
299 |
> |
complist = NULL; |
300 |
> |
complen = 0; |
301 |
> |
} else if (i < complen-1) { |
302 |
|
list2 = (PACKHEAD *)realloc((char *)complist, |
303 |
|
(i+1)*sizeof(PACKHEAD)); |
304 |
|
if (list2 != NULL) { |