| 5 |
|
* General component matrix combiner, operating on a row at a time. |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
– |
#include <errno.h> |
| 8 |
|
#include <math.h> |
| 9 |
|
#include "platform.h" |
| 10 |
+ |
#include "rtprocess.h" |
| 11 |
|
#include "rtio.h" |
| 12 |
– |
#include "resolu.h" |
| 12 |
|
#include "rmatrix.h" |
| 13 |
|
#include "calcomp.h" |
| 15 |
– |
#include "paths.h" |
| 14 |
|
|
| 15 |
|
#ifndef M_PI |
| 16 |
|
#define M_PI 3.14159265358979323846 |
| 43 |
|
RMATRIX *mcat = NULL; /* final concatenation */ |
| 44 |
|
int mcat_last = 0; /* goes after trailing ops? */ |
| 45 |
|
|
| 46 |
< |
int in_nrows; /* input row count */ |
| 47 |
< |
#define in_ncols (mop[0].rmp->ncols) /* input column count */ |
| 46 |
> |
int in_nrows; /* number of input rows (or 0) */ |
| 47 |
> |
#define in_ncols (mop[0].rmp->ncols) /* number of input columns */ |
| 48 |
|
#define in_ncomp (mop[0].rmp->ncomp) /* input #components */ |
| 49 |
|
|
| 50 |
|
extern int nowarn; /* turn off warnings? */ |
| 53 |
|
int cur_col; /* current input/output column */ |
| 54 |
|
int cur_chan; /* if we're looping channels */ |
| 55 |
|
|
| 56 |
+ |
SUBPROC *cproc = NULL; /* child process array */ |
| 57 |
+ |
int nchildren = 0; /* # of child processes */ |
| 58 |
+ |
int inchild = -1; /* our child ID (-1: parent) */ |
| 59 |
+ |
|
| 60 |
|
static int checksymbolic(ROPMAT *rop); |
| 61 |
|
|
| 62 |
|
static int |
| 188 |
|
{ |
| 189 |
|
const int nc = rop->imx.ncomp; |
| 190 |
|
const int dt = rop->imx.dtype; |
| 191 |
+ |
double cf = 1; |
| 192 |
|
int i, j; |
| 193 |
|
/* check suffix => reference file */ |
| 194 |
|
if (strchr(rop->preop.csym, '.') > rop->preop.csym) |
| 209 |
|
int comp = 0; |
| 210 |
|
switch (rop->preop.csym[j]) { |
| 211 |
|
case 'B': |
| 212 |
+ |
case 'b': |
| 213 |
|
++comp; |
| 214 |
|
/* fall through */ |
| 215 |
|
case 'G': |
| 216 |
+ |
case 'g': |
| 217 |
|
++comp; |
| 218 |
|
/* fall through */ |
| 219 |
|
case 'R': |
| 220 |
+ |
case 'r': |
| 221 |
+ |
if (rop->preop.csym[j] <= 'Z') |
| 222 |
+ |
cf = 1./WHTEFFICACY; |
| 223 |
|
if (dt == DTxyze) { |
| 224 |
|
for (i = 3; i--; ) |
| 225 |
< |
rop->preop.cmat[j*nc+i] = 1./WHTEFFICACY * |
| 218 |
< |
xyz2rgbmat[comp][i]; |
| 225 |
> |
rop->preop.cmat[j*nc+i] = cf*xyz2rgbmat[comp][i]; |
| 226 |
|
} else if (nc == 3) |
| 227 |
|
rop->preop.cmat[j*nc+comp] = 1.; |
| 228 |
|
else |
| 229 |
|
rgbrow(rop, j, comp); |
| 230 |
|
break; |
| 231 |
|
case 'Z': |
| 232 |
+ |
case 'z': |
| 233 |
|
++comp; |
| 234 |
|
/* fall through */ |
| 235 |
|
case 'Y': |
| 236 |
+ |
case 'y': |
| 237 |
|
++comp; |
| 238 |
|
/* fall through */ |
| 239 |
|
case 'X': |
| 240 |
+ |
case 'x': |
| 241 |
+ |
if ((rop->preop.csym[j] <= 'Z') & (dt != DTxyze)) |
| 242 |
+ |
cf = WHTEFFICACY; |
| 243 |
|
if (dt == DTxyze) { |
| 244 |
|
rop->preop.cmat[j*nc+comp] = 1.; |
| 245 |
|
} else if (nc == 3) { |
| 251 |
|
else |
| 252 |
|
xyzrow(rop, j, comp); |
| 253 |
|
|
| 254 |
< |
for (i = nc*(dt != DTxyze); i--; ) |
| 255 |
< |
rop->preop.cmat[j*nc+i] *= WHTEFFICACY; |
| 254 |
> |
for (i = nc*(cf != 1); i--; ) |
| 255 |
> |
rop->preop.cmat[j*nc+i] *= cf; |
| 256 |
|
break; |
| 257 |
|
case 'S': /* scotopic (il)luminance */ |
| 258 |
+ |
cf = WHTSCOTOPIC; |
| 259 |
+ |
/* fall through */ |
| 260 |
+ |
case 's': |
| 261 |
|
sensrow(rop, j, scolor2scotopic); |
| 262 |
< |
for (i = nc; i--; ) |
| 263 |
< |
rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC; |
| 262 |
> |
for (i = nc*(cf != 1); i--; ) |
| 263 |
> |
rop->preop.cmat[j*nc+i] *= cf; |
| 264 |
|
break; |
| 265 |
|
case 'M': /* melanopic (il)luminance */ |
| 266 |
+ |
cf = WHTMELANOPIC; |
| 267 |
+ |
/* fall through */ |
| 268 |
+ |
case 'm': |
| 269 |
|
sensrow(rop, j, scolor2melanopic); |
| 270 |
< |
for (i = nc; i--; ) |
| 271 |
< |
rop->preop.cmat[j*nc+i] *= WHTMELANOPIC; |
| 270 |
> |
for (i = nc*(cf != 1); i--; ) |
| 271 |
> |
rop->preop.cmat[j*nc+i] *= cf; |
| 272 |
|
break; |
| 273 |
|
case 'A': /* average component */ |
| 274 |
+ |
case 'a': |
| 275 |
|
for (i = nc; i--; ) |
| 276 |
|
rop->preop.cmat[j*nc+i] = 1./(double)nc; |
| 277 |
|
break; |
| 286 |
|
memcpy(rop->rmp->wlpart, WLPART, sizeof(rop->rmp->wlpart)); |
| 287 |
|
rop->rmp->ncomp = rop->preop.clen / nc; |
| 288 |
|
/* decide on output type */ |
| 289 |
< |
if (!strcmp(rop->preop.csym, "XYZ")) { |
| 289 |
> |
if (!strcasecmp(rop->preop.csym, "XYZ")) { |
| 290 |
|
if (dt <= DTspec) |
| 291 |
|
rop->rmp->dtype = DTxyze; |
| 292 |
< |
} else if (!strcmp(rop->preop.csym, "RGB")) { |
| 292 |
> |
} else if (!strcasecmp(rop->preop.csym, "RGB")) { |
| 293 |
|
if (dt <= DTspec) |
| 294 |
|
rop->rmp->dtype = DTrgbe; |
| 295 |
|
} else if (rop->rmp->dtype == DTspec) |
| 393 |
|
return(0); |
| 394 |
|
rmx_free(res); |
| 395 |
|
} else if (dst != src) |
| 396 |
< |
memcpy(dst->mtx, src->mtx, |
| 378 |
< |
sizeof(double)*dst->ncomp*dst->ncols*dst->nrows); |
| 396 |
> |
memcpy(dst->mtx, src->mtx, rmx_array_size(dst)); |
| 397 |
|
if (ro->nsf == dst->ncomp) |
| 398 |
|
rmx_scale(dst, ro->sca); |
| 399 |
|
return(1); |
| 487 |
|
fprintf(stderr, "%s: warning - data type mismatch\n", |
| 488 |
|
mop[i].inspec); |
| 489 |
|
if (!i) { |
| 472 |
– |
imp->nrows = in_nrows = mop[0].rmp->nrows; |
| 490 |
|
imp->ncols = mop[0].rmp->ncols; |
| 491 |
|
imp->ncomp = mop[0].rmp->ncomp; |
| 492 |
|
memcpy(imp->wlpart, mop[0].rmp->wlpart, sizeof(imp->wlpart)); |
| 493 |
< |
} else if ((mop[i].rmp->nrows != imp->nrows) | |
| 494 |
< |
(mop[i].rmp->ncols != imp->ncols) | |
| 495 |
< |
(mop[i].rmp->ncomp != imp->ncomp)) { |
| 493 |
> |
} else if ((mop[i].rmp->ncols != imp->ncols) | |
| 494 |
> |
(mop[i].rmp->ncomp != imp->ncomp) | |
| 495 |
> |
((in_nrows > 0) & (mop[i].rmp->nrows > 0) & |
| 496 |
> |
(mop[i].rmp->nrows != in_nrows))) { |
| 497 |
|
fprintf(stderr, "%s: mismatch in size or #components\n", |
| 498 |
|
mop[i].inspec); |
| 499 |
|
return(0); |
| 500 |
|
} /* XXX should check wlpart? */ |
| 501 |
+ |
if (in_nrows <= 0) |
| 502 |
+ |
in_nrows = imp->nrows = mop[i].rmp->nrows; |
| 503 |
|
} /* set up .cal environment */ |
| 504 |
|
esupport |= E_VARIABLE|E_FUNCTION|E_RCONST; |
| 505 |
|
esupport &= ~(E_OUTCHAN|E_INCHAN); |
| 541 |
|
} |
| 542 |
|
|
| 543 |
|
static int |
| 544 |
< |
combine_input(ROPMAT *res, FILE *fout) |
| 544 |
> |
spawned_children(int np) |
| 545 |
|
{ |
| 546 |
< |
int set_r, set_c; |
| 547 |
< |
RMATRIX *tmp = NULL; |
| 548 |
< |
int co_set; |
| 549 |
< |
int i; |
| 550 |
< |
/* allocate input row buffers */ |
| 546 |
> |
size_t recsize = 0; |
| 547 |
> |
int i, rv; |
| 548 |
> |
|
| 549 |
> |
#if defined(_WIN32) || defined(_WIN64) |
| 550 |
> |
if (np > 1) { |
| 551 |
> |
fputs("Warning: only one process under Windows\n", stderr); |
| 552 |
> |
np = 1; |
| 553 |
> |
} else |
| 554 |
> |
#endif |
| 555 |
> |
if ((in_nrows > 0) & (np > in_nrows)) |
| 556 |
> |
np = in_nrows; |
| 557 |
> |
/* we'll be doing a row at a time */ |
| 558 |
|
for (i = 0; i < nmats; i++) { |
| 559 |
< |
mop[i].imx.nrows = 1; /* we'll be doing a row at a time */ |
| 559 |
> |
mop[i].imx.nrows = 1; |
| 560 |
|
if (!rmx_prepare(&mop[i].imx)) |
| 561 |
|
goto memerror; |
| 562 |
+ |
recsize += rmx_array_size(&mop[i].imx); |
| 563 |
|
if (mop[i].rmp != &mop[i].imx) { |
| 564 |
|
mop[i].rmp->nrows = 1; |
| 565 |
|
if (!rmx_prepare(mop[i].rmp)) |
| 566 |
|
goto memerror; |
| 567 |
|
} |
| 568 |
|
} |
| 569 |
< |
/* prep output row buffers */ |
| 570 |
< |
if (mcat || res->preop.clen > 0) { |
| 571 |
< |
if (!split_input(res)) /* need separate buffer */ |
| 569 |
> |
/* prep output row buffer */ |
| 570 |
> |
if (mcat || mop[nmats].preop.clen > 0) { |
| 571 |
> |
if (!split_input(&mop[nmats])) /* need separate buffer */ |
| 572 |
|
return(0); |
| 573 |
< |
if (res->preop.clen > 0) |
| 574 |
< |
res->rmp->ncomp = res->preop.clen / res->imx.ncomp; |
| 575 |
< |
res->rmp->nrows = 1; |
| 576 |
< |
if (!mcat | !mcat_last && !rmx_prepare(res->rmp)) |
| 573 |
> |
if (mop[nmats].preop.clen > 0) |
| 574 |
> |
mop[nmats].rmp->ncomp = mop[nmats].preop.clen / |
| 575 |
> |
mop[nmats].imx.ncomp; |
| 576 |
> |
mop[nmats].rmp->nrows = 1; |
| 577 |
> |
if (!mcat | !mcat_last && !rmx_prepare(mop[nmats].rmp)) |
| 578 |
|
goto memerror; |
| 579 |
|
} |
| 580 |
+ |
mop[nmats].imx.nrows = 1; |
| 581 |
+ |
if (!rmx_prepare(&mop[nmats].imx)) |
| 582 |
+ |
goto memerror; |
| 583 |
+ |
if (np <= 1) { /* single process return point */ |
| 584 |
+ |
#ifdef getc_unlocked |
| 585 |
+ |
for (i = 0; i < nmats; i++) |
| 586 |
+ |
flockfile(mop[i].infp); |
| 587 |
+ |
flockfile(stdout); |
| 588 |
+ |
#endif |
| 589 |
+ |
return(0); |
| 590 |
+ |
} |
| 591 |
+ |
fflush(stdout); /* flush header & spawn children */ |
| 592 |
+ |
cproc = (SUBPROC *)malloc(sizeof(SUBPROC)*np); |
| 593 |
+ |
if (!cproc) |
| 594 |
+ |
goto memerror; |
| 595 |
+ |
nchildren = np; |
| 596 |
+ |
for (i = 0; i < np; i++) { |
| 597 |
+ |
cproc[i].flags = PF_FILT_OUT; |
| 598 |
+ |
cproc[i].w = dup(1); |
| 599 |
+ |
cproc[i].r = 0; |
| 600 |
+ |
cproc[i].pid = -1; |
| 601 |
+ |
rv = open_process(&cproc[i], NULL); |
| 602 |
+ |
if (rv <= 0) break; |
| 603 |
+ |
if (!i && 2*rv >= recsize) { |
| 604 |
+ |
fputs("Problem too small for multi-processing\n", |
| 605 |
+ |
stderr); |
| 606 |
+ |
close_processes(cproc, 1); |
| 607 |
+ |
exit(1); |
| 608 |
+ |
} |
| 609 |
+ |
} |
| 610 |
+ |
if (rv < 0) { |
| 611 |
+ |
perror("fork"); |
| 612 |
+ |
close_processes(cproc, i); |
| 613 |
+ |
exit(1); |
| 614 |
+ |
} |
| 615 |
+ |
if (rv > 0) /* parent return? */ |
| 616 |
+ |
return(1); |
| 617 |
+ |
inchild = i; /* our child index */ |
| 618 |
+ |
while (i-- > 0) /* don't share siblings' pipes */ |
| 619 |
+ |
close(cproc[i].w); |
| 620 |
+ |
fpurge(stdin); /* discard previous matrix input */ |
| 621 |
+ |
#ifdef getc_unlocked |
| 622 |
+ |
flockfile(stdin); |
| 623 |
+ |
#endif |
| 624 |
+ |
for (i = 0; i < nmats; i++) { |
| 625 |
+ |
if (mop[i].infp != stdin) |
| 626 |
+ |
fclose(mop[i].infp); /* ! pclose() */ |
| 627 |
+ |
mop[i].infp = stdin; |
| 628 |
+ |
mop[i].imx.dtype = DTdouble; |
| 629 |
+ |
} |
| 630 |
+ |
return(0); /* child return */ |
| 631 |
+ |
memerror: |
| 632 |
+ |
fputs("Out of memory in spawned_children()\n", stderr); |
| 633 |
+ |
exit(1); |
| 634 |
+ |
} |
| 635 |
+ |
|
| 636 |
+ |
static int |
| 637 |
+ |
parent_loop() |
| 638 |
+ |
{ |
| 639 |
+ |
FILE **outfp = (FILE **)malloc(nchildren*sizeof(FILE *)); |
| 640 |
+ |
int i; |
| 641 |
+ |
|
| 642 |
+ |
if (!outfp) goto memerror; |
| 643 |
+ |
for (i = 0; i < nchildren; i++) { |
| 644 |
+ |
outfp[i] = fdopen(cproc[i].w, "w"); |
| 645 |
+ |
if (!outfp[i]) goto memerror; |
| 646 |
+ |
#ifdef getc_unlocked |
| 647 |
+ |
flockfile(outfp[i]); |
| 648 |
+ |
#endif |
| 649 |
+ |
} |
| 650 |
+ |
#ifdef getc_unlocked |
| 651 |
+ |
for (i = 0; i < nmats; i++) |
| 652 |
+ |
flockfile(mop[i].infp); |
| 653 |
+ |
#endif |
| 654 |
+ |
for (cur_row = 0; (in_nrows <= 0) | (cur_row < in_nrows); cur_row++) { |
| 655 |
+ |
FILE *ofp = outfp[cur_row % nchildren]; |
| 656 |
+ |
for (i = 0; i < nmats; i++) |
| 657 |
+ |
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
| 658 |
+ |
if (cur_row > in_nrows) /* unknown #input rows? */ |
| 659 |
+ |
break; |
| 660 |
+ |
fprintf(stderr, "%s: read error at row %d\n", |
| 661 |
+ |
mop[i].inspec, cur_row); |
| 662 |
+ |
return(0); |
| 663 |
+ |
} |
| 664 |
+ |
if (i < nmats) |
| 665 |
+ |
break; |
| 666 |
+ |
for (i = 0; i < nmats; i++) |
| 667 |
+ |
if (!rmx_write_data(mop[i].imx.mtx, mop[i].imx.ncomp, |
| 668 |
+ |
mop[i].imx.ncols, DTdouble, ofp)) |
| 669 |
+ |
return(0); |
| 670 |
+ |
if (fflush(ofp) == EOF) |
| 671 |
+ |
return(0); |
| 672 |
+ |
} |
| 673 |
+ |
for (i = 0; i < nchildren; i++) { |
| 674 |
+ |
sleep(2); /* try to maintain order */ |
| 675 |
+ |
fclose(outfp[i]); |
| 676 |
+ |
} |
| 677 |
+ |
free(outfp); |
| 678 |
+ |
i = close_processes(cproc, nchildren); |
| 679 |
+ |
free(cproc); cproc = NULL; |
| 680 |
+ |
if (i < 0) { |
| 681 |
+ |
fputs("Warning: missing child in parent_loop()\n", stderr); |
| 682 |
+ |
return(1); |
| 683 |
+ |
} |
| 684 |
+ |
if (i > 0) { |
| 685 |
+ |
fprintf(stderr, "Child exited with status %d\n", i); |
| 686 |
+ |
return(0); |
| 687 |
+ |
} |
| 688 |
+ |
return(1); |
| 689 |
+ |
memerror: |
| 690 |
+ |
fputs("Out of memory in parent_loop()\n", stderr); |
| 691 |
+ |
exit(1); |
| 692 |
+ |
} |
| 693 |
+ |
|
| 694 |
+ |
static int |
| 695 |
+ |
combine_input() |
| 696 |
+ |
{ |
| 697 |
+ |
const int row0 = (inchild >= 0)*inchild; |
| 698 |
+ |
const int rstep = nchildren + !nchildren; |
| 699 |
+ |
ROPMAT *res = &mop[nmats]; |
| 700 |
+ |
int set_r, set_c; |
| 701 |
+ |
RMATRIX *tmp = NULL; |
| 702 |
+ |
int co_set; |
| 703 |
+ |
int i; |
| 704 |
+ |
|
| 705 |
|
if (mcat && mcat_last && |
| 706 |
|
!(tmp = rmx_alloc(1, res->imx.ncols, res->rmp->ncomp))) |
| 707 |
|
goto memerror; |
| 554 |
– |
res->imx.nrows = 1; |
| 555 |
– |
if (!rmx_prepare(&res->imx)) |
| 556 |
– |
goto memerror; |
| 708 |
|
/* figure out what the user set */ |
| 709 |
|
co_set = fundefined("co"); |
| 710 |
|
if (!co_set) |
| 719 |
|
set_c = varlookup("c") != NULL && !vardefined("c"); |
| 720 |
|
} else /* save a little time */ |
| 721 |
|
set_r = set_c = 0; |
| 722 |
+ |
|
| 723 |
|
/* read/process row-by-row */ |
| 724 |
< |
for (cur_row = 0; cur_row < in_nrows; cur_row++) { |
| 724 |
> |
for (cur_row = row0; (in_nrows <= 0) | (cur_row < in_nrows); cur_row += rstep) { |
| 725 |
|
RMATRIX *mres = NULL; |
| 726 |
< |
for (i = 0; i < nmats; i++) { |
| 726 |
> |
for (i = 0; i < nmats; i++) |
| 727 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
| 728 |
+ |
if (cur_row > in_nrows) /* unknown #input rows? */ |
| 729 |
+ |
break; |
| 730 |
|
fprintf(stderr, "%s: read error at row %d\n", |
| 731 |
|
mop[i].inspec, cur_row); |
| 732 |
|
return(0); |
| 733 |
|
} |
| 734 |
+ |
if (i < nmats) |
| 735 |
+ |
break; |
| 736 |
+ |
for (i = 0; i < nmats; i++) |
| 737 |
|
if (!apply_op(mop[i].rmp, &mop[i].imx, &mop[i].preop)) |
| 738 |
|
return(0); |
| 582 |
– |
} |
| 739 |
|
if (set_r) varset("r", '=', cur_row); |
| 740 |
|
for (cur_col = 0; cur_col < in_ncols; cur_col++) { |
| 741 |
|
if (set_c) varset("c", '=', cur_col); |
| 772 |
|
return(0); |
| 773 |
|
} |
| 774 |
|
rmx_free(mres); mres = NULL; |
| 775 |
+ |
if (inchild >= 0) { /* children share stdout */ |
| 776 |
+ |
i = getc(stdin); /* signals it's our turn */ |
| 777 |
+ |
if (i != EOF) ungetc(i, stdin); |
| 778 |
+ |
} |
| 779 |
|
if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp, |
| 780 |
< |
res->rmp->ncols, res->rmp->dtype, fout)) |
| 780 |
> |
res->rmp->ncols, res->rmp->dtype, stdout)) |
| 781 |
|
return(0); |
| 782 |
+ |
if (inchild >= 0 && fflush(stdout) == EOF) |
| 783 |
+ |
return(0); |
| 784 |
|
} |
| 785 |
< |
#if 0 /* we're about to exit, so who cares? */ |
| 624 |
< |
rmx_free(tmp); /* clean up */ |
| 625 |
< |
rmx_reset(res->rmp); |
| 626 |
< |
rmx_reset(&res->imx); |
| 627 |
< |
for (i = 0; i < nmats; i++) { |
| 628 |
< |
rmx_reset(mop[i].rmp); |
| 629 |
< |
rmx_reset(&mop[i].imx); |
| 630 |
< |
if (mop[i].inspec[0] == '!') |
| 631 |
< |
pclose(mop[i].infp); |
| 632 |
< |
else if (mop[i].inspec != stdin_name) |
| 633 |
< |
fclose(mop[i].infp); |
| 634 |
< |
mop[i].infp = NULL; |
| 635 |
< |
} |
| 636 |
< |
#endif |
| 637 |
< |
return(fflush(fout) != EOF); |
| 785 |
> |
return(inchild >= 0 || fflush(stdout) != EOF); |
| 786 |
|
memerror: |
| 787 |
|
fputs("Out of buffer space in combine_input()\n", stderr); |
| 788 |
|
return(0); |
| 806 |
|
{ |
| 807 |
|
int i; |
| 808 |
|
|
| 809 |
< |
for (i = nmats; i > n2alloc; i--) { |
| 809 |
> |
if (n2alloc == nall) |
| 810 |
> |
return; |
| 811 |
> |
for (i = nall; i > n2alloc; i--) { |
| 812 |
|
rmx_reset(&mop[i].imx); |
| 813 |
|
if (mop[i].rmp != &mop[i].imx) |
| 814 |
|
rmx_free(mop[i].rmp); |
| 818 |
|
fputs("Out of memory in resize_inparr()\n", stderr); |
| 819 |
|
exit(1); |
| 820 |
|
} |
| 821 |
< |
if (n2alloc > nmats) |
| 822 |
< |
memset(mop+nmats, 0, (n2alloc-nmats)*sizeof(ROPMAT)); |
| 821 |
> |
if (n2alloc > nall) |
| 822 |
> |
memset(mop+nall, 0, (n2alloc-nall)*sizeof(ROPMAT)); |
| 823 |
|
nall = n2alloc; |
| 824 |
|
} |
| 825 |
|
|
| 832 |
|
const char *defCsym = NULL; |
| 833 |
|
int echoheader = 1; |
| 834 |
|
int stdin_used = 0; |
| 835 |
+ |
int nproc = 1; |
| 836 |
|
const char *mcat_spec = NULL; |
| 837 |
|
int n2comp = 0; |
| 838 |
|
uby8 comp_ndx[128]; |
| 860 |
|
case 'h': |
| 861 |
|
echoheader = !echoheader; |
| 862 |
|
break; |
| 863 |
+ |
case 'n': |
| 864 |
+ |
nproc = atoi(argv[++i]); |
| 865 |
+ |
if (nproc <= 0) |
| 866 |
+ |
goto userr; |
| 867 |
+ |
break; |
| 868 |
|
case 'e': |
| 869 |
|
if (!n) goto userr; |
| 870 |
|
comp_ndx[n2comp++] = i++; |
| 913 |
|
if (n && !isflt(argv[i+1])) { |
| 914 |
|
mop[nmats].preop.csym = argv[++i]; |
| 915 |
|
mop[nmats].preop.clen = 0; |
| 916 |
+ |
mcat_last = 0; |
| 917 |
|
break; |
| 918 |
|
} |
| 919 |
|
if (n > MAXCOMP*MAXCOMP) n = MAXCOMP*MAXCOMP; |
| 1003 |
|
fprintf(stderr, "%s: unsupported output format\n", argv[0]); |
| 1004 |
|
return(1); |
| 1005 |
|
} |
| 1006 |
+ |
doptimize(1); /* optimize definitions */ |
| 1007 |
+ |
if (spawned_children(nproc)) /* running in parent process? */ |
| 1008 |
+ |
return(parent_loop() ? 0 : 1); |
| 1009 |
|
/* process & write rows */ |
| 1010 |
< |
return(combine_input(&mop[nmats], stdout) ? 0 : 1); |
| 1010 |
> |
return(combine_input() ? 0 : 1); |
| 1011 |
|
stdin_error: |
| 1012 |
|
fprintf(stderr, "%s: %s used for more than one input\n", |
| 1013 |
|
argv[0], stdin_name); |
| 1014 |
|
return(1); |
| 1015 |
|
userr: |
| 1016 |
|
fprintf(stderr, |
| 1017 |
< |
"Usage: %s [-h][-f{adfc}][-e expr][-f file][-s sf .. | -c ce ..] m1 .. -m mcat > mres\n", |
| 1017 |
> |
"Usage: %s [-h][-f{adfc}][-n nproc][-e expr][-f file][-s sf .. | -c ce ..] m1 .. -m mcat > mres\n", |
| 1018 |
|
argv[0]); |
| 1019 |
|
return(1); |
| 1020 |
|
} |