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

Comparing ray/src/cv/ies2rad.c (file contents):
Revision 2.12 by greg, Tue Apr 25 21:37:14 1995 UTC vs.
Revision 2.15 by gregl, Fri Jul 25 11:18:18 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 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 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12  
13   #include <stdio.h>
14   #include <math.h>
15 + #include <sys/types.h>
16   #include <ctype.h>
17   #include "color.h"
18   #include "paths.h"
# Line 108 | Line 109 | float  defcolor[3] = {1.,1.,1.};       /* default lamp color
109   float   *lampcolor = defcolor;          /* pointer to current lamp color */
110   double  multiplier = 1.0;               /* multiplier for all light sources */
111   char    units[64] = "meters";           /* output units */
112 + int     out2stdout = 0;                 /* put out to stdout r.t. file */
113   int     instantiate = 0;                /* instantiate geometry */
114   double  illumrad = 0.0;                 /* radius for illum sphere */
115  
# Line 126 | Line 128 | extern char    *strcpy(), *strcat(), *stradd(), *tailtrun
128                  *filename(), *libname(), *fullname(), *malloc(),
129                  *getword(), *atos();
130   extern float    *matchlamp();
131 + extern time_t   fdate();
132  
133   #define scnint(fp,ip)   cvtint(ip,getword(fp))
134   #define scnflt(fp,rp)   cvtflt(rp,getword(fp))
# Line 203 | Line 206 | char   *argv[];
206                  case 'f':               /* lamp data file */
207                          lampdat = argv[++i];
208                          break;
209 <                case 'o':               /* output file name */
209 >                case 'o':               /* output file root name */
210                          outfile = argv[++i];
211                          break;
212 +                case 's':               /* output to stdout */
213 +                        out2stdout = !out2stdout;
214 +                        break;
215                  case 'i':               /* illum */
216                          illumrad = atof(argv[++i]);
217                          break;
# Line 241 | Line 247 | char   *argv[];
247                          exit(ies2rad(NULL, outfile) == 0 ? 0 : 1);
248                  else if (i == argc-1)
249                          exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1);
250 <                else {
251 <                        fprintf(stderr, "%s: single input file required\n",
246 <                                        argv[0]);
247 <                        exit(1);
248 <                }
250 >                else
251 >                        goto needsingle;
252          } else if (i >= argc) {
253                  fprintf(stderr, "%s: missing output file specification\n",
254                                  argv[0]);
255                  exit(1);
256          }
257 +        if (out2stdout && i != argc-1)
258 +                goto needsingle;
259          status = 0;
260          for ( ; i < argc; i++) {
261                  tailtrunc(strcpy(outname,filename(argv[i])));
# Line 258 | Line 263 | char   *argv[];
263                          status = 1;
264          }
265          exit(status);
266 + needsingle:
267 +        fprintf(stderr, "%s: single input file required\n", argv[0]);
268 +        exit(1);
269   }
270  
271  
# Line 464 | Line 472 | char   *inpname, *outname;
472                  perror(inpname);
473                  return(-1);
474          }
475 <        if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) {
475 >        if (out2stdout)
476 >                outfp = stdout;
477 >        else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) {
478                  perror(buf);
479                  fclose(inpfp);
480                  return(-1);
# Line 704 | Line 714 | FILE   *fp;
714   char    *mod, *name;
715   int     dolower, doupper;
716   {
717 +        int     dosides = 0;
718          char    buf[MAXWORD];
719          
720          fprintf(fp, "\n%s %s %s_light\n", mod,
# Line 714 | Line 725 | int    dolower, doupper;
725                          lampcolor[1]/shp->area,
726                          lampcolor[2]/shp->area);
727          if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM)
728 <                if (shp->isillum) {
718 <                        fprintf(fp, "\nvoid illum %s_glow\n", name);
719 <                        fprintf(fp, "0\n0\n3 0 0 0\n");
720 <                } else {
728 >                if (!shp->isillum) {
729                          fprintf(fp, "\n%s glow %s_glow\n", mod, name);
730                          fprintf(fp, "0\n0\n4 %g %g %g -1\n",
731                                          lampcolor[0]/shp->area,
732                                          lampcolor[1]/shp->area,
733                                          lampcolor[2]/shp->area);
734 +                        dosides++;
735                  }
736          switch (shp->type) {
737          case RECT:
# Line 731 | Line 740 | int    dolower, doupper;
740                          putrectsrc(shp, fp, buf, name, 0);
741                  if (doupper)
742                          putrectsrc(shp, fp, buf, name, 1);
743 <                if (doupper && dolower && shp->h > MINDIM) {
743 >                if (dosides) {
744                          strcat(strcpy(buf, name), "_glow");
745                          putsides(shp, fp, buf, name);
746                  }
# Line 742 | Line 751 | int    dolower, doupper;
751                          putdisksrc(shp, fp, buf, name, 0);
752                  if (doupper)
753                          putdisksrc(shp, fp, buf, name, 1);
754 <                if (doupper && dolower && shp->h > MINDIM) {
754 >                if (dosides) {
755                          strcat(strcpy(buf, name), "_glow");
756                          putcyl(shp, fp, buf, name);
757                  }
# Line 1040 | Line 1049 | FILE   *outfp;                 /* close output file upon return */
1049                  strcpy(cp, "| oconv - > ");
1050                  cp += 12;
1051                  fullname(cp,outname,T_OCT);
1052 <                if (system(buf)) {              /* create octree */
1052 >                if (fdate(inpname) > fdate(outname) &&
1053 >                                system(buf)) {          /* create octree */
1054                          fclose(outfp);
1055                          return(-1);
1056                  }
# Line 1054 | Line 1064 | FILE   *outfp;                 /* close output file upon return */
1064                  fprintf(outfp, "0\n0\n");
1065                  fclose(outfp);
1066          } else {                        /* else append to luminaire file */
1057                fclose(outfp);
1067                  if (!FEQ(meters2out, 1.0)) {    /* apply scalefactor */
1068                          sprintf(cp, "| xform -s %f ", meters2out);
1069                          cp += strlen(cp);
1070                  }
1071 <                strcpy(cp, ">> ");              /* append works for DOS? */
1072 <                cp += 3;
1073 <                fullname(cp,outname,T_RAD);
1071 >                if (!out2stdout) {
1072 >                        fclose(outfp);
1073 >                        strcpy(cp, ">> ");      /* append works for DOS? */
1074 >                        cp += 3;
1075 >                        fullname(cp,outname,T_RAD);
1076 >                }
1077                  if (system(buf))
1078                          return(-1);
1079          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines