| 119 |
|
if (pid < 0) { |
| 120 |
|
fprintf(stderr, "%s: cannot fork subprocess\n", |
| 121 |
|
progname); |
| 122 |
+ |
await_children(nchild); |
| 123 |
|
exit(1); |
| 124 |
|
} |
| 125 |
|
++nchild; /* subprocess started */ |
| 272 |
|
return(best.amt); |
| 273 |
|
} |
| 274 |
|
|
| 274 |
– |
#ifdef DEBUG |
| 275 |
– |
static char * |
| 276 |
– |
thetaphi(const FVECT v) |
| 277 |
– |
{ |
| 278 |
– |
static char buf[128]; |
| 279 |
– |
double theta, phi; |
| 280 |
– |
|
| 281 |
– |
theta = 180./M_PI*acos(v[2]); |
| 282 |
– |
phi = 180./M_PI*atan2(v[1],v[0]); |
| 283 |
– |
sprintf(buf, "(%.0f,%.0f)", theta, phi); |
| 284 |
– |
|
| 285 |
– |
return(buf); |
| 286 |
– |
} |
| 287 |
– |
#endif |
| 288 |
– |
|
| 275 |
|
/* Compute and insert migration along directed edge (may fork child) */ |
| 276 |
|
static MIGRATION * |
| 277 |
|
create_migration(RBFNODE *from_rbf, RBFNODE *to_rbf) |
| 281 |
|
MIGRATION *newmig; |
| 282 |
|
double *src_rem, *dst_rem; |
| 283 |
|
double total_rem = 1., move_amt; |
| 284 |
< |
int i; |
| 284 |
> |
int i, j; |
| 285 |
|
/* check if exists already */ |
| 286 |
|
for (newmig = from_rbf->ejl; newmig != NULL; |
| 287 |
|
newmig = nextedge(from_rbf,newmig)) |
| 300 |
|
exit(1); |
| 301 |
|
} |
| 302 |
|
#ifdef DEBUG |
| 303 |
< |
fprintf(stderr, "Building path from (theta,phi) %s ", |
| 304 |
< |
thetaphi(from_rbf->invec)); |
| 305 |
< |
fprintf(stderr, "to %s with %d x %d matrix\n", |
| 306 |
< |
thetaphi(to_rbf->invec), |
| 303 |
> |
fprintf(stderr, "Building path from (theta,phi) (%.0f,%.0f) ", |
| 304 |
> |
get_theta180(from_rbf->invec), |
| 305 |
> |
get_phi360(from_rbf->invec)); |
| 306 |
> |
fprintf(stderr, "to (%.0f,%.0f) with %d x %d matrix\n", |
| 307 |
> |
get_theta180(to_rbf->invec), |
| 308 |
> |
get_phi360(to_rbf->invec), |
| 309 |
|
from_rbf->nrbf, to_rbf->nrbf); |
| 310 |
|
#endif |
| 311 |
|
/* starting quantities */ |
| 312 |
|
memset(newmig->mtx, 0, sizeof(float)*from_rbf->nrbf*to_rbf->nrbf); |
| 313 |
|
for (i = from_rbf->nrbf; i--; ) |
| 314 |
|
src_rem[i] = rbf_volume(&from_rbf->rbfa[i]) / from_rbf->vtotal; |
| 315 |
< |
for (i = to_rbf->nrbf; i--; ) |
| 316 |
< |
dst_rem[i] = rbf_volume(&to_rbf->rbfa[i]) / to_rbf->vtotal; |
| 315 |
> |
for (j = to_rbf->nrbf; j--; ) |
| 316 |
> |
dst_rem[j] = rbf_volume(&to_rbf->rbfa[j]) / to_rbf->vtotal; |
| 317 |
> |
|
| 318 |
|
do { /* move a bit at a time */ |
| 319 |
|
move_amt = migration_step(newmig, src_rem, dst_rem, &pmtx); |
| 320 |
|
total_rem -= move_amt; |
| 332 |
– |
#ifdef DEBUG |
| 333 |
– |
if (!nchild) |
| 334 |
– |
fprintf(stderr, "\r%.9f remaining...", total_rem); |
| 335 |
– |
#endif |
| 321 |
|
} while ((total_rem > end_thresh) & (move_amt > 0)); |
| 322 |
< |
#ifdef DEBUG |
| 338 |
< |
if (!nchild) fputs("done.\n", stderr); |
| 339 |
< |
else fprintf(stderr, "finished with %.9f remaining\n", total_rem); |
| 340 |
< |
#endif |
| 322 |
> |
|
| 323 |
|
for (i = from_rbf->nrbf; i--; ) { /* normalize final matrix */ |
| 324 |
< |
float nf = rbf_volume(&from_rbf->rbfa[i]); |
| 343 |
< |
int j; |
| 324 |
> |
double nf = rbf_volume(&from_rbf->rbfa[i]); |
| 325 |
|
if (nf <= FTINY) continue; |
| 326 |
|
nf = from_rbf->vtotal / nf; |
| 327 |
|
for (j = to_rbf->nrbf; j--; ) |
| 328 |
< |
mtx_coef(newmig,i,j) *= nf; |
| 328 |
> |
mtx_coef(newmig,i,j) *= nf; /* row now sums to 1.0 */ |
| 329 |
|
} |
| 330 |
|
end_subprocess(); /* exit here if subprocess */ |
| 331 |
|
free_routes(&pmtx); /* free working arrays */ |