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.10 by greg, Tue Feb 20 16:13:53 1996 UTC

# Line 15 | Line 15 | static char SCCSid[] = "$SunId$ LBL";
15   #include "view.h"
16   #include "vars.h"
17   #include "netproc.h"
18 +                                /* default remote shell */
19 + #ifdef _AUX_SOURCE
20 + #define REMSH           "remsh"
21 + #else
22 + #define REMSH           "rsh"
23 + #endif
24                                  /* input variables */
25   #define HOST            0               /* rendering host machine */
26   #define RENDER          1               /* rendering options */
# Line 38 | Line 44 | static char SCCSid[] = "$SunId$ LBL";
44   #define DISKSPACE       19              /* how much disk space to use */
45   #define RESOLUTION      20              /* desired final resolution */
46   #define EXPOSURE        21              /* how to compute exposure */
47 + #define RSH             22              /* remote shell script or program */
48  
49 < int     NVARS = 22;             /* total number of variables */
49 > int     NVARS = 23;             /* total number of variables */
50  
51   VARIABLE        vv[] = {                /* variable-value pairs */
52          {"host",        4,      0,      NULL,   NULL},
# Line 57 | Line 64 | VARIABLE       vv[] = {                /* variable-value pairs */
64          {"ANIMATE",     2,      0,      NULL,   onevalue},
65          {"TRANSFER",    2,      0,      NULL,   onevalue},
66          {"ARCHIVE",     2,      0,      NULL,   onevalue},
67 <        {"INTERP",      3,      0,      NULL,   intvalue},
68 <        {"OVERSAMP",    2,      0,      NULL,   fltvalue},
67 >        {"INTERPOLATE", 3,      0,      NULL,   intvalue},
68 >        {"OVERSAMPLE",  2,      0,      NULL,   fltvalue},
69          {"MBLUR",       2,      0,      NULL,   onevalue},
70          {"RTRACE",      2,      0,      NULL,   boolvalue},
71          {"DISKSPACE",   3,      0,      NULL,   fltvalue},
72          {"RESOLUTION",  3,      0,      NULL,   onevalue},
73          {"EXPOSURE",    3,      0,      NULL,   onevalue},
74 +        {"RSH",         3,      0,      NULL,   onevalue},
75   };
76  
77   #define SFNAME  "STATUS"                /* status file name */
# Line 84 | Line 92 | int    nowarn = 0;             /* turn warnings off? */
92   int     silent = 0;             /* silent mode? */
93   int     noaction = 0;           /* take no action? */
94  
95 + char    *remsh;                 /* remote shell program/script */
96   char    rendopt[2048] = "";     /* rendering options */
97   char    rresopt[32];            /* rendering resolution options */
98   char    fresopt[32];            /* filter resolution options */
99   int     pfiltalways;            /* always use pfilt? */
100  
101 + char    arcargs[10240];         /* files to archive */
102 + char    *arcfirst, *arcnext;    /* pointers to first and next argument */
103 +
104   struct pslot {
105          int     pid;                    /* process ID (0 if empty) */
106          int     fout;                   /* output frame number */
# Line 99 | Line 111 | int    npslots;                /* number of process slots */
111   int     lastpid;                /* ID of last completed background process */
112   PSERVER *lastpserver;           /* last process server used */
113  
114 + #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
115 +
116   struct pslot    *findpslot();
117  
118   VIEW    *getview();
# Line 199 | Line 213 | getastat()                     /* check/set animation status */
213                  goto fmterr;
214          fclose(fp);
215          if (astat.pid != 0) {                   /* thinks it's still running */
216 <                gethostname(buf, sizeof(buf));
203 <                if (strcmp(buf, astat.host)) {
216 >                if (strcmp(myhostname(), astat.host)) {
217                          fprintf(stderr,
218                          "%s: process %d may still be running on host %s\n",
219                                          progname, astat.pid, astat.host);
# Line 219 | Line 232 | getastat()                     /* check/set animation status */
232                  return(-1);
233          }
234   setours:                                        /* set our values */
235 <        gethostname(astat.host, sizeof(astat.host));
235 >        strcpy(astat.host, myhostname());
236          astat.pid = getpid();
237          strcpy(astat.cfname, cfname);
238          return(0);
# Line 277 | Line 290 | checkdir()                     /* make sure we have our directory */
290  
291   setdefaults()                   /* set default values */
292   {
293 +        extern char     *atos();
294          char    buf[256];
295  
296          if (vdef(ANIMATE)) {
# Line 300 | Line 314 | setdefaults()                  /* set default values */
314                  vdef(START)++;
315          }
316          if (!vdef(END)) {
317 <                sprintf(buf, "%d", countviews());
317 >                sprintf(buf, "%d", countviews()+vint(START)-1);
318                  vval(END) = savqstr(buf);
319                  vdef(END)++;
320          }
321 +        if (vint(END) < vint(START)) {
322 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
323 +                                progname);
324 +                quit(1);
325 +        }
326          if (!vdef(BASENAME)) {
327                  sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
328                  vval(BASENAME) = savqstr(buf);
# Line 337 | Line 356 | setdefaults()                  /* set default values */
356                  vval(DISKSPACE) = "100";
357                  vdef(DISKSPACE)++;
358          }
359 +        if (!vdef(RSH)) {
360 +                vval(RSH) = REMSH;
361 +                vdef(RSH)++;
362 +        }
363 +                                /* locate remote shell program */
364 +        atos(buf, sizeof(buf), vval(RSH));
365 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
366 +                remsh = savqstr(remsh);
367 +        else
368 +                remsh = vval(RSH);      /* will generate error if used */
369 +
370                                  /* append rendering options */
371          if (vdef(RENDER))
372                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
# Line 399 | Line 429 | sethosts()                     /* set up process servers */
429   }
430  
431  
432 < getradfile(rfname)              /* run rad and get needed variables */
433 < char    *rfname;
432 > getradfile(rfargs)              /* run rad and get needed variables */
433 > char    *rfargs;
434   {
435          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
436          char    combuf[256];
# Line 410 | Line 440 | char   *rfname;
440          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
441          sprintf(combuf,
442          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
443 <                        rfname, rendopt+2);
443 >                        rfargs, rendopt+2);
444          cp = combuf;
445          while (*cp) cp++;               /* match unset variables */
446          for (i = 0; mvar[i] >= 0; i++)
# Line 422 | Line 452 | char   *rfname;
452          sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
453          cp += 11;                       /* point to file name */
454          if (system(combuf)) {
455 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
456 <                                progname, rfname);
455 >                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
456 >                                progname, combuf);
457                  quit(1);
458          }
459          loadvars(cp);                   /* load variables and remove file */
# Line 480 | Line 510 | animate()                      /* run animation */
510                                  progname);
511                  quit(1);
512          }
513 +                                        /* initialize archive argument list */
514 +        i = 16;
515 +        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
516 +                i = strlen(vval(ARCHIVE));
517 +        arcnext = arcfirst = arcargs + i;
518                                          /* initialize status file */
519          if (astat.rnext == 0)
520                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 574 | Line 609 | filterframes()                         /* catch up with filtering */
609                  dofilt(i, vp, getexp(i), 0);            /* filter frame */
610          }
611          bwait(0);                       /* wait for filter processes */
612 <        archive(astat.fnext, i-1);      /* archive originals */
612 >        archive();                      /* archive originals */
613          astat.fnext = i;                /* update status */
614          putastat();
615   }
# Line 636 | Line 671 | int    first, last;
671   char    *vfn;
672   {
673          char    combuf[2048];
674 +        char    *inspoint;
675          register int    i;
676  
677          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 646 | Line 682 | char   *vfn;
682                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
683                          }
684                                          /* create command */
685 <        sprintf(combuf, "rpict%s -w0 ", rendopt);
685 >        sprintf(combuf, "rpict%s -w0", rendopt);
686          if (vint(INTERP) || atoi(vval(MBLUR)))
687 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
688 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
689 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
687 >                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
688 >        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
689 >                        vval(BASENAME), rresopt, first);
690 >        inspoint = combuf + strlen(combuf);
691 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
692                                          /* run in parallel */
693 <        if (pruncom(combuf, (last-first+1)/(vint(INTERP)+1))) {
693 >        i = (last-first+1)/(vint(INTERP)+1);
694 >        if (i < 1) i = 1;
695 >        if (pruncom(combuf, inspoint, i)) {
696                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
697                                  progname, first, last);
698                  quit(1);
# Line 730 | Line 770 | int    frame;
770   }
771  
772  
773 < archive(first, last)                    /* archive and remove renderings */
734 < int     first, last;
773 > archive()                       /* archive and remove renderings */
774   {
775   #define RMCOML  (sizeof(rmcom)-1)
776          static char     rmcom[] = "rm -f";
738        int     offset = RMCOML;
739        char    combuf[10240];
740        struct stat     stb;
741        register char   *cp;
777          register int    i;
778  
779 <        if (noaction)
780 <                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;
779 >        if (arcnext == arcfirst)
780 >                return;                         /* nothing to do */
781          if (vdef(ARCHIVE)) {                    /* run archive command */
782                  i = strlen(vval(ARCHIVE));
783 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
784 <                if (runcom(combuf+offset-i)) {
785 <                        fprintf(stderr,
786 <                "%s: error running archive command on frames %d through %d\n",
773 <                                        progname, first, last);
783 >                strncpy(arcfirst-i, vval(ARCHIVE), i);
784 >                if (runcom(arcfirst-i)) {
785 >                        fprintf(stderr, "%s: error running archive command\n",
786 >                                        progname);
787                          quit(1);
788                  }
789          }
790                                                  /* run remove command */
791 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
792 <        runcom(combuf+offset-RMCOML);
791 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
792 >        runcom(arcfirst-RMCOML);
793 >        arcnext = arcfirst;                     /* reset argument list */
794   #undef RMCOML
795   }
796  
# Line 789 | Line 803 | char   *ep;
803   int     rvr;
804   {
805          extern int      frecover();
806 +        static int      iter = 0;
807          char    fnbefore[128], fnafter[128];
808 <        char    combuf[1024], fname[128];
809 <        int     usepinterp, usepfilt;
808 >        char    combuf[1024], fname0[128], fname1[128];
809 >        int     usepinterp, usepfilt, nora_rgbe;
810          int     frseq[2];
811                                                  /* check what is needed */
812          usepinterp = atoi(vval(MBLUR));
813          usepfilt = pfiltalways | ep==NULL;
814 +        if (ep != NULL && !strcmp(ep, "1"))
815 +                ep = "+0";
816 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
817 +                        *ep != '+' || *ep != '-' || !isint(ep);
818                                                  /* compute rendered views */
819          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
820          frseq[1] = frseq[0] + vint(INTERP) + 1;
# Line 804 | Line 823 | int    rvr;
823          if (frseq[1] == frame) {                        /* pfilt only */
824                  frseq[0] = frseq[1];
825                  usepinterp = 0;                 /* update what's needed */
826 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
827 <        } else if (frseq[0] == frame) {         /* no interpolation */
828 <                                                /* update what's needed */
829 <                if (!usepinterp)
830 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
826 >                usepfilt |= nora_rgbe;
827 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
828 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
829 >                        *arcnext++ = ' ';
830 >                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
831 >                        while (*arcnext) arcnext++;
832 >                        strcpy(arcnext, ".unf");
833 >                        arcnext += 4;
834 >                        if (usepinterp || vint(INTERP)) {       /* and z-buf */
835 >                                *arcnext++ = ' ';
836 >                                sprintf(arcnext, vval(BASENAME),
837 >                                                frame-vint(INTERP)-1);
838 >                                while (*arcnext) arcnext++;
839 >                                strcpy(arcnext, ".zbf");
840 >                                arcnext += 4;
841 >                        }
842 >                }
843 >                if (!usepinterp)                /* update what's needed */
844 >                        usepfilt |= nora_rgbe;
845          } else                                  /* interpolation needed */
846                  usepinterp++;
847          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 823 | Line 856 | int    rvr;
856                          return(1);
857                  if (atoi(vval(MBLUR))) {
858                          FILE    *fp;            /* motion blurring */
859 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
860 <                        if ((fp = fopen(fname, "w")) == NULL) {
861 <                                perror(fname); quit(1);
859 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
860 >                                        'a'+(iter%26));
861 >                        if ((fp = fopen(fname0, "w")) == NULL) {
862 >                                perror(fname0); quit(1);
863                          }
864                          fputs(VIEWSTR, fp);
865                          fprintview(vp, fp);
# Line 836 | Line 870 | int    rvr;
870                                                  progname, frame+1);
871                                  quit(1);
872                          }
873 <                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
874 <                        if ((fp = fopen(fname, "w")) == NULL) {
875 <                                perror(fname); quit(1);
873 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
874 >                                        'a'+(iter%26));
875 >                        if ((fp = fopen(fname1, "w")) == NULL) {
876 >                                perror(fname1); quit(1);
877                          }
878                          fputs(VIEWSTR, fp);
879                          fprintview(vp, fp);
880                          putc('\n', fp); fclose(fp);
881                          sprintf(combuf,
882 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
882 >                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
883                          *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
884 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
885 <                                        vval(DIRECTORY), vval(DIRECTORY),
886 <                                        vval(DIRECTORY), vval(DIRECTORY));
884 >                                        atoi(vval(MBLUR)),
885 >                                        fname0, fname1, fname0, fname1);
886 >                        iter++;
887                  } else                          /* no blurring */
888                          strcpy(combuf, "pinterp");
889                  strcat(combuf, viewopt(vp));
# Line 895 | Line 930 | int    rvr;
930          } else {                                /* else just check it */
931                  if (rvr == 2)
932                          return(1);
933 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
933 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
934          }
935                                                  /* output file name */
936 <        sprintf(fname, vval(BASENAME), frame);
937 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
936 >        sprintf(fname0, vval(BASENAME), frame);
937 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
938          if (rvr)                                /* in recovery */
939                  return(runcom(combuf));
940          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 931 | Line 966 | int    n;
966                          quit(1);
967                  }
968          } else if (n < viewnum) {       /* rewind file */
969 +                if (viewnum == 1 && feof(viewfp))
970 +                        return(&curview);               /* just one view */
971                  if (fseek(viewfp, 0L, 0) == EOF) {
972                          perror(vval(VIEWFILE));
973                          quit(1);
# Line 940 | Line 977 | int    n;
977          }
978          while (n > viewnum) {           /* scan to desired view */
979                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
980 <                        return(NULL);
980 >                        return(viewnum==1 ? &curview : NULL);
981                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
982                          viewnum++;
983          }
# Line 1052 | Line 1089 | int    status;
1089          register PROC   *pp;
1090  
1091          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        }
1092          if (pp->elen) {                 /* pass errors */
1093 +                if (ps->hostname[0])
1094 +                        fprintf(stderr, "%s: ", ps->hostname);
1095 +                fprintf(stderr, "Error output from: %s\n", pp->com);
1096                  fputs(pp->errs, stderr);
1097                  fflush(stderr);
1098                  if (ps->hostname[0])
# Line 1097 | Line 1131 | int    (*rf)();
1131  
1132          if (noaction) {
1133                  if (!silent)
1134 <                        printf("\t%s\n", com);  /* just echo it */
1134 >                        printf("\t%s\n", com);  /* echo command */
1135                  return(0);
1136          }
1137                                          /* else start it when we can */
1138          while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1139                  bwait(1);
1140 +        if (!silent) {                          /* echo command */
1141 +                PSERVER *ps;
1142 +                int     psn = pid;
1143 +                ps = findjob(&psn);
1144 +                printf("\t%s\n", com);
1145 +                printf("\tProcess started on %s\n", phostname(ps));
1146 +                fflush(stdout);
1147 +        }
1148          psl = findpslot(pid);           /* record info. in appropriate slot */
1149          psl->pid = pid;
1150          psl->fout = fout;
# Line 1138 | Line 1180 | int    ncoms;
1180  
1181  
1182   int
1183 < pruncom(com, maxcopies)         /* run a command in parallel over network */
1184 < char    *com;
1183 > pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1184 > char    *com, *ppins;
1185   int     maxcopies;
1186   {
1187          int     retstatus = 0;
1188 +        int     hostcopies;
1189 +        char    com1buf[10240], *com1, *endcom1;
1190          int     status;
1191          register PSERVER        *ps;
1192  
1193 <        if (noaction) {
1194 <                if (!silent)
1195 <                        printf("\t%s\n", com);  /* just echo */
1193 >        if (!silent)
1194 >                printf("\t%s\n", com);  /* echo command */
1195 >        if (noaction)
1196                  return(0);
1197 <        }
1197 >        fflush(stdout);
1198                                          /* start jobs on each server */
1199 <        for (ps = pslist; ps != NULL; ps = ps->next)
1199 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1200 >                hostcopies = 0;
1201 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1202 >                        strcpy(com1=com1buf, com);      /* build -PP command */
1203 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1204 >                                        vval(DIRECTORY), phostname(ps));
1205 >                        strcat(com1, ppins);
1206 >                        endcom1 = com1 + strlen(com1);
1207 >                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1208 >                                        vval(DIRECTORY), phostname(ps));
1209 >                } else {
1210 >                        com1 = com;
1211 >                        endcom1 = NULL;
1212 >                }
1213                  while (maxcopies > 0 &&
1214 <                                startjob(ps, savestr(com), donecom) != -1) {
1214 >                                startjob(ps, savestr(com1), donecom) != -1) {
1215                          sleep(10);
1216 +                        hostcopies++;
1217                          maxcopies--;
1218 +                        if (endcom1 != NULL)
1219 +                                *endcom1 = '\0';
1220                  }
1221 +                if (!silent && hostcopies) {
1222 +                        if (hostcopies > 1)
1223 +                                printf("\t%d duplicate processes", hostcopies);
1224 +                        else
1225 +                                printf("\tProcess");
1226 +                        printf(" started on %s\n", phostname(ps));
1227 +                        fflush(stdout);
1228 +                }
1229 +        }
1230                                          /* wait for jobs to finish */
1231          while ((status = wait4job(NULL, -1)) != -1)
1232                  if (status)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines