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.11 by greg, Tue Apr 16 10:38:19 1996 UTC vs.
Revision 2.24 by gwlarson, Thu Feb 26 10:27:45 1998 UTC

# Line 93 | Line 93 | 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 */
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? */
# Line 108 | Line 108 | struct pslot {
108   }       *pslot;                 /* process slots */
109   int     npslots;                /* number of process slots */
110  
111 int     lastpid;                /* ID of last completed background process */
112 PSERVER *lastpserver;           /* last process server used */
113
111   #define phostname(ps)   ((ps)->hostname[0] ? (ps)->hostname : astat.host)
112  
113   struct pslot    *findpslot();
114  
115 + PSERVER *lastpserver;           /* last process server with error */
116 +
117   VIEW    *getview();
118   char    *getexp();
119  
120 + extern time_t   fdate(), time();
121  
122 +
123   main(argc, argv)
124   int     argc;
125   char    *argv[];
# Line 149 | Line 150 | char   *argv[];
150          cfname = argv[i];
151                                                  /* load variables */
152          loadvars(cfname);
153 +                                                /* check variables */
154 +        checkvalues();
155                                                  /* did we get DIRECTORY? */
156          checkdir();
157                                                  /* check status */
# Line 190 | Line 193 | userr:
193  
194   getastat()                      /* check/set animation status */
195   {
196 <        char    buf[256];
196 >        char    sfname[256];
197          FILE    *fp;
198  
199 <        sprintf(buf, "%s/%s", vval(DIRECTORY), SFNAME);
200 <        if ((fp = fopen(buf, "r")) == NULL) {
199 >        sprintf(sfname, "%s/%s", vval(DIRECTORY), SFNAME);
200 >        if ((fp = fopen(sfname, "r")) == NULL) {
201                  if (errno != ENOENT) {
202 <                        perror(buf);
202 >                        perror(sfname);
203                          return(-1);
204                  }
205                  astat.rnext = astat.fnext = astat.tnext = 0;
# Line 229 | Line 232 | getastat()                     /* check/set animation status */
232                  }
233                  /* assume it is dead */
234          }
235 <        if (strcmp(cfname, astat.cfname) && astat.tnext != 0) { /* other's */
235 >        if (strcmp(cfname, astat.cfname) && astat.pid != 0) {   /* other's */
236                  fprintf(stderr, "%s: unfinished job \"%s\"\n",
237                                  progname, astat.cfname);
238                  return(-1);
239          }
240 +                                                /* check control file mods. */
241 +        if (!nowarn && fdate(cfname) > fdate(sfname))
242 +                fprintf(stderr,
243 +                        "%s: warning - control file modified since last run\n",
244 +                                progname);
245   setours:                                        /* set our values */
246          strcpy(astat.host, myhostname());
247          astat.pid = getpid();
# Line 241 | Line 249 | setours:                                       /* set our values */
249          return(0);
250   fmterr:
251          fprintf(stderr, "%s: format error in status file \"%s\"\n",
252 <                        progname, buf);
252 >                        progname, sfname);
253          fclose(fp);
254          return(-1);
255   }
# Line 294 | Line 302 | checkdir()                     /* make sure we have our directory */
302   setdefaults()                   /* set default values */
303   {
304          extern char     *atos();
305 +        int     decades;
306          char    buf[256];
307  
308          if (vdef(ANIMATE)) {
# Line 327 | Line 336 | setdefaults()                  /* set default values */
336                  quit(1);
337          }
338          if (!vdef(BASENAME)) {
339 <                sprintf(buf, "%s/frame%%03d", vval(DIRECTORY));
339 >                decades = (int)log10((double)vint(END)) + 1;
340 >                if (decades < 3) decades = 3;
341 >                sprintf(buf, "%s/frame%%0%dd", vval(DIRECTORY), decades);
342                  vval(BASENAME) = savqstr(buf);
343                  vdef(BASENAME)++;
344          }
# Line 439 | Line 450 | char   *rfargs;
450          char    combuf[256];
451          register int    i;
452          register char   *cp;
453 +        char    *pippt;
454                                          /* create rad command */
455          sprintf(rendopt, " @%s/render.opt", vval(DIRECTORY));
456          sprintf(combuf,
457          "rad -v 0 -s -e -w %s OPTFILE=%s | egrep '^[ \t]*(NOMATCH",
458                          rfargs, rendopt+2);
459          cp = combuf;
460 <        while (*cp) cp++;               /* match unset variables */
460 >        while (*cp) {
461 >                if (*cp == '|') pippt = cp;
462 >                cp++;
463 >        }                               /* match unset variables */
464          for (i = 0; mvar[i] >= 0; i++)
465                  if (!vdef(mvar[i])) {
466                          *cp++ = '|';
467                          strcpy(cp, vnam(mvar[i]));
468                          while (*cp) cp++;
469 +                        pippt = NULL;
470                  }
471 <        sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
472 <        cp += 11;                       /* point to file name */
471 >        if (pippt != NULL)
472 >                strcpy(pippt, "> /dev/null");   /* nothing to match */
473 >        else {
474 >                sprintf(cp, ")[ \t]*=' > %s/radset.var", vval(DIRECTORY));
475 >                cp += 11;               /* point to file name */
476 >        }
477          if (system(combuf)) {
478                  fprintf(stderr, "%s: error executing rad command:\n\t%s\n",
479                                  progname, combuf);
480                  quit(1);
481          }
482 <        loadvars(cp);                   /* load variables and remove file */
483 <        unlink(cp);
482 >        if (pippt == NULL) {            /* load variables and remove file */
483 >                loadvars(cp);
484 >                unlink(cp);
485 >        }
486   }
487  
488  
# Line 475 | Line 497 | animate()                      /* run animation */
497          i = sscanf(vval(RESOLUTION), "%d %d %f", &xres, &yres, &pa);
498          mult = vflt(OVERSAMP);
499          if (i == 3) {
500 <                sprintf(rresopt, "-x %d -y %d -pa %f", (int)(mult*xres),
500 >                sprintf(rresopt, "-x %d -y %d -pa %.3f", (int)(mult*xres),
501                                  (int)(mult*yres), pa);
502 <                sprintf(fresopt, "-x %d -y %d -pa %f", xres, yres, pa);
502 >                sprintf(fresopt, "-x %d -y %d -pa %.3f", xres, yres, pa);
503          } else if (i) {
504                  if (i == 1) yres = xres;
505                  sprintf(rresopt, "-x %d -y %d", (int)(mult*xres),
# Line 505 | Line 527 | animate()                      /* run animation */
527                                          /* figure # frames per batch */
528          d1 = mult*xres*mult*yres*4;             /* space for orig. picture */
529          if ((i=vint(INTERP)) || atoi(vval(MBLUR)))
530 <                d1 += mult*xres*mult*yres*4;    /* space for z-buffer */
530 >                d1 += mult*xres*mult*yres*sizeof(float);        /* Z-buffer */
531          d2 = xres*yres*4;                       /* space for final picture */
532          frames_batch = (i+1)*(vflt(DISKSPACE)*1048576.-d1)/(d1+i*d2);
533          if (frames_batch < i+2) {
# Line 834 | Line 856 | int    rvr;
856                          while (*arcnext) arcnext++;
857                          strcpy(arcnext, ".unf");
858                          arcnext += 4;
859 <                        if (usepinterp || vint(INTERP)) {       /* and z-buf */
859 >                        if (usepinterp || vint(INTERP)) {       /* and Z-buf */
860                                  *arcnext++ = ' ';
861                                  sprintf(arcnext, vval(BASENAME),
862                                                  frame-vint(INTERP)-1);
# Line 892 | Line 914 | int    rvr;
914                  strcat(combuf, viewopt(vp));
915                  if (vbool(RTRACE))
916                          sprintf(combuf+strlen(combuf), " -ff -fr '%s -w0 %s'",
917 <                                        rendopt, vval(OCTREE));
917 >                                        rendopt+1, vval(OCTREE));
918                  if (vdef(PINTERP))
919                          sprintf(combuf+strlen(combuf), " %s", vval(PINTERP));
920                  if (usepfilt)
# Line 963 | Line 985 | int    n;
985                  }
986                  return(NULL);
987          }
988 <        if (viewfp == NULL) {           /* open file */
988 >        if (viewfp == NULL) {                   /* open file */
989                  if ((viewfp = fopen(vval(VIEWFILE), "r")) == NULL) {
990                          perror(vval(VIEWFILE));
991                          quit(1);
992                  }
993 <        } else if (n < viewnum) {       /* rewind file */
993 >        } else if (n > 0 && n < viewnum) {      /* rewind file */
994                  if (viewnum == 1 && feof(viewfp))
995                          return(&curview);               /* just one view */
996                  if (fseek(viewfp, 0L, 0) == EOF) {
# Line 978 | Line 1000 | int    n;
1000                  copystruct(&curview, &stdview);
1001                  viewnum = 0;
1002          }
1003 +        if (n < 0) {                            /* get next view */
1004 +                register int    c = getc(viewfp);
1005 +                if (c == EOF)
1006 +                        return((VIEW *)NULL);           /* that's it */
1007 +                ungetc(c, viewfp);
1008 +                n = viewnum + 1;
1009 +        }
1010          while (n > viewnum) {           /* scan to desired view */
1011                  if (fgets(linebuf, sizeof(linebuf), viewfp) == NULL)
1012 <                        return(viewnum==1 ? &curview : NULL);
1012 >                        return(viewnum==1 ? &curview : (VIEW *)NULL);
1013                  if (isview(linebuf) && sscanview(&curview, linebuf) > 0)
1014                          viewnum++;
1015          }
# Line 991 | Line 1020 | int    n;
1020   int
1021   countviews()                    /* count views in view file */
1022   {
1023 <        register int    n = 0;
1023 >        int     n;
1024  
1025 <        while (getview(n+1) != NULL)
1025 >        if (getview(n=1) == NULL)
1026 >                return(0);
1027 >        while (getview(-1) != NULL)
1028                  n++;
1029          return(n);
1030   }
# Line 1013 | Line 1044 | int    n;
1044          if (n == 0) {                           /* signal to close file */
1045                  if (expfp != NULL) {
1046                          fclose(expfp);
1047 +                        free((char *)exppos);
1048                          expfp = NULL;
1049                  }
1050                  return(NULL);
1051 <        }
1051 >        } else if (n > vint(END))               /* request past end (error?) */
1052 >                return(NULL);
1053          if (!vdef(EXPOSURE))                    /* no setting (auto) */
1054                  return(NULL);
1055          if (isflt(vval(EXPOSURE)))              /* always the same */
# Line 1054 | Line 1087 | int    n;
1087                  }
1088                  curfrm++;
1089                  cp = fskip(expval);                     /* check format */
1090 <                if (cp == NULL || *cp != '\n') {
1090 >                if (cp != NULL)
1091 >                        while (isspace(*cp))
1092 >                                *cp++ = '\0';
1093 >                if (cp == NULL || *cp) {
1094                          fprintf(stderr,
1095                                  "%s: exposure format error on line %d\n",
1096                                          vval(EXPOSURE), curfrm);
1097                          quit(1);
1098                  }
1063                *cp = '\0';
1099          }
1100          return(expval);                         /* return value */
1101   }
# Line 1090 | Line 1125 | int    pn;
1125   int     status;
1126   {
1127          register PROC   *pp;
1128 +        register struct pslot   *psl;
1129  
1130          pp = ps->proc + pn;
1131          if (pp->elen) {                 /* pass errors */
# Line 1101 | Line 1137 | int    status;
1137                  if (ps->hostname[0])
1138                          status = 1;     /* because rsh doesn't return status */
1139          }
1140 +        lastpserver = NULL;
1141 +        psl = findpslot(pp->pid);       /* check for bruncom() slot */
1142 +        if (psl->pid) {
1143 +                if (status) {
1144 +                        if (psl->rcvf != NULL)  /* attempt recovery */
1145 +                                status = (*psl->rcvf)(psl->fout);
1146 +                        if (status) {
1147 +                                fprintf(stderr,
1148 +                                        "%s: error rendering frame %d\n",
1149 +                                                progname, psl->fout);
1150 +                                quit(1);
1151 +                        }
1152 +                        lastpserver = ps;
1153 +                }
1154 +                psl->pid = 0;                   /* free process slot */
1155 +        } else if (status)
1156 +                lastpserver = ps;
1157          freestr(pp->com);               /* free command string */
1105        lastpid = pp->pid;              /* record PID for bwait() */
1106        lastpserver = ps;               /* record server for serverdown() */
1158          return(status);
1159   }
1160  
# Line 1111 | Line 1162 | int    status;
1162   int
1163   serverdown()                    /* check status of last process server */
1164   {
1165 +        if (lastpserver == NULL || !lastpserver->hostname[0])
1166 +                return(0);
1167          if (pserverOK(lastpserver))     /* server still up? */
1168                  return(0);
1169          delpserver(lastpserver);        /* else delete it */
# Line 1137 | Line 1190 | int    (*rf)();
1190                          printf("\t%s\n", com);  /* echo command */
1191                  return(0);
1192          }
1193 <                                        /* else start it when we can */
1194 <        while ((pid = startjob(NULL, savestr(com), donecom)) == -1)
1193 >        com = savestr(com);             /* else start it when we can */
1194 >        while ((pid = startjob(NULL, com, donecom)) == -1)
1195                  bwait(1);
1196          if (!silent) {                          /* echo command */
1197                  PSERVER *ps;
# Line 1160 | Line 1213 | bwait(ncoms)                           /* wait for batch job(s) to finish */
1213   int     ncoms;
1214   {
1215          int     status;
1163        register struct pslot   *psl;
1216  
1217          if (noaction)
1218                  return;
1219          while ((status = wait4job(NULL, -1)) != -1) {
1220 <                psl = findpslot(lastpid);
1221 <                if (status) {           /* attempt recovery */
1222 <                        serverdown();   /* check server */
1171 <                        if (psl->rcvf == NULL || (*psl->rcvf)(psl->fout)) {
1172 <                                fprintf(stderr,
1173 <                                        "%s: error rendering frame %d\n",
1174 <                                                progname, psl->fout);
1175 <                                quit(1);
1176 <                        }
1177 <                }
1178 <                psl->pid = 0;           /* free process slot */
1179 <                if (!--ncoms)
1180 <                        return;         /* done enough */
1220 >                serverdown();           /* update server status */
1221 >                if (--ncoms == 0)
1222 >                        break;          /* done enough */
1223          }
1224   }
1225  
# Line 1189 | Line 1231 | int    maxcopies;
1231   {
1232          int     retstatus = 0;
1233          int     hostcopies;
1234 <        char    com1buf[10240], *com1, *endcom1;
1234 >        char    buf[10240], *com1, *s;
1235          int     status;
1236 +        int     pfd;
1237 +        register int    n;
1238          register PSERVER        *ps;
1239  
1240          if (!silent)
# Line 1202 | Line 1246 | int    maxcopies;
1246          for (ps = pslist; ps != NULL; ps = ps->next) {
1247                  hostcopies = 0;
1248                  if (maxcopies > 1 && ps->nprocs > 1 && ppins != NULL) {
1249 <                        strcpy(com1=com1buf, com);      /* build -PP command */
1249 >                        strcpy(com1=buf, com);  /* build -PP command */
1250                          sprintf(com1+(ppins-com), " -PP %s/%s.persist",
1251                                          vval(DIRECTORY), phostname(ps));
1252                          strcat(com1, ppins);
1253 <                        endcom1 = com1 + strlen(com1);
1210 <                        sprintf(endcom1, "; kill `sed -n '1s/^[^ ]* //p' %s/%s.persist`",
1211 <                                        vval(DIRECTORY), phostname(ps));
1212 <                } else {
1253 >                } else
1254                          com1 = com;
1255 <                        endcom1 = NULL;
1255 >                while (maxcopies > 0) {
1256 >                        s = savestr(com1);
1257 >                        if (startjob(ps, s, donecom) != -1) {
1258 >                                sleep(20);
1259 >                                hostcopies++;
1260 >                                maxcopies--;
1261 >                        } else {
1262 >                                freestr(s);
1263 >                                break;
1264 >                        }
1265                  }
1216                while (maxcopies > 0 &&
1217                                startjob(ps, savestr(com1), donecom) != -1) {
1218                        sleep(10);
1219                        hostcopies++;
1220                        maxcopies--;
1221                        if (endcom1 != NULL)
1222                                *endcom1 = '\0';
1223                }
1266                  if (!silent && hostcopies) {
1267                          if (hostcopies > 1)
1268                                  printf("\t%d duplicate processes", hostcopies);
# Line 1232 | Line 1274 | int    maxcopies;
1274          }
1275                                          /* wait for jobs to finish */
1276          while ((status = wait4job(NULL, -1)) != -1)
1277 <                if (status)
1278 <                        retstatus += !serverdown();     /* check server */
1277 >                retstatus += status && !serverdown();
1278 >                                        /* terminate parallel rpict's */
1279 >        for (ps = pslist; ps != NULL; ps = ps->next) {
1280 >                sprintf(buf, "%s/%s.persist", vval(DIRECTORY), phostname(ps));
1281 >                if ((pfd = open(buf, O_RDONLY)) >= 0) {
1282 >                        n = read(pfd, buf, sizeof(buf)-1);      /* get PID */
1283 >                        buf[n] = '\0';
1284 >                        close(pfd);
1285 >                        for (n = 0; buf[n] && !isspace(buf[n]); n++)
1286 >                                ;
1287 >                                                                /* terminate */
1288 >                        sprintf(buf, "kill -ALRM %d", atoi(buf+n));
1289 >                        wait4job(ps, startjob(ps, buf, NULL));
1290 >                }
1291 >        }
1292          return(retstatus);
1293   }
1294  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines