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.11 by greg, Tue Apr 16 10:38:19 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1995 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# 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 161 | Line 175 | char   *argv[];
175                  argv[i] = vval(NEXTANIM);       /* just change input file */
176                  if (!silent)
177                          printargs(argc, argv, stdout);
178 <                execvp(progname, argv);         /* pass to next */
179 <                quit(1);                        /* shouldn't return */
178 >                if ((argv[0] = getpath(progname,getenv("PATH"),X_OK)) == NULL)
179 >                        fprintf(stderr, "%s: command not found\n", progname);
180 >                else
181 >                        execv(progname, argv);
182 >                quit(1);
183          }
184          quit(0);
185   userr:
# Line 199 | Line 216 | getastat()                     /* check/set animation status */
216                  goto fmterr;
217          fclose(fp);
218          if (astat.pid != 0) {                   /* thinks it's still running */
219 <                gethostname(buf, sizeof(buf));
203 <                if (strcmp(buf, astat.host)) {
219 >                if (strcmp(myhostname(), astat.host)) {
220                          fprintf(stderr,
221                          "%s: process %d may still be running on host %s\n",
222                                          progname, astat.pid, astat.host);
# Line 219 | Line 235 | getastat()                     /* check/set animation status */
235                  return(-1);
236          }
237   setours:                                        /* set our values */
238 <        gethostname(astat.host, sizeof(astat.host));
238 >        strcpy(astat.host, myhostname());
239          astat.pid = getpid();
240          strcpy(astat.cfname, cfname);
241          return(0);
# Line 277 | Line 293 | checkdir()                     /* make sure we have our directory */
293  
294   setdefaults()                   /* set default values */
295   {
296 +        extern char     *atos();
297          char    buf[256];
298  
299          if (vdef(ANIMATE)) {
# Line 300 | Line 317 | setdefaults()                  /* set default values */
317                  vdef(START)++;
318          }
319          if (!vdef(END)) {
320 <                sprintf(buf, "%d", countviews());
320 >                sprintf(buf, "%d", countviews()+vint(START)-1);
321                  vval(END) = savqstr(buf);
322                  vdef(END)++;
323          }
324 +        if (vint(END) < vint(START)) {
325 +                fprintf(stderr, "%s: ending frame less than starting frame\n",
326 +                                progname);
327 +                quit(1);
328 +        }
329          if (!vdef(BASENAME)) {
330                  sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
331                  vval(BASENAME) = savqstr(buf);
# Line 337 | Line 359 | setdefaults()                  /* set default values */
359                  vval(DISKSPACE) = "100";
360                  vdef(DISKSPACE)++;
361          }
362 +        if (!vdef(RSH)) {
363 +                vval(RSH) = REMSH;
364 +                vdef(RSH)++;
365 +        }
366 +                                /* locate remote shell program */
367 +        atos(buf, sizeof(buf), vval(RSH));
368 +        if ((remsh = getpath(buf, getenv("PATH"), X_OK)) != NULL)
369 +                remsh = savqstr(remsh);
370 +        else
371 +                remsh = vval(RSH);      /* will generate error if used */
372 +
373                                  /* append rendering options */
374          if (vdef(RENDER))
375                  sprintf(rendopt+strlen(rendopt), " %s", vval(RENDER));
# Line 399 | Line 432 | sethosts()                     /* set up process servers */
432   }
433  
434  
435 < getradfile(rfname)              /* run rad and get needed variables */
436 < char    *rfname;
435 > getradfile(rfargs)              /* run rad and get needed variables */
436 > char    *rfargs;
437   {
438          static short    mvar[] = {OCTREE,PFILT,RESOLUTION,EXPOSURE,-1};
439          char    combuf[256];
# Line 410 | Line 443 | char   *rfname;
443          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
444          sprintf(combuf,
445          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
446 <                        rfname, rendopt+2);
446 >                        rfargs, rendopt+2);
447          cp = combuf;
448          while (*cp) cp++;               /* match unset variables */
449          for (i = 0; mvar[i] >= 0; i++)
# Line 422 | Line 455 | char   *rfname;
455          sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
456          cp += 11;                       /* point to file name */
457          if (system(combuf)) {
458 <                fprintf(stderr, "%s: bad rad input file \"%s\"\n",
459 <                                progname, rfname);
458 >                fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
459 >                                progname, combuf);
460                  quit(1);
461          }
462          loadvars(cp);                   /* load variables and remove file */
# Line 480 | Line 513 | animate()                      /* run animation */
513                                  progname);
514                  quit(1);
515          }
516 +                                        /* initialize archive argument list */
517 +        i = 16;
518 +        if (vdef(ARCHIVE) && strlen(vval(ARCHIVE)) > i)
519 +                i = strlen(vval(ARCHIVE));
520 +        arcnext = arcfirst = arcargs + i;
521                                          /* initialize status file */
522          if (astat.rnext == 0)
523                  astat.rnext = astat.fnext = astat.tnext = vint(START);
# Line 574 | Line 612 | filterframes()                         /* catch up with filtering */
612                  dofilt(i, vp, getexp(i), 0);            /* filter frame */
613          }
614          bwait(0);                       /* wait for filter processes */
615 <        archive(astat.fnext, i-1);      /* archive originals */
615 >        archive();                      /* archive originals */
616          astat.fnext = i;                /* update status */
617          putastat();
618   }
# Line 636 | Line 674 | int    first, last;
674   char    *vfn;
675   {
676          char    combuf[2048];
677 +        char    *inspoint;
678          register int    i;
679  
680          if (!noaction && vint(INTERP))          /* create dummy frames */
# Line 646 | Line 685 | char   *vfn;
685                                  close(open(combuf, O_RDONLY|O_CREAT, 0666));
686                          }
687                                          /* create command */
688 <        sprintf(combuf, "rpict%s -w0 ", rendopt);
688 >        sprintf(combuf, "rpict%s -w0", rendopt);
689          if (vint(INTERP) || atoi(vval(MBLUR)))
690 <                sprintf(combuf+strlen(combuf), "-z %s.zbf ", vval(BASENAME));
691 <        sprintf(combuf+strlen(combuf), "-o %s.unf %s -S %d %s < %s",
692 <                        vval(BASENAME), rresopt, first, vval(OCTREE), vfn);
690 >                sprintf(combuf+strlen(combuf), " -z %s.zbf", vval(BASENAME));
691 >        sprintf(combuf+strlen(combuf), " -o %s.unf %s -S %d",
692 >                        vval(BASENAME), rresopt, first);
693 >        inspoint = combuf + strlen(combuf);
694 >        sprintf(inspoint, " %s < %s", vval(OCTREE), vfn);
695                                          /* run in parallel */
696 <        if (pruncom(combuf, (last-first+1)/(vint(INTERP)+1))) {
696 >        i = (last-first+1)/(vint(INTERP)+1);
697 >        if (i < 1) i = 1;
698 >        if (pruncom(combuf, inspoint, i)) {
699                  fprintf(stderr, "%s: error rendering frames %d through %d\n",
700                                  progname, first, last);
701                  quit(1);
# Line 730 | Line 773 | int    frame;
773   }
774  
775  
776 < archive(first, last)                    /* archive and remove renderings */
734 < int     first, last;
776 > archive()                       /* archive and remove renderings */
777   {
778   #define RMCOML  (sizeof(rmcom)-1)
779          static char     rmcom[] = "rm -f";
738        int     offset = RMCOML;
739        char    combuf[10240];
740        struct stat     stb;
741        register char   *cp;
780          register int    i;
781  
782 <        if (noaction)
783 <                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;
782 >        if (arcnext == arcfirst)
783 >                return;                         /* nothing to do */
784          if (vdef(ARCHIVE)) {                    /* run archive command */
785                  i = strlen(vval(ARCHIVE));
786 <                strncpy(combuf+offset-i, vval(ARCHIVE), i);
787 <                if (runcom(combuf+offset-i)) {
788 <                        fprintf(stderr,
789 <                "%s: error running archive command on frames %d through %d\n",
773 <                                        progname, first, last);
786 >                strncpy(arcfirst-i, vval(ARCHIVE), i);
787 >                if (runcom(arcfirst-i)) {
788 >                        fprintf(stderr, "%s: error running archive command\n",
789 >                                        progname);
790                          quit(1);
791                  }
792          }
793                                                  /* run remove command */
794 <        strncpy(combuf+offset-RMCOML, rmcom, RMCOML);
795 <        runcom(combuf+offset-RMCOML);
794 >        strncpy(arcfirst-RMCOML, rmcom, RMCOML);
795 >        runcom(arcfirst-RMCOML);
796 >        arcnext = arcfirst;                     /* reset argument list */
797   #undef RMCOML
798   }
799  
# Line 789 | Line 806 | char   *ep;
806   int     rvr;
807   {
808          extern int      frecover();
809 +        static int      iter = 0;
810          char    fnbefore[128], fnafter[128];
811 <        char    combuf[1024], fname[128];
812 <        int     usepinterp, usepfilt;
811 >        char    combuf[1024], fname0[128], fname1[128];
812 >        int     usepinterp, usepfilt, nora_rgbe;
813          int     frseq[2];
814                                                  /* check what is needed */
815          usepinterp = atoi(vval(MBLUR));
816          usepfilt = pfiltalways | ep==NULL;
817 +        if (ep != NULL && !strcmp(ep, "1"))
818 +                ep = "+0";
819 +        nora_rgbe = strcmp(vval(OVERSAMP),"1") || ep==NULL ||
820 +                        *ep != '+' || *ep != '-' || !isint(ep);
821                                                  /* compute rendered views */
822          frseq[0] = frame - ((frame-1) % (vint(INTERP)+1));
823          frseq[1] = frseq[0] + vint(INTERP) + 1;
# Line 804 | Line 826 | int    rvr;
826          if (frseq[1] == frame) {                        /* pfilt only */
827                  frseq[0] = frseq[1];
828                  usepinterp = 0;                 /* update what's needed */
829 <                usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
830 <        } else if (frseq[0] == frame) {         /* no interpolation */
831 <                                                /* update what's needed */
832 <                if (!usepinterp)
833 <                        usepfilt |= vflt(OVERSAMP)>1.01 || strcmp(ep,"1");
829 >                usepfilt |= nora_rgbe;
830 >        } else if (frseq[0] == frame) {         /* no interpolation needed */
831 >                if (!rvr && frame > 1+vint(INTERP)) {   /* archive previous */
832 >                        *arcnext++ = ' ';
833 >                        sprintf(arcnext, vval(BASENAME), frame-vint(INTERP)-1);
834 >                        while (*arcnext) arcnext++;
835 >                        strcpy(arcnext, ".unf");
836 >                        arcnext += 4;
837 >                        if (usepinterp || vint(INTERP)) {       /* and z-buf */
838 >                                *arcnext++ = ' ';
839 >                                sprintf(arcnext, vval(BASENAME),
840 >                                                frame-vint(INTERP)-1);
841 >                                while (*arcnext) arcnext++;
842 >                                strcpy(arcnext, ".zbf");
843 >                                arcnext += 4;
844 >                        }
845 >                }
846 >                if (!usepinterp)                /* update what's needed */
847 >                        usepfilt |= nora_rgbe;
848          } else                                  /* interpolation needed */
849                  usepinterp++;
850          if (frseq[1] >= astat.rnext)            /* next batch unavailable */
# Line 823 | Line 859 | int    rvr;
859                          return(1);
860                  if (atoi(vval(MBLUR))) {
861                          FILE    *fp;            /* motion blurring */
862 <                        sprintf(fname, "%s/vw0", vval(DIRECTORY));
863 <                        if ((fp = fopen(fname, "w")) == NULL) {
864 <                                perror(fname); quit(1);
862 >                        sprintf(fname0, "%s/vw0%c", vval(DIRECTORY),
863 >                                        'a'+(iter%26));
864 >                        if ((fp = fopen(fname0, "w")) == NULL) {
865 >                                perror(fname0); quit(1);
866                          }
867                          fputs(VIEWSTR, fp);
868                          fprintview(vp, fp);
# Line 836 | Line 873 | int    rvr;
873                                                  progname, frame+1);
874                                  quit(1);
875                          }
876 <                        sprintf(fname, "%s/vw1", vval(DIRECTORY));
877 <                        if ((fp = fopen(fname, "w")) == NULL) {
878 <                                perror(fname); quit(1);
876 >                        sprintf(fname1, "%s/vw1%c", vval(DIRECTORY),
877 >                                        'a'+(iter%26));
878 >                        if ((fp = fopen(fname1, "w")) == NULL) {
879 >                                perror(fname1); quit(1);
880                          }
881                          fputs(VIEWSTR, fp);
882                          fprintview(vp, fp);
883                          putc('\n', fp); fclose(fp);
884                          sprintf(combuf,
885 <        "(pmblur %s %d %s/vw0 %s/vw1; rm -f %s/vw0 %s/vw1) | pinterp -B",
885 >                        "(pmblur %s %d %s %s; rm -f %s %s) | pinterp -B",
886                          *sskip(vval(MBLUR)) ? sskip2(vval(MBLUR),1) : "1",
887 <                                        atoi(vval(MBLUR)), vval(DIRECTORY),
888 <                                        vval(DIRECTORY), vval(DIRECTORY),
889 <                                        vval(DIRECTORY), vval(DIRECTORY));
887 >                                        atoi(vval(MBLUR)),
888 >                                        fname0, fname1, fname0, fname1);
889 >                        iter++;
890                  } else                          /* no blurring */
891                          strcpy(combuf, "pinterp");
892                  strcat(combuf, viewopt(vp));
# Line 895 | Line 933 | int    rvr;
933          } else {                                /* else just check it */
934                  if (rvr == 2)
935                          return(1);
936 <                sprintf(combuf, "ra_rgbe -r %s.unf", fnbefore);
936 >                sprintf(combuf, "ra_rgbe -e %s -r %s.unf", ep, fnbefore);
937          }
938                                                  /* output file name */
939 <        sprintf(fname, vval(BASENAME), frame);
940 <        sprintf(combuf+strlen(combuf), " > %s.pic", fname);
939 >        sprintf(fname0, vval(BASENAME), frame);
940 >        sprintf(combuf+strlen(combuf), " > %s.pic", fname0);
941          if (rvr)                                /* in recovery */
942                  return(runcom(combuf));
943          bruncom(combuf, frame, frecover);       /* else run in background */
# Line 931 | Line 969 | int    n;
969                          quit(1);
970                  }
971          } else if (n < viewnum) {       /* rewind file */
972 +                if (viewnum == 1 && feof(viewfp))
973 +                        return(&curview);               /* just one view */
974                  if (fseek(viewfp, 0L, 0) == EOF) {
975                          perror(vval(VIEWFILE));
976                          quit(1);
# Line 940 | Line 980 | int    n;
980          }
981          while (n > viewnum) {           /* scan to desired view */
982                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
983 <                        return(NULL);
983 >                        return(viewnum==1 ? &curview : NULL);
984                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
985                          viewnum++;
986          }
# Line 1052 | Line 1092 | int    status;
1092          register PROC   *pp;
1093  
1094          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        }
1095          if (pp->elen) {                 /* pass errors */
1096 +                if (ps->hostname[0])
1097 +                        fprintf(stderr, "%s: ", ps->hostname);
1098 +                fprintf(stderr, "Error output from: %s\n", pp->com);
1099                  fputs(pp->errs, stderr);
1100                  fflush(stderr);
1101                  if (ps->hostname[0])
# Line 1097 | Line 1134 | int    (*rf)();
1134  
1135          if (noaction) {
1136                  if (!silent)
1137 <                        printf("\t%s\n", com);  /* just echo it */
1137 >                        printf("\t%s\n", com);  /* echo command */
1138                  return(0);
1139          }
1140                                          /* else start it when we can */
1141          while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1142                  bwait(1);
1143 +        if (!silent) {                          /* echo command */
1144 +                PSERVER *ps;
1145 +                int     psn = pid;
1146 +                ps = findjob(&psn);
1147 +                printf("\t%s\n", com);
1148 +                printf("\tProcess started on %s\n", phostname(ps));
1149 +                fflush(stdout);
1150 +        }
1151          psl = findpslot(pid);           /* record info. in appropriate slot */
1152          psl->pid = pid;
1153          psl->fout = fout;
# Line 1138 | Line 1183 | int    ncoms;
1183  
1184  
1185   int
1186 < pruncom(com, maxcopies)         /* run a command in parallel over network */
1187 < char    *com;
1186 > pruncom(com, ppins, maxcopies)  /* run a command in parallel over network */
1187 > char    *com, *ppins;
1188   int     maxcopies;
1189   {
1190          int     retstatus = 0;
1191 +        int     hostcopies;
1192 +        char    com1buf[10240], *com1, *endcom1;
1193          int     status;
1194          register PSERVER        *ps;
1195  
1196 <        if (noaction) {
1197 <                if (!silent)
1198 <                        printf("\t%s\n", com);  /* just echo */
1196 >        if (!silent)
1197 >                printf("\t%s\n", com);  /* echo command */
1198 >        if (noaction)
1199                  return(0);
1200 <        }
1200 >        fflush(stdout);
1201                                          /* start jobs on each server */
1202 <        for (ps = pslist; ps != NULL; ps = ps->next)
1202 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1203 >                hostcopies = 0;
1204 >                if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1205 >                        strcpy(com1=com1buf, com);      /* build -PP command */
1206 >                        sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1207 >                                        vval(DIRECTORY), phostname(ps));
1208 >                        strcat(com1, ppins);
1209 >                        endcom1 = com1 + strlen(com1);
1210 >                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1211 >                                        vval(DIRECTORY), phostname(ps));
1212 >                } else {
1213 >                        com1 = com;
1214 >                        endcom1 = NULL;
1215 >                }
1216                  while (maxcopies > 0 &&
1217 <                                startjob(ps, savestr(com), donecom) != -1) {
1217 >                                startjob(ps, savestr(com1), donecom) != -1) {
1218                          sleep(10);
1219 +                        hostcopies++;
1220                          maxcopies--;
1221 +                        if (endcom1 != NULL)
1222 +                                *endcom1 = '\0';
1223                  }
1224 +                if (!silent && hostcopies) {
1225 +                        if (hostcopies > 1)
1226 +                                printf("\t%d duplicate processes", hostcopies);
1227 +                        else
1228 +                                printf("\tProcess");
1229 +                        printf(" started on %s\n", phostname(ps));
1230 +                        fflush(stdout);
1231 +                }
1232 +        }
1233                                          /* wait for jobs to finish */
1234          while ((status = wait4job(NULL, -1)) != -1)
1235                  if (status)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines