--- ray/src/util/rtcontrib.c 2005/05/26 15:14:42 1.3 +++ ray/src/util/rtcontrib.c 2005/06/02 18:51:46 1.11 @@ -1,13 +1,13 @@ #ifndef lint -static const char RCSid[] = "$Id: rtcontrib.c,v 1.3 2005/05/26 15:14:42 greg Exp $"; +static const char RCSid[] = "$Id: rtcontrib.c,v 1.11 2005/06/02 18:51:46 greg Exp $"; #endif /* * Gather rtrace output to compute contributions from particular sources */ +#include "standard.h" #include -#include "rtio.h" -#include "rterror.h" +#include #include "platform.h" #include "rtprocess.h" #include "selcall.h" @@ -64,23 +64,21 @@ struct rtproc { int bsiz; /* ray tree buffer length */ char *buf; /* ray tree buffer */ int nbr; /* number of bytes from rtrace */ -}; /* rtrace process */ +}; /* rtrace process buffer */ /* rtrace command and defaults */ -char *rtargv[256] = { "rtrace", "-dt", "0", "-dj", ".5", "-dr", "3", - "-ab", "1", "-ad", "128", }; +char *rtargv[256] = { "rtrace", "-dj", ".5", "-dr", "3", + "-ab", "1", "-ad", "128", "-lr", "-10", }; int rtargc = 11; /* overriding rtrace options */ -char *myrtopts[] = { "-o~~TmWdp", "-h-", - "-x", "1", "-y", "0", - "-as", "0", "-aa", "0", NULL }; +char *myrtopts[] = { "-o~~TmWdp", "-h-", "-x", "1", "-y", "0", + "-dt", "0", "-as", "0", "-aa", "0", NULL }; struct rtproc rt0; /* head of rtrace process list */ struct rtproc *rt_unproc = NULL; /* unprocessed ray trees */ char persistfn[] = "pfXXXXXX"; /* persist file name */ -char fmt[8]; /* rtrace i/o format */ int gargc; /* global argc */ char **gargv; /* global argv */ @@ -108,9 +106,9 @@ int nmods = 0; /* number of modifiers */ MODCONT *addmodifier(char *modn, char *outf, char *binv); -int done_rprocs(struct rtproc *rtp); void init(int np); -void tracecontribs(FILE *fp); +int done_rprocs(struct rtproc *rtp); +void trace_contribs(FILE *fp); struct rtproc *wait_rproc(void); struct rtproc *get_rproc(void); void queue_raytree(struct rtproc *rtp); @@ -125,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: @@ -160,12 +160,14 @@ main(int argc, char *argv[]) int nprocs = 1; char *curout = NULL; char *binval = NULL; + char fmt[8]; 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 */ @@ -203,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); @@ -270,7 +281,8 @@ main(int argc, char *argv[]) execv(rtpath, rtargv); perror(rtpath); /* execv() should not return */ exit(1); - } else if (nprocs > 1) { /* add persist file if parallel */ + } + if (nprocs > 1) { /* add persist file if parallel */ rtargv[rtargc++] = "-PP"; rtargv[rtargc++] = mktemp(persistfn); } @@ -284,7 +296,7 @@ main(int argc, char *argv[]) rtargv[rtargc] = NULL; /* start rtrace & compute contributions */ init(nprocs); - tracecontribs(stdin); + trace_contribs(stdin); quit(0); } @@ -336,7 +348,7 @@ quit(int status) exit(status); /* flushes all output streams */ } -/* start rtrace and initialize buffers */ +/* start rtrace processes and initialize */ void init(int np) { @@ -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 */ @@ -562,10 +584,21 @@ badspec: int getinp(char *buf, FILE *fp) { + char *cp; + int i; + switch (inpfmt) { case 'a': - if (fgets(buf, 128, fp) == NULL) - return 0; + cp = buf; /* make sure we get 6 floats */ + for (i = 0; i < 6; i++) { + if (fgetword(cp, buf+127-cp, fp) == NULL) + return 0; + if ((cp = fskip(cp)) == NULL || *cp) + return 0; + *cp++ = ' '; + } + getc(fp); /* get/put eol */ + *cp-- = '\0'; *cp = '\n'; return strlen(buf); case 'f': if (fread(buf, sizeof(float), 6, fp) < 6) @@ -832,7 +865,7 @@ get_rproc(void) /* trace ray contributions (main loop) */ void -tracecontribs(FILE *fin) +trace_contribs(FILE *fin) { char inpbuf[128]; int iblen;