3 |
|
#endif |
4 |
|
/* |
5 |
|
* General component matrix combiner, operating on a row at a time. |
6 |
+ |
* |
7 |
+ |
* Multi-processing mode under Unix creates children that each work |
8 |
+ |
* on one input row at a time, fed by the original process. Final conversion |
9 |
+ |
* and output to stdout is sorted by last child while its siblings send it |
10 |
+ |
* their record calculations. |
11 |
|
*/ |
12 |
|
|
8 |
– |
#include <signal.h> |
13 |
|
#include <math.h> |
14 |
|
#include "platform.h" |
15 |
|
#include "rtprocess.h" |
21 |
|
#define M_PI 3.14159265358979323846 |
22 |
|
#endif |
23 |
|
|
20 |
– |
#define MAXCOMP MAXCSAMP /* #components we support */ |
21 |
– |
|
24 |
|
/* Unary matrix operation(s) */ |
25 |
|
typedef struct { |
26 |
|
double cmat[MAXCOMP*MAXCOMP]; /* component transformation */ |
59 |
|
SUBPROC *cproc = NULL; /* child process array */ |
60 |
|
int nchildren = 0; /* # of child processes */ |
61 |
|
int inchild = -1; /* our child ID (-1: parent) */ |
60 |
– |
int gpid = -1; /* group process ID (parent) */ |
61 |
– |
int nr_out = 0; /* # of rows output by kids */ |
62 |
|
|
63 |
< |
static int checksymbolic(ROPMAT *rop); |
63 |
> |
extern int checksymbolic(ROPMAT *rop); |
64 |
|
|
65 |
< |
static void |
66 |
< |
on_sigio(int dummy) |
67 |
< |
{ |
68 |
< |
nr_out++; /* happens when child outputs row */ |
69 |
< |
signal(SIGIO, on_sigio); /* reset to maximize portability */ |
70 |
< |
} |
71 |
< |
|
72 |
< |
static int |
65 |
> |
/* Split input matrices to allow for certain operations */ |
66 |
> |
int |
67 |
|
split_input(ROPMAT *rop) |
68 |
|
{ |
69 |
|
if (rop->rmp == &rop->imx && !(rop->rmp = rmx_copy(&rop->imx))) { |
75 |
|
} |
76 |
|
|
77 |
|
/* Check/set transform based on a reference input file */ |
78 |
< |
static int |
78 |
> |
int |
79 |
|
checkreffile(ROPMAT *rop) |
80 |
|
{ |
81 |
|
static const char *curRF = NULL; |
138 |
|
} |
139 |
|
|
140 |
|
/* Compute conversion row from spectrum to one channel of RGB */ |
141 |
< |
static void |
141 |
> |
void |
142 |
|
rgbrow(ROPMAT *rop, int r, int p) |
143 |
|
{ |
144 |
|
const int nc = rop->imx.ncomp; |
155 |
|
} |
156 |
|
|
157 |
|
/* Compute conversion row from spectrum to one channel of XYZ */ |
158 |
< |
static void |
158 |
> |
void |
159 |
|
xyzrow(ROPMAT *rop, int r, int p) |
160 |
|
{ |
161 |
|
const int nc = rop->imx.ncomp; |
172 |
|
} |
173 |
|
|
174 |
|
/* Use the spectral sensitivity function to compute matrix coefficients */ |
175 |
< |
static void |
176 |
< |
sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, int ncs, const float wlpt[4])) |
175 |
> |
void |
176 |
> |
sensrow(ROPMAT *rop, int r, double (*sf)(const SCOLOR sc, int ncs, const float wlpt[4])) |
177 |
|
{ |
178 |
|
const int nc = rop->imx.ncomp; |
179 |
|
int i; |
187 |
|
} |
188 |
|
|
189 |
|
/* Check/set symbolic transform */ |
190 |
< |
static int |
190 |
> |
int |
191 |
|
checksymbolic(ROPMAT *rop) |
192 |
|
{ |
193 |
|
const int nc = rop->imx.ncomp; |
195 |
|
double cf = 1; |
196 |
|
int i, j; |
197 |
|
/* check suffix => reference file */ |
198 |
< |
if (strchr(rop->preop.csym, '.') > rop->preop.csym) |
198 |
> |
if (strchr(rop->preop.csym, '.') != NULL) |
199 |
|
return(checkreffile(rop)); |
200 |
|
|
201 |
|
if (nc < 3) { |
301 |
|
return(1); |
302 |
|
} |
303 |
|
|
304 |
< |
static int |
304 |
> |
/* Set up color transform for matrix */ |
305 |
> |
int |
306 |
|
get_component_xfm(ROPMAT *rop) |
307 |
|
{ |
308 |
|
int i, j; |
385 |
|
return(1); |
386 |
|
} |
387 |
|
|
388 |
< |
static int |
388 |
> |
/* Apply the given color transform and/or scaling operation */ |
389 |
> |
int |
390 |
|
apply_op(RMATRIX *dst, const RMATRIX *src, const RUNARYOP *ro) |
391 |
|
{ |
392 |
|
if (ro->clen > 0) { |
405 |
|
return(1); |
406 |
|
} |
407 |
|
|
408 |
< |
static int |
408 |
> |
/* Open the associated input file and load/check header */ |
409 |
> |
int |
410 |
|
open_input(ROPMAT *rop) |
411 |
|
{ |
412 |
|
int outtype; |
428 |
|
} |
429 |
|
|
430 |
|
/* Return nominal wavelength associated with input component (return nm) */ |
431 |
< |
static double |
431 |
> |
double |
432 |
|
l_wavelength(char *nam) |
433 |
|
{ |
434 |
|
double comp = argument(1); |
452 |
|
} |
453 |
|
|
454 |
|
/* Return ith input with optional channel selector */ |
455 |
< |
static double |
455 |
> |
double |
456 |
|
l_chanin(char *nam) |
457 |
|
{ |
458 |
|
double inp = argument(1); |
477 |
|
return(mop[mi].rmp->mtx[cur_col*in_ncomp + chan]); |
478 |
|
} |
479 |
|
|
480 |
< |
static int |
480 |
> |
/* Set up our operations and check consistency */ |
481 |
> |
int |
482 |
|
initialize(RMATRIX *imp) |
483 |
|
{ |
484 |
|
int i; |
491 |
|
restype = mop[i].rmp->dtype; |
492 |
|
if (!imp->dtype || (restype = rmx_newtype(restype, imp->dtype)) > 0) |
493 |
|
imp->dtype = restype; |
494 |
< |
else |
494 |
> |
else if (!nowarn) |
495 |
|
fprintf(stderr, "%s: warning - data type mismatch\n", |
496 |
|
mop[i].inspec); |
497 |
|
if (!i) { |
525 |
|
return(1); |
526 |
|
} |
527 |
|
|
528 |
< |
static void |
528 |
> |
/* Copy input header information to output header, indented */ |
529 |
> |
void |
530 |
|
output_headinfo(FILE *fp) |
531 |
|
{ |
532 |
|
int i; |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
< |
static int |
552 |
> |
/* Spawn the indicated number of children and return 1 in parent */ |
553 |
> |
int |
554 |
|
spawned_children(int np) |
555 |
|
{ |
556 |
|
int i, rv; |
557 |
|
|
558 |
|
#if defined(_WIN32) || defined(_WIN64) |
559 |
|
if (np > 1) { |
560 |
< |
fputs("Warning: only one process under Windows\n", stderr); |
560 |
> |
if (!nowarn) |
561 |
> |
fputs("Warning: only one process under Windows\n", stderr); |
562 |
|
np = 1; |
563 |
|
} else |
564 |
|
#endif |
565 |
< |
if ((in_nrows > 0) & (np > in_nrows)) |
566 |
< |
np = in_nrows; |
565 |
> |
if ((in_nrows > 0) & (np*4 > in_nrows)) |
566 |
> |
np = in_nrows/4; |
567 |
|
/* we'll be doing a row at a time */ |
568 |
|
for (i = 0; i < nmats; i++) { |
569 |
|
mop[i].imx.nrows = 1; |
575 |
|
goto memerror; |
576 |
|
} |
577 |
|
} |
578 |
< |
/* prep output row buffer */ |
579 |
< |
if (mcat || mop[nmats].preop.clen > 0) { |
578 |
> |
/* prep output row buffer(s) */ |
579 |
> |
if (mop[nmats].preop.clen > 0) { |
580 |
|
if (!split_input(&mop[nmats])) /* need separate buffer */ |
580 |
– |
return(0); |
581 |
– |
if (mop[nmats].preop.clen > 0) |
582 |
– |
mop[nmats].rmp->ncomp = mop[nmats].preop.clen / |
583 |
– |
mop[nmats].imx.ncomp; |
584 |
– |
mop[nmats].rmp->nrows = 1; |
585 |
– |
if (!mcat | !mcat_last && !rmx_prepare(mop[nmats].rmp)) |
581 |
|
goto memerror; |
582 |
+ |
mop[nmats].rmp->ncomp = mop[nmats].preop.clen / |
583 |
+ |
mop[nmats].imx.ncomp; |
584 |
|
} |
585 |
|
mop[nmats].imx.nrows = 1; |
586 |
|
if (!rmx_prepare(&mop[nmats].imx)) |
587 |
|
goto memerror; |
588 |
< |
if (np <= 1) { /* single process return point */ |
588 |
> |
if (mop[nmats].rmp != &mop[nmats].imx) { |
589 |
> |
mop[nmats].rmp->nrows = 1; |
590 |
> |
if (!rmx_prepare(mop[nmats].rmp)) |
591 |
> |
goto memerror; |
592 |
> |
} |
593 |
> |
if (np <= 1) { /* single process return */ |
594 |
|
#ifdef getc_unlocked |
595 |
|
for (i = 0; i < nmats; i++) |
596 |
|
flockfile(mop[i].infp); |
598 |
|
#endif |
599 |
|
return(0); |
600 |
|
} |
599 |
– |
gpid = setpgrp(); /* set group process ID */ |
600 |
– |
signal(SIGIO, on_sigio); |
601 |
|
fflush(stdout); /* flush header & spawn children */ |
602 |
< |
cproc = (SUBPROC *)malloc(sizeof(SUBPROC)*np); |
602 |
> |
nchildren = np + 1; /* extra child to sequence output */ |
603 |
> |
cproc = (SUBPROC *)malloc(sizeof(SUBPROC)*nchildren); |
604 |
|
if (!cproc) |
605 |
|
goto memerror; |
606 |
< |
nchildren = np; |
607 |
< |
for (i = 0; i < np; i++) { |
608 |
< |
cproc[i].flags = PF_FILT_OUT; |
609 |
< |
cproc[i].w = dup(1); |
610 |
< |
cproc[i].r = 0; |
611 |
< |
cproc[i].pid = -1; |
611 |
< |
rv = open_process(&cproc[i], NULL); |
612 |
< |
if (rv <= 0) break; |
613 |
< |
} |
614 |
< |
if (rv > 0) |
615 |
< |
return(1); /* parent return value */ |
606 |
> |
for (i = nchildren; i--; ) cproc[i] = sp_inactive; |
607 |
> |
cproc[nchildren-1].flags |= PF_FILT_OUT; |
608 |
> |
/* start each child from parent */ |
609 |
> |
for (i = 0; i < nchildren; i++) |
610 |
> |
if ((rv = open_process(&cproc[i], NULL)) <= 0) |
611 |
> |
break; /* child breaks here */ |
612 |
|
if (rv < 0) { |
613 |
< |
perror("fork"); |
613 |
> |
perror("fork"); /* WTH? */ |
614 |
> |
close_processes(cproc, i); |
615 |
|
exit(1); |
616 |
|
} |
617 |
< |
inchild = i; /* our child index */ |
618 |
< |
while (i-- > 0) /* don't share siblings' pipes */ |
617 |
> |
if (i != nchildren-1) { /* last child is sole reader */ |
618 |
> |
int j = i; |
619 |
> |
while (j-- > 0) { |
620 |
> |
close(cproc[j].r); |
621 |
> |
cproc[j].r = -1; |
622 |
> |
} |
623 |
> |
} |
624 |
> |
if (rv > 0) |
625 |
> |
return(1); /* parent return value */ |
626 |
> |
|
627 |
> |
inchild = i; /* else set our child index */ |
628 |
> |
while (i-- > 0) /* only parent writes siblings */ |
629 |
|
close(cproc[i].w); |
630 |
< |
fpurge(stdin); /* discard previous matrix input */ |
630 |
> |
|
631 |
> |
i = nmats; /* close matrix streams (carefully) */ |
632 |
> |
while (i-- > 0) { |
633 |
> |
if (mop[i].infp != stdin) { |
634 |
> |
close(fileno(mop[i].infp)); /* avoid lseek() */ |
635 |
> |
fclose(mop[i].infp); /* ! pclose() */ |
636 |
> |
} |
637 |
> |
mop[i].infp = NULL; |
638 |
> |
} |
639 |
> |
fpurge(stdin); /* discard previously buffered input */ |
640 |
> |
|
641 |
> |
if (inchild == nchildren-1) |
642 |
> |
return(-1); /* output process return value */ |
643 |
> |
|
644 |
> |
i = nmats; /* get matrix rows from parent */ |
645 |
> |
while (i-- > 0) { |
646 |
> |
mop[i].infp = stdin; |
647 |
> |
mop[i].imx.dtype = DTrmx_native; |
648 |
> |
mop[i].imx.pflags &= ~RMF_SWAPIN; |
649 |
> |
} |
650 |
|
#ifdef getc_unlocked |
651 |
|
flockfile(stdin); |
652 |
|
#endif |
653 |
< |
for (i = 0; i < nmats; i++) { |
654 |
< |
if (mop[i].infp != stdin) |
629 |
< |
fclose(mop[i].infp); /* ! pclose() */ |
630 |
< |
mop[i].infp = stdin; |
631 |
< |
mop[i].imx.dtype = DTdouble; |
632 |
< |
} |
633 |
< |
return(0); /* child return */ |
653 |
> |
mop[nmats].rmp->dtype = DTrmx_native; |
654 |
> |
return(0); /* worker child return value */ |
655 |
|
memerror: |
656 |
|
fputs("Out of memory in spawned_children()\n", stderr); |
657 |
|
exit(1); |
658 |
|
} |
659 |
|
|
660 |
< |
static int |
661 |
< |
parent_loop() |
660 |
> |
/* Run parental feeder loop */ |
661 |
> |
int |
662 |
> |
parent_loop(void) |
663 |
|
{ |
642 |
– |
FILE **outfp = (FILE **)malloc(nchildren*sizeof(FILE *)); |
664 |
|
int i; |
665 |
|
|
666 |
< |
if (!outfp) goto memerror; |
667 |
< |
for (i = 0; i < nchildren; i++) { |
668 |
< |
outfp[i] = fdopen(cproc[i].w, "w"); |
669 |
< |
if (!outfp[i]) goto memerror; |
649 |
< |
#ifdef getc_unlocked |
650 |
< |
flockfile(outfp[i]); |
651 |
< |
#endif |
666 |
> |
rmx_reset(&mop[nmats].imx); /* not touching output side */ |
667 |
> |
if (mop[nmats].rmp != &mop[nmats].imx) { |
668 |
> |
rmx_free(mop[nmats].rmp); |
669 |
> |
mop[nmats].rmp = &mop[nmats].imx; |
670 |
|
} |
671 |
|
#ifdef getc_unlocked |
672 |
< |
for (i = 0; i < nmats; i++) |
672 |
> |
for (i = 0; i < nmats; i++) /* we handle matrix inputs */ |
673 |
|
flockfile(mop[i].infp); |
674 |
|
#endif |
675 |
+ |
/* load & send rows to kids */ |
676 |
|
for (cur_row = 0; (in_nrows <= 0) | (cur_row < in_nrows); cur_row++) { |
677 |
< |
FILE *ofp = outfp[cur_row % nchildren]; |
677 |
> |
int wfd = cproc[cur_row % (nchildren-1)].w; |
678 |
|
for (i = 0; i < nmats; i++) |
679 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
680 |
|
if (cur_row > in_nrows) /* unknown #input rows? */ |
681 |
|
break; |
682 |
< |
fprintf(stderr, "%s: read error at row %d\n", |
682 |
> |
fprintf(stderr, "%s: load error at row %d\n", |
683 |
|
mop[i].inspec, cur_row); |
684 |
|
return(0); |
685 |
|
} |
686 |
|
if (i < nmats) |
687 |
|
break; |
688 |
|
for (i = 0; i < nmats; i++) |
689 |
< |
if (!rmx_write_data(mop[i].imx.mtx, mop[i].imx.ncomp, |
690 |
< |
mop[i].imx.ncols, DTdouble, ofp)) |
691 |
< |
return(0); |
692 |
< |
if (fflush(ofp) == EOF) |
693 |
< |
return(0); |
689 |
> |
if (writebuf(wfd, mop[i].imx.mtx, rmx_array_size(&mop[i].imx)) |
690 |
> |
!= rmx_array_size(&mop[i].imx)) { |
691 |
> |
fprintf(stderr, "%s: write error at row %d\n", |
692 |
> |
mop[i].inspec, cur_row); |
693 |
> |
return(0); |
694 |
> |
} |
695 |
|
} |
696 |
< |
for (i = 0; i < nchildren; i++) |
697 |
< |
fclose(outfp[i]); |
678 |
< |
free(outfp); |
679 |
< |
i = close_processes(cproc, nchildren); |
680 |
< |
free(cproc); cproc = NULL; |
696 |
> |
i = close_processes(cproc, nchildren); /* collect family */ |
697 |
> |
free(cproc); cproc = NULL; nchildren = 0; |
698 |
|
if (i < 0) { |
699 |
< |
fputs("Warning: missing child in parent_loop()\n", stderr); |
699 |
> |
if (!nowarn) |
700 |
> |
fputs("Warning: lost child process\n", stderr); |
701 |
|
return(1); |
702 |
|
} |
703 |
|
if (i > 0) { |
704 |
|
fprintf(stderr, "Child exited with status %d\n", i); |
705 |
|
return(0); |
706 |
|
} |
707 |
< |
return(1); |
690 |
< |
memerror: |
691 |
< |
fputs("Out of memory in parent_loop()\n", stderr); |
692 |
< |
exit(1); |
707 |
> |
return(1); /* return success! */ |
708 |
|
} |
709 |
|
|
710 |
< |
static int |
711 |
< |
combine_input() |
710 |
> |
/* Main operation loop, may be run in each child */ |
711 |
> |
int |
712 |
> |
combine_input(void) |
713 |
|
{ |
714 |
|
const int row0 = (inchild >= 0)*inchild; |
715 |
< |
const int rstep = nchildren + !nchildren; |
715 |
> |
const int rstep = nchildren ? nchildren-1 : 1; |
716 |
|
ROPMAT *res = &mop[nmats]; |
717 |
|
int set_r, set_c; |
718 |
|
RMATRIX *tmp = NULL; |
719 |
|
int co_set; |
720 |
|
int i; |
721 |
|
|
722 |
< |
if (mcat && mcat_last && |
723 |
< |
!(tmp = rmx_alloc(1, res->imx.ncols, res->rmp->ncomp))) |
724 |
< |
goto memerror; |
722 |
> |
if (mcat_last && !(tmp = rmx_alloc(1, res->imx.ncols, res->rmp->ncomp))) { |
723 |
> |
fputs("Out of buffer space in combine_input()\n", stderr); |
724 |
> |
return(0); |
725 |
> |
} |
726 |
|
/* figure out what the user set */ |
727 |
|
co_set = fundefined("co"); |
728 |
|
if (!co_set) |
744 |
|
if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) { |
745 |
|
if (cur_row > in_nrows) /* unknown #input rows? */ |
746 |
|
break; |
747 |
< |
fprintf(stderr, "%s: read error at row %d\n", |
747 |
> |
fprintf(stderr, "%s: load error at row %d\n", |
748 |
|
mop[i].inspec, cur_row); |
749 |
|
return(0); |
750 |
|
} |
789 |
|
return(0); |
790 |
|
} |
791 |
|
rmx_free(mres); mres = NULL; |
775 |
– |
if (inchild >= 0) /* children share stdout */ |
776 |
– |
while (nr_out < cur_row) |
777 |
– |
pause(); /* wait for our turn */ |
792 |
|
if (!rmx_write_data(res->rmp->mtx, res->rmp->ncomp, |
793 |
< |
res->rmp->ncols, res->rmp->dtype, stdout)) |
793 |
> |
res->rmp->ncols, res->rmp->dtype, stdout) || |
794 |
> |
(inchild >= 0 && fflush(stdout) == EOF)) { |
795 |
> |
fprintf(stderr, "Conversion/write error at row %d\n", |
796 |
> |
cur_row); |
797 |
|
return(0); |
781 |
– |
if (inchild >= 0) { /* flush and notify group */ |
782 |
– |
if (fflush(stdout) == EOF) |
783 |
– |
return(0); |
784 |
– |
killpg(gpid, SIGIO); /* increments everyone's nr_out */ |
798 |
|
} |
799 |
|
} |
800 |
|
return(inchild >= 0 || fflush(stdout) != EOF); |
788 |
– |
memerror: |
789 |
– |
fputs("Out of buffer space in combine_input()\n", stderr); |
790 |
– |
return(0); |
801 |
|
multerror: |
802 |
< |
fputs("Unexpected matrix multiply error in combine_input()\n", stderr); |
802 |
> |
fputs("Unexpected matrix multiply error\n", stderr); |
803 |
|
return(0); |
804 |
|
} |
805 |
|
|
806 |
< |
static int |
806 |
> |
/* Run output process loop when #processes > 1 */ |
807 |
> |
int |
808 |
> |
output_loop(void) |
809 |
> |
{ |
810 |
> |
const size_t row_size = rmx_array_size(mop[nmats].rmp); |
811 |
> |
int cur_child = 0; |
812 |
> |
int i = nmats; |
813 |
> |
|
814 |
> |
while (i-- > 0) { /* free input buffers */ |
815 |
> |
rmx_reset(&mop[i].imx); |
816 |
> |
if (mop[i].rmp != &mop[i].imx) { |
817 |
> |
rmx_free(mop[i].rmp); |
818 |
> |
mop[i].rmp = &mop[i].imx; |
819 |
> |
} |
820 |
> |
} |
821 |
> |
if (mop[nmats].rmp != &mop[nmats].imx) /* output is split? */ |
822 |
> |
rmx_reset(&mop[nmats].imx); |
823 |
> |
#ifdef getc_unlocked |
824 |
> |
flockfile(stdout); /* we own this, now */ |
825 |
> |
#endif |
826 |
> |
for ( ; ; ) { /* loop until no more */ |
827 |
> |
ssize_t rv; |
828 |
> |
rv = readbuf(cproc[cur_child].r, mop[nmats].rmp->mtx, row_size); |
829 |
> |
if (!rv) /* out of rows? */ |
830 |
> |
break; |
831 |
> |
if (rv != row_size) { |
832 |
> |
fputs("Read error\n", stderr); |
833 |
> |
return(0); |
834 |
> |
} /* do final conversion */ |
835 |
> |
if (!rmx_write_data(mop[nmats].rmp->mtx, mop[nmats].rmp->ncomp, |
836 |
> |
mop[nmats].rmp->ncols, mop[nmats].rmp->dtype, stdout)) { |
837 |
> |
fputs("Conversion/write error\n", stderr); |
838 |
> |
return(0); |
839 |
> |
} |
840 |
> |
cur_child++; |
841 |
> |
cur_child *= (cur_child < inchild); /* loop over workers */ |
842 |
> |
} |
843 |
> |
return(fflush(stdout) != EOF); |
844 |
> |
} |
845 |
> |
|
846 |
> |
/* Check/convert floating-point arguments following this */ |
847 |
> |
int |
848 |
|
get_factors(double da[], int n, char *av[]) |
849 |
|
{ |
850 |
|
int ac; |
854 |
|
return(ac); |
855 |
|
} |
856 |
|
|
857 |
< |
static void |
857 |
> |
/* Resize/reallocate the input array as requested */ |
858 |
> |
void |
859 |
|
resize_inparr(int n2alloc) |
860 |
|
{ |
861 |
|
int i; |
862 |
|
|
863 |
|
if (n2alloc == nall) |
864 |
|
return; |
865 |
< |
for (i = nall; i > n2alloc; i--) { |
865 |
> |
for (i = nall; i-- > n2alloc; ) { |
866 |
|
rmx_reset(&mop[i].imx); |
867 |
|
if (mop[i].rmp != &mop[i].imx) |
868 |
|
rmx_free(mop[i].rmp); |
888 |
|
int stdin_used = 0; |
889 |
|
int nproc = 1; |
890 |
|
const char *mcat_spec = NULL; |
891 |
+ |
int transpose_mcat = 0; |
892 |
|
int n2comp = 0; |
893 |
|
uby8 comp_ndx[128]; |
894 |
|
int i; |
958 |
|
} |
959 |
|
break; |
960 |
|
case 'C': |
961 |
+ |
mcat_last = 0; |
962 |
|
if (!n || isflt(argv[i+1])) |
963 |
|
goto userr; |
964 |
|
defCsym = mop[nmats].preop.csym = argv[++i]; |
965 |
|
mop[nmats].preop.clen = 0; |
912 |
– |
mcat_last = 0; |
966 |
|
break; |
967 |
|
case 'c': |
968 |
+ |
mcat_last = 0; |
969 |
|
if (n && !isflt(argv[i+1])) { |
970 |
|
mop[nmats].preop.csym = argv[++i]; |
971 |
|
mop[nmats].preop.clen = 0; |
981 |
|
goto userr; |
982 |
|
} |
983 |
|
mop[nmats].preop.csym = NULL; |
930 |
– |
mcat_last = 0; |
984 |
|
break; |
985 |
|
case 'm': |
986 |
|
if (!n) goto userr; |
987 |
+ |
mcat_last = 1; |
988 |
+ |
transpose_mcat = (argv[i][2] == 't'); |
989 |
|
if (argv[++i][0] == '-' && !argv[i][1]) { |
990 |
|
if (stdin_used++) goto stdin_error; |
991 |
|
mcat_spec = stdin_name; |
992 |
|
} else |
993 |
|
mcat_spec = argv[i]; |
939 |
– |
mcat_last = 1; |
994 |
|
break; |
995 |
|
default: |
996 |
|
fprintf(stderr, "%s: unknown option '%s'\n", |
1004 |
|
} |
1005 |
|
resize_inparr(nmats+1); /* extra matrix at end for result */ |
1006 |
|
mop[nmats].inspec = "trailing_ops"; |
1007 |
< |
/* load final concatenation matrix */ |
1008 |
< |
if (mcat_spec && !(mcat = rmx_load(mcat_spec, RMPnone))) { |
1009 |
< |
fprintf(stderr, "%s: error loading concatenation matrix: %s\n", |
1010 |
< |
argv[0], mcat_spec); |
1011 |
< |
return(1); |
1007 |
> |
|
1008 |
> |
if (mcat_spec) { /* load final concatenation matrix? */ |
1009 |
> |
mcat = rmx_load(mcat_spec); |
1010 |
> |
if (!mcat) { |
1011 |
> |
fprintf(stderr, "%s: error loading concatenation matrix: %s\n", |
1012 |
> |
argv[0], mcat_spec); |
1013 |
> |
return(1); |
1014 |
> |
} |
1015 |
> |
if (transpose_mcat && !rmx_transpose(mcat)) { |
1016 |
> |
fprintf(stderr, "%s: error transposing concatenation matrix: %s\n", |
1017 |
> |
argv[0], mcat_spec); |
1018 |
> |
return(1); |
1019 |
> |
} |
1020 |
|
} |
1021 |
|
/* get/check inputs, set constants */ |
1022 |
|
if (!initialize(&mop[nmats].imx)) |
1056 |
|
return(1); |
1057 |
|
mop[nmats].rmp->ncols = mcat->ncols; |
1058 |
|
} |
1059 |
+ |
#if DTrmx_native==DTfloat |
1060 |
+ |
if (outfmt == DTdouble) |
1061 |
+ |
fprintf(stderr, "%s: warning - writing float result as double\n", argv[0]); |
1062 |
+ |
#endif |
1063 |
|
newheader("RADIANCE", stdout); /* write output header */ |
1064 |
|
if (echoheader) |
1065 |
|
output_headinfo(stdout); |
1071 |
|
return(1); |
1072 |
|
} |
1073 |
|
doptimize(1); /* optimize definitions */ |
1074 |
< |
if (spawned_children(nproc)) /* running in parent process? */ |
1074 |
> |
i = spawned_children(nproc); /* create multiple processes if requested */ |
1075 |
> |
if (i > 0) /* running in parent process? */ |
1076 |
|
return(parent_loop() ? 0 : 1); |
1077 |
< |
/* process & write rows */ |
1077 |
> |
if (i < 0) /* running in output process? */ |
1078 |
> |
return(output_loop() ? 0 : 1); |
1079 |
> |
/* else we are a worker process */ |
1080 |
|
return(combine_input() ? 0 : 1); |
1081 |
|
stdin_error: |
1082 |
|
fprintf(stderr, "%s: %s used for more than one input\n", |