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

Comparing ray/src/util/ranimate.c (file contents):
Revision 2.2 by greg, Thu Jan 18 11:25:11 1996 UTC vs.
Revision 2.8 by greg, Wed Jan 24 14:31:36 1996 UTC

# Line 57 | Line 57 | VARIABLE       vv[] = {                /* variable-value pairs */
57          {"ANIMATE",     2,      0,      NULL,   onevalue},
58          {"TRANSFER",    2,      0,      NULL,   onevalue},
59          {"ARCHIVE",     2,      0,      NULL,   onevalue},
60 <        {"INTERP",      3,      0,      NULL,   intvalue},
61 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
60 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
61 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
62          {"MBLUR",       2,      0,      NULL,   onevalue},
63          {"RTRACE",      2,      0,      NULL,   boolvalue},
64          {"DISKSPACE",   3,      0,      NULL,   fltvalue},
# Line 89 | Line 89 | char   rresopt[32];            /* rendering resolution options */
89   char    fresopt[32];            /* filter resolution options */
90   int     pfiltalways;            /* always use pfilt? */
91  
92 + char    arcargs[10240];         /* files to archive */
93 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
94 +
95   struct pslot {
96          int     pid;                    /* process ID (0 if empty) */
97          int     fout;                   /* output frame number */
# Line 99 | Line 102 | int    npslots;                /* number of process slots */
102   int     lastpid;                /* ID of last completed background process */
103   PSERVER *lastpserver;           /* last process server used */
104  
105 + #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
106 +
107   struct pslot    *findpslot();
108  
109   VIEW    *getview();
# Line 300 | Line 305 | setdefaults()                  /* set default values */
305                  vdef(START)++;
306          }
307          if (!vdef(END)) {
308 <                sprintf(buf, "%d", countviews());
308 >                sprintf(buf, "%d", countviews()+vint(START)-1);
309                  vval(END) = savqstr(buf);
310                  vdef(END)++;
311          }
312 +        if (vint(END) < vint(START)) {
313 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
314 +                                progname);
315 +                quit(1);
316 +        }
317          if (!vdef(BASENAME)) {
318                  sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
319                  vval(BASENAME) = savqstr(buf);
# Line 399 | Line 409 | sethosts()                     /* set up process servers */
409   }
410  
411  
412 < getradfile(rfname)              /* run rad and get needed variables */
413 < char    *rfname;
412 > getradfile(rfargs)              /* run rad and get needed variables */
413 > char    *rfargs;
414   {
415          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
416          char    combuf[256];
# Line 410 | Line 420 | char   *rfname;
420          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
421          sprintf(combuf,
422          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
423 <                        rfname, rendopt+2);
423 >                        rfargs, rendopt+2);
424          cp = combuf;
425          while (*cp) cp++;               /* match unset variables */
426          for (i = 0; mvar[i] >= 0; i++)
# Line 422 | Line 432 | char   *rfname;
432          sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
433          cp += 11;                       /* point to file name */
434          if (system(combuf)) {
435 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
436 <                                progname, rfname);
435 >                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
436 >                                progname, combuf);
437                  quit(1);
438          }
439          loadvars(cp);                   /* load variables and remove file */
# Line 480 | Line 490 | animate()                      /* run animation */
490                                  progname);
491                  quit(1);
492          }
493 +                                        /* initialize archive argument list */
494 +        i = 16;
495 +        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
496 +                i = strlen(vval(ARCHIVE));
497 +        arcnext = arcfirst = arcargs + i;
498                                          /* initialize status file */
499          if (astat.rnext == 0)
500                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 574 | Line 589 | filterframes()                         /* catch up with filtering */
589                  dofilt(i, vp, getexp(i), 0);            /* filter frame */
590          }
591          bwait(0);                       /* wait for filter processes */
592 <        archive(astat.fnext, i-1);      /* archive originals */
592 >        archive();                      /* archive originals */
593          astat.fnext = i;                /* update status */
594          putastat();
595   }
# Line 636 | Line 651 | int    first, last;
651   char    *vfn;
652   {
653          char    combuf[2048];
654 +        char    *inspoint;
655          register int    i;
656  
657          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 646 | Line 662 | char   *vfn;
662                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
663                          }
664                                          /* create command */
665 <        sprintf(combuf, "rpict%s -w0 ", rendopt);
665 >        sprintf(combuf, "rpict%s -w0", rendopt);
666          if (vint(INTERP) || atoi(vval(MBLUR)))
667 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
668 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
669 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
667 >                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
668 >        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
669 >                        vval(BASENAME), rresopt, first);
670 >        inspoint = combuf + strlen(combuf);
671 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
672                                          /* run in parallel */
673 <        if (pruncom(combuf, (last-first+1)/(vint(INTERP)+1))) {
673 >        i = (last-first+1)/(vint(INTERP)+1);
674 >        if (i < 1) i = 1;
675 >        if (pruncom(combuf, inspoint, i)) {
676                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
677                                  progname, first, last);
678                  quit(1);
# Line 730 | Line 750 | int    frame;
750   }
751  
752  
753 < archive(first, last)                    /* archive and remove renderings */
734 < int     first, last;
753 > archive()                       /* archive and remove renderings */
754   {
755   #define RMCOML  (sizeof(rmcom)-1)
756          static char     rmcom[] = "rm -f";
738        int     offset = RMCOML;
739        char    combuf[10240];
740        struct stat     stb;
741        register char   *cp;
757          register int    i;
758  
759 <        if (noaction)
760 <                return;
746 <        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > offset)
747 <                offset = strlen(vval(ARCHIVE));
748 <        cp = combuf + offset;
749 <        *cp++ = ' ';                            /* make argument list */
750 <        for (i = first; i <= last; i++) {
751 <                sprintf(cp, vval(BASENAME), i);
752 <                strcat(cp, ".unf");
753 <                if (stat(cp, &stb) == 0 && stb.st_size > 0) {   /* non-zero? */
754 <                        while (*cp) cp++;
755 <                        *cp++ = ' ';
756 <                        sprintf(cp, vval(BASENAME), i);
757 <                        strcat(cp, ".zbf");
758 <                        if (access(cp, F_OK) == 0) {            /* exists? */
759 <                                while (*cp) cp++;
760 <                                *cp++ = ' ';
761 <                        }
762 <                }
763 <        }
764 <        *--cp = '\0';
765 <        if (cp <= combuf + offset)              /* no files? */
766 <                return;
759 >        if (arcnext == arcfirst)
760 >                return;                         /* nothing to do */
761          if (vdef(ARCHIVE)) {                    /* run archive command */
762                  i = strlen(vval(ARCHIVE));
763 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
764 <                if (runcom(combuf+offset-i)) {
765 <                        fprintf(stderr,
766 <                "%s: error running archive command on frames %d through %d\n",
773 <                                        progname, first, last);
763 >                strncpy(arcfirst-i, vval(ARCHIVE), i);
764 >                if (runcom(arcfirst-i)) {
765 >                        fprintf(stderr, "%s: error running archive command\n",
766 >                                        progname);
767                          quit(1);
768                  }
769          }
770                                                  /* run remove command */
771 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
772 <        runcom(combuf+offset-RMCOML);
771 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
772 >        runcom(arcfirst-RMCOML);
773 >        arcnext = arcfirst;                     /* reset argument list */
774   #undef RMCOML
775   }
776  
# Line 789 | Line 783 | char   *ep;
783   int     rvr;
784   {
785          extern int      frecover();
786 +        static int      iter = 0;
787          char    fnbefore[128], fnafter[128];
788 <        char    combuf[1024], fname[128];
789 <        int     usepinterp, usepfilt;
788 >        char    combuf[1024], fname0[128], fname1[128];
789 >        int     usepinterp, usepfilt, nora_rgbe;
790          int     frseq[2];
791                                                  /* check what is needed */
792          usepinterp = atoi(vval(MBLUR));
793          usepfilt = pfiltalways | ep==NULL;
794 +        if (ep != NULL && !strcmp(ep, "1"))
795 +                ep = "+0";
796 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
797 +                        *ep != '+' || *ep != '-' || !isint(ep);
798                                                  /* compute rendered views */
799          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
800          frseq[1] = frseq[0] + vint(INTERP) + 1;
# Line 804 | Line 803 | int    rvr;
803          if (frseq[1] == frame) {                        /* pfilt only */
804                  frseq[0] = frseq[1];
805                  usepinterp = 0;                 /* update what's needed */
806 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
807 <        } else if (frseq[0] == frame) {         /* no interpolation */
808 <                                                /* update what's needed */
809 <                if (!usepinterp)
810 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
806 >                usepfilt |= nora_rgbe;
807 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
808 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
809 >                        *arcnext++ = ' ';
810 >                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
811 >                        while (*arcnext) arcnext++;
812 >                        strcpy(arcnext, ".unf");
813 >                        arcnext += 4;
814 >                        if (usepinterp || vint(INTERP)) {       /* and z-buf */
815 >                                *arcnext++ = ' ';
816 >                                sprintf(arcnext, vval(BASENAME),
817 >                                                frame-vint(INTERP)-1);
818 >                                while (*arcnext) arcnext++;
819 >                                strcpy(arcnext, ".zbf");
820 >                                arcnext += 4;
821 >                        }
822 >                }
823 >                if (!usepinterp)                /* update what's needed */
824 >                        usepfilt |= nora_rgbe;
825          } else                                  /* interpolation needed */
826                  usepinterp++;
827          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 823 | Line 836 | int    rvr;
836                          return(1);
837                  if (atoi(vval(MBLUR))) {
838                          FILE    *fp;            /* motion blurring */
839 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
840 <                        if ((fp = fopen(fname, "w")) == NULL) {
841 <                                perror(fname); quit(1);
839 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
840 >                                        'a'+(iter%26));
841 >                        if ((fp = fopen(fname0, "w")) == NULL) {
842 >                                perror(fname0); quit(1);
843                          }
844                          fputs(VIEWSTR, fp);
845                          fprintview(vp, fp);
# Line 836 | Line 850 | int    rvr;
850                                                  progname, frame+1);
851                                  quit(1);
852                          }
853 <                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
854 <                        if ((fp = fopen(fname, "w")) == NULL) {
855 <                                perror(fname); quit(1);
853 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
854 >                                        'a'+(iter%26));
855 >                        if ((fp = fopen(fname1, "w")) == NULL) {
856 >                                perror(fname1); quit(1);
857                          }
858                          fputs(VIEWSTR, fp);
859                          fprintview(vp, fp);
860                          putc('\n', fp); fclose(fp);
861                          sprintf(combuf,
862 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
862 >                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
863                          *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
864 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
865 <                                        vval(DIRECTORY), vval(DIRECTORY),
866 <                                        vval(DIRECTORY), vval(DIRECTORY));
864 >                                        atoi(vval(MBLUR)),
865 >                                        fname0, fname1, fname0, fname1);
866 >                        iter++;
867                  } else                          /* no blurring */
868                          strcpy(combuf, "pinterp");
869                  strcat(combuf, viewopt(vp));
# Line 895 | Line 910 | int    rvr;
910          } else {                                /* else just check it */
911                  if (rvr == 2)
912                          return(1);
913 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
913 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
914          }
915                                                  /* output file name */
916 <        sprintf(fname, vval(BASENAME), frame);
917 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
916 >        sprintf(fname0, vval(BASENAME), frame);
917 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
918          if (rvr)                                /* in recovery */
919                  return(runcom(combuf));
920          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 931 | Line 946 | int    n;
946                          quit(1);
947                  }
948          } else if (n < viewnum) {       /* rewind file */
949 +                if (viewnum == 1 && feof(viewfp))
950 +                        return(&curview);               /* just one view */
951                  if (fseek(viewfp, 0L, 0) == EOF) {
952                          perror(vval(VIEWFILE));
953                          quit(1);
# Line 940 | Line 957 | int    n;
957          }
958          while (n > viewnum) {           /* scan to desired view */
959                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
960 <                        return(NULL);
960 >                        return(viewnum==1 ? &curview : NULL);
961                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
962                          viewnum++;
963          }
# Line 1052 | Line 1069 | int    status;
1069          register PROC   *pp;
1070  
1071          pp = ps->proc + pn;
1055        if (!silent) {                  /* echo command */
1056                if (ps->hostname[0])
1057                        printf("On %s:", ps->hostname);
1058                printf("\t%s\n", pp->com);
1059                fflush(stdout);
1060        }
1072          if (pp->elen) {                 /* pass errors */
1073 +                if (ps->hostname[0])
1074 +                        fprintf(stderr, "%s: ", ps->hostname);
1075 +                fprintf(stderr, "Error output from: %s\n", pp->com);
1076                  fputs(pp->errs, stderr);
1077                  fflush(stderr);
1078                  if (ps->hostname[0])
# Line 1097 | Line 1111 | int    (*rf)();
1111  
1112          if (noaction) {
1113                  if (!silent)
1114 <                        printf("\t%s\n", com);  /* just echo it */
1114 >                        printf("\t%s\n", com);  /* echo command */
1115                  return(0);
1116          }
1117                                          /* else start it when we can */
1118          while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1119                  bwait(1);
1120 +        if (!silent) {                          /* echo command */
1121 +                PSERVER *ps;
1122 +                int     psn = pid;
1123 +                ps = findjob(&psn);
1124 +                printf("\t%s\n", com);
1125 +                printf("\tProcess started on %s\n", phostname(ps));
1126 +                fflush(stdout);
1127 +        }
1128          psl = findpslot(pid);           /* record info. in appropriate slot */
1129          psl->pid = pid;
1130          psl->fout = fout;
# Line 1138 | Line 1160 | int    ncoms;
1160  
1161  
1162   int
1163 < pruncom(com, maxcopies)         /* run a command in parallel over network */
1164 < char    *com;
1163 > pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1164 > char    *com, *ppins;
1165   int     maxcopies;
1166   {
1167          int     retstatus = 0;
1168 +        int     hostcopies;
1169 +        char    com1buf[10240], *com1, *endcom1;
1170          int     status;
1171          register PSERVER        *ps;
1172  
1173 <        if (noaction) {
1174 <                if (!silent)
1175 <                        printf("\t%s\n", com);  /* just echo */
1173 >        if (!silent)
1174 >                printf("\t%s\n", com);  /* echo command */
1175 >        if (noaction)
1176                  return(0);
1177 <        }
1177 >        fflush(stdout);
1178                                          /* start jobs on each server */
1179 <        for (ps = pslist; ps != NULL; ps = ps->next)
1179 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1180 >                hostcopies = 0;
1181 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1182 >                        strcpy(com1=com1buf, com);      /* build -PP command */
1183 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1184 >                                        vval(DIRECTORY), phostname(ps));
1185 >                        strcat(com1, ppins);
1186 >                        endcom1 = com1 + strlen(com1);
1187 >                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1188 >                                        vval(DIRECTORY), phostname(ps));
1189 >                } else {
1190 >                        com1 = com;
1191 >                        endcom1 = NULL;
1192 >                }
1193                  while (maxcopies > 0 &&
1194 <                                startjob(ps, savestr(com), donecom) != -1) {
1194 >                                startjob(ps, savestr(com1), donecom) != -1) {
1195                          sleep(10);
1196 +                        hostcopies++;
1197                          maxcopies--;
1198 +                        if (endcom1 != NULL)
1199 +                                *endcom1 = '\0';
1200                  }
1201 +                if (!silent && hostcopies) {
1202 +                        if (hostcopies > 1)
1203 +                                printf("\t%d duplicate processes", hostcopies);
1204 +                        else
1205 +                                printf("\tProcess");
1206 +                        printf(" started on %s\n", phostname(ps));
1207 +                        fflush(stdout);
1208 +                }
1209 +        }
1210                                          /* wait for jobs to finish */
1211          while ((status = wait4job(NULL, -1)) != -1)
1212                  if (status)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines