ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rtcontrib.c
(Generate patch)

Comparing ray/src/util/rtcontrib.c (file contents):
Revision 1.3 by greg, Thu May 26 15:14:42 2005 UTC vs.
Revision 1.11 by greg, Thu Jun 2 18:51:46 2005 UTC

# Line 5 | Line 5 | static const char RCSid[] = "$Id$";
5   * Gather rtrace output to compute contributions from particular sources
6   */
7  
8 + #include  "standard.h"
9   #include  <ctype.h>
10 < #include  "rtio.h"
10 < #include  "rterror.h"
10 > #include  <signal.h>
11   #include  "platform.h"
12   #include  "rtprocess.h"
13   #include  "selcall.h"
# Line 64 | Line 64 | struct rtproc {
64          int             bsiz;           /* ray tree buffer length */
65          char            *buf;           /* ray tree buffer */
66          int             nbr;            /* number of bytes from rtrace */
67 < };                              /* rtrace process */
67 > };                              /* rtrace process buffer */
68  
69                                          /* rtrace command and defaults */
70 < char            *rtargv[256] = { "rtrace", "-dt", "0", "-dj", ".5", "-dr", "3",
71 <                                "-ab", "1", "-ad", "128", };
70 > char            *rtargv[256] = { "rtrace", "-dj", ".5", "-dr", "3",
71 >                                "-ab", "1", "-ad", "128", "-lr", "-10", };
72   int  rtargc = 11;
73                                          /* overriding rtrace options */
74 < char            *myrtopts[] = { "-o~~TmWdp", "-h-",
75 <                                "-x", "1", "-y", "0",
76 <                                "-as", "0", "-aa", "0", NULL };
74 > char            *myrtopts[] = { "-o~~TmWdp", "-h-", "-x", "1", "-y", "0",
75 >                                "-dt", "0", "-as", "0", "-aa", "0", NULL };
76  
77   struct rtproc   rt0;                    /* head of rtrace process list */
78  
79   struct rtproc   *rt_unproc = NULL;      /* unprocessed ray trees */
80  
81   char    persistfn[] = "pfXXXXXX";       /* persist file name */
83 char    fmt[8];                         /* rtrace i/o format */
82  
83   int             gargc;                  /* global argc */
84   char            **gargv;                /* global argv */
# Line 108 | Line 106 | int            nmods = 0;              /* number of modifiers */
106  
107   MODCONT *addmodifier(char *modn, char *outf, char *binv);
108  
111 int done_rprocs(struct rtproc *rtp);
109   void init(int np);
110 < void tracecontribs(FILE *fp);
110 > int done_rprocs(struct rtproc *rtp);
111 > void trace_contribs(FILE *fp);
112   struct rtproc *wait_rproc(void);
113   struct rtproc *get_rproc(void);
114   void queue_raytree(struct rtproc *rtp);
# Line 125 | Line 123 | static void
123   setformat(const char *fmt)
124   {
125          switch (fmt[0]) {
128        case 'a':
126          case 'f':
127          case 'd':
128 +                SET_FILE_BINARY(stdin);
129 +                /* fall through */
130 +        case 'a':
131                  inpfmt = fmt[0];
132                  break;
133          default:
# Line 160 | Line 160 | main(int argc, char *argv[])
160          int     nprocs = 1;
161          char    *curout = NULL;
162          char    *binval = NULL;
163 +        char    fmt[8];
164          int     i, j;
165                                  /* global program name */
166          gargv = argv;
167 <                                /* set up calcomp mode */
167 >                                /* initialize calcomp routines */
168          esupport |= E_VARIABLE|E_FUNCTION|E_INCHAN|E_RCONST|E_REDEFW;
169          esupport &= ~(E_OUTCHAN);
170 +        varset("PI", ':', PI);
171                                  /* get our options */
172          for (i = 1; i < argc-1; i++) {
173                                                  /* expand arguments */
# Line 203 | Line 205 | main(int argc, char *argv[])
205                                  break;
206                          case 'f':               /* file or i/o format */
207                                  if (!argv[i][2]) {
208 +                                        char    *fpath;
209                                          if (i >= argc-1) break;
210 <                                        fcompile(argv[++i]);
210 >                                        fpath = getpath(argv[++i],
211 >                                                        getrlibpath(), R_OK);
212 >                                        if (fpath == NULL) {
213 >                                                sprintf(errmsg,
214 >                                                        "cannot find file '%s'",
215 >                                                                argv[i]);
216 >                                                error(USER, errmsg);
217 >                                        }
218 >                                        fcompile(fpath);
219                                          continue;
220                                  }
221                                  setformat(argv[i]+2);
# Line 270 | Line 281 | main(int argc, char *argv[])
281                  execv(rtpath, rtargv);
282                  perror(rtpath); /* execv() should not return */
283                  exit(1);
284 <        } else if (nprocs > 1) {        /* add persist file if parallel */
284 >        }
285 >        if (nprocs > 1) {       /* add persist file if parallel */
286                  rtargv[rtargc++] = "-PP";
287                  rtargv[rtargc++] = mktemp(persistfn);
288          }
# Line 284 | Line 296 | main(int argc, char *argv[])
296          rtargv[rtargc] = NULL;
297                                  /* start rtrace & compute contributions */
298          init(nprocs);
299 <        tracecontribs(stdin);
299 >        trace_contribs(stdin);
300          quit(0);
301   }
302  
# Line 336 | Line 348 | quit(int status)
348          exit(status);                   /* flushes all output streams */
349   }
350  
351 < /* start rtrace and initialize buffers */
351 > /* start rtrace processes and initialize */
352   void
353   init(int np)
354   {
# Line 489 | Line 501 | getofile(const char *ospec, const char *mname, int bn)
501          LUENT           *lep;
502          
503          if (ospec == NULL) {                    /* use stdout? */
504 <                if (!using_stdout && header)
505 <                        printheader(stdout);
504 >                if (!using_stdout) {
505 >                        if (outfmt != 'a')
506 >                                SET_FILE_BINARY(stdout);
507 >                        if (header)
508 >                                printheader(stdout);
509 >                }
510                  using_stdout = 1;
511                  return stdout;
512          }
# Line 532 | Line 548 | getofile(const char *ospec, const char *mname, int bn)
548          if (lep->key == NULL)                   /* new entry */
549                  lep->key = strcpy((char *)malloc(strlen(ofname)+1), ofname);
550          if (lep->data == NULL) {                /* open output file */
551 <                FILE            *fp = fopen(ofname, "w");
551 >                FILE            *fp;
552                  int             i;
553 +                if (ofname[0] == '!')           /* output to command */
554 +                        fp = popen(ofname+1, "w");
555 +                else
556 +                        fp = fopen(ofname, "w");
557                  if (fp == NULL) {
558                          sprintf(errmsg, "cannot open '%s' for writing", ofname);
559                          error(SYSTEM, errmsg);
560                  }
561 +                if (outfmt != 'a')
562 +                        SET_FILE_BINARY(fp);
563                  if (header)
564                          printheader(fp);
565                                                  /* play catch-up */
# Line 562 | Line 584 | badspec:
584   int
585   getinp(char *buf, FILE *fp)
586   {
587 +        char    *cp;
588 +        int     i;
589 +
590          switch (inpfmt) {
591          case 'a':
592 <                if (fgets(buf, 128, fp) == NULL)
593 <                        return 0;
592 >                cp = buf;               /* make sure we get 6 floats */
593 >                for (i = 0; i < 6; i++) {
594 >                        if (fgetword(cp, buf+127-cp, fp) == NULL)
595 >                                return 0;
596 >                        if ((cp = fskip(cp)) == NULL || *cp)
597 >                                return 0;
598 >                        *cp++ = ' ';
599 >                }
600 >                getc(fp);               /* get/put eol */
601 >                *cp-- = '\0'; *cp = '\n';
602                  return strlen(buf);
603          case 'f':
604                  if (fread(buf, sizeof(float), 6, fp) < 6)
# Line 832 | Line 865 | get_rproc(void)
865  
866   /* trace ray contributions (main loop) */
867   void
868 < tracecontribs(FILE *fin)
868 > trace_contribs(FILE *fin)
869   {
870          char            inpbuf[128];
871          int             iblen;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines