--- ray/src/util/rtcontrib.c 2005/05/31 03:48:59 1.7 +++ ray/src/util/rtcontrib.c 2005/06/05 19:52:01 1.13 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.7 2005/05/31 03:48:59 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.13 2005/06/05 19:52:01 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources @@ -123,9 +123,11 @@ static void setformat(const char *fmt) { switch (fmt[0]) { - case 'a': case 'f': case 'd': + SET_FILE_BINARY(stdin); + /* fall through */ + case 'a': inpfmt = fmt[0]; break; default: @@ -162,9 +164,10 @@ main(int argc, char *argv[]) int i, j; /* global program name */ gargv = argv; - /* set up calcomp mode */ + /* initialize calcomp routines */ esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_RCONST|E_REDEFW; esupport &= ~(E_OUTCHAN); + varset("PI", ':', PI); /* get our options */ for (i = 1; i < argc-1; i++) { /* expand arguments */ @@ -202,8 +205,17 @@ main(int argc, char *argv[]) break; case 'f': /* file or i/o format */ if (!argv[i][2]) { + char *fpath; if (i >= argc-1) break; - fcompile(argv[++i]); + fpath = getpath(argv[++i], + getrlibpath(), R_OK); + if (fpath == NULL) { + sprintf(errmsg, + "cannot find file '%s'", + argv[i]); + error(USER, errmsg); + } + fcompile(fpath); continue; } setformat(argv[i]+2); @@ -489,8 +501,12 @@ getofile(const char *ospec, const char *mname, int bn) LUENT *lep; if (ospec == NULL) { /* use stdout? */ - if (!using_stdout && header) - printheader(stdout); + if (!using_stdout) { + if (outfmt != 'a') + SET_FILE_BINARY(stdout); + if (header) + printheader(stdout); + } using_stdout = 1; return stdout; } @@ -532,12 +548,18 @@ getofile(const char *ospec, const char *mname, int bn) if (lep->key == NULL) /* new entry */ lep->key = strcpy((char *)malloc(strlen(ofname)+1), ofname); if (lep->data == NULL) { /* open output file */ - FILE *fp = fopen(ofname, "w"); + FILE *fp; int i; + if (ofname[0] == '!') /* output to command */ + fp = popen(ofname+1, "w"); + else + fp = fopen(ofname, "w"); if (fp == NULL) { sprintf(errmsg, "cannot open '%s' for writing", ofname); error(SYSTEM, errmsg); } + if (outfmt != 'a') + SET_FILE_BINARY(fp); if (header) printheader(fp); /* play catch-up */ @@ -684,9 +706,17 @@ done_contrib(void) MODCONT *mp; /* output modifiers in order */ for (i = 0; i < nmods; i++) { + FILE *fp; mp = (MODCONT *)lu_find(&modconttab,modname[i])->data; - for (j = 0; j < mp->nbins; j++) - putcontrib(mp->cbin[j], + fp = getofile(mp->outspec, mp->modname, 0); + putcontrib(mp->cbin[0], fp); + if (mp->nbins > 3 && /* minor optimization */ + fp == getofile(mp->outspec, mp->modname, 1)) + for (j = 1; j < mp->nbins; j++) + putcontrib(mp->cbin[j], fp); + else + for (j = 1; j < mp->nbins; j++) + putcontrib(mp->cbin[j], getofile(mp->outspec, mp->modname, j)); /* clear for next ray tree */ memset(mp->cbin, 0, sizeof(DCOLOR)*mp->nbins);