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 1.1 by greg, Tue Dec 11 08:45:48 1990 UTC vs.
Revision 2.17 by gregl, Mon Nov 10 10:13:58 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 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 11 | Line 11 | static char SCCSid[] = "$SunId$ LBL";
11   */
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"
19  
20   #define PI              3.14159265358979323846
21                                          /* floating comparisons */
22   #define FTINY           1e-6
23   #define FEQ(a,b)        ((a)<=(b)+FTINY&&(a)>=(b)-FTINY)
24 +                                        /* keywords */
25 + #define MAGICID         "IESNA"
26 + #define LMAGICID        5
27 + #define FIRSTREV        86
28 + #define LASTREV         95
29 +
30 + #define D86             0               /* keywords defined in LM-63-1986 */
31 +
32 + #define K_TST           0
33 + #define K_MAN           1
34 + #define K_LMC           2
35 + #define K_LMN           3
36 + #define K_LPC           4
37 + #define K_LMP           5
38 + #define K_BAL           6
39 + #define K_MTC           7
40 + #define K_OTH           8
41 + #define K_SCH           9
42 + #define K_MOR           10
43 + #define K_BLK           11
44 + #define K_EBK           12
45 +
46 + #define D91             ((1L<<13)-1)    /* keywords defined in LM-63-1991 */
47 +
48 + #define K_LMG           13
49 +
50 + #define D95             ((1L<<14)-1)    /* keywords defined in LM-63-1995 */
51 +
52 + char    k_kwd[][20] = {"TEST", "MANUFAC", "LUMCAT", "LUMINAIRE", "LAMPCAT",
53 +                        "LAMP", "BALLAST", "MAINTCAT", "OTHER", "SEARCH",
54 +                        "MORE", "BLOCK", "ENDBLOCK", "LUMINOUSGEOMETRY"};
55 +
56 + long k_defined[] = {D86, D86, D86, D86, D86, D91, D91, D91, D91, D95};
57 +
58 + int     filerev = FIRSTREV;
59 +
60 + #define keymatch(i,s)   (k_defined[filerev-FIRSTREV]&1L<<(i) &&\
61 +                                k_match(k_kwd[i],s))
62 +
63 + #define checklamp(s)    (!(k_defined[filerev-FIRSTREV]&(1<<K_LMP|1<<K_LPC)) ||\
64 +                                keymatch(K_LMP,s) || keymatch(K_LPC,s))
65 +
66                                          /* tilt specs */
67   #define TLTSTR          "TILT="
68   #define TLTSTRLEN       5
# Line 34 | Line 80 | static char SCCSid[] = "$SunId$ LBL";
80                                          /* string lengths */
81   #define MAXLINE         132
82   #define MAXWORD         76
37 #define MAXPATH         128
83                                          /* file types */
84   #define T_RAD           ".rad"
85   #define T_DST           ".dat"
86 < #define T_TLT           "+.dat"
86 > #define T_TLT           "%.dat"
87 > #define T_OCT           ".oct"
88                                          /* shape types */
89   #define RECT            1
90   #define DISK            2
# Line 48 | Line 94 | static char SCCSid[] = "$SunId$ LBL";
94  
95   #define F_M             .3048           /* feet to meters */
96  
97 < #define abspath(p)      ((p)[0] == '/' || (p)[0] == '.')
97 > #define abspath(p)      (ISDIRSEP((p)[0]) || (p)[0] == '.')
98  
99 + static char     default_name[] = "default";
100 +
101   char    *libdir = NULL;                 /* library directory location */
102   char    *prefdir = NULL;                /* subdirectory */
103   char    *lampdat = "lamp.tab";          /* lamp data file */
104  
105   double  meters2out = 1.0;               /* conversion from meters to output */
106   char    *lamptype = NULL;               /* selected lamp type */
107 < float   *lampcolor = NULL;              /* pointer to lamp color */
107 > char    *deflamp = NULL;                /* default lamp type */
108   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 < double  minaspect = 0.0;                /* minimum allowed aspect ratio */
113 < int     maxemitters = 1;                /* maximum emitters per hemisphere */
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  
116   typedef struct {
117 +        int     isillum;                        /* do as illum */
118          int     type;                           /* RECT, DISK, SPHERE */
119 +        double  mult;                           /* candela multiplier */
120          double  w, l, h;                        /* width, length, height */
121 <        double  area;                           /* effective radiating area */
122 < } SHAPE;                                /* a source shape */
121 >        double  area;                           /* max. projected area */
122 > } SRCINFO;                              /* a source shape (units=meters) */
123  
124   int     gargc;                          /* global argc (minus filenames) */
125   char    **gargv;                        /* global argv */
126  
127   extern char     *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(),
128 <                *filename(), *libname(), *fullname(), *malloc();
129 < extern double   atof();
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))
135 + #define isint           isflt                   /* IES allows real as integer */
136  
137 +
138   main(argc, argv)
139   int     argc;
140   char    *argv[];
# Line 150 | 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':               /* square emitters */
213 <                        minaspect = .6;
158 <                        if (argv[i][2] == '/') {
159 <                                maxemitters = atoi(argv[i]+3);
160 <                                if (maxemitters < 1)
161 <                                        goto badopt;
162 <                        }
212 >                case 's':               /* output to stdout */
213 >                        out2stdout = !out2stdout;
214                          break;
215                  case 'i':               /* illum */
216                          illumrad = atof(argv[++i]);
166                        if (illumrad < MINDIM)
167                                illumrad = MINDIM;
217                          break;
218 <                case 't':               /* select lamp type */
218 >                case 'g':               /* instatiate geometry? */
219 >                        instantiate = !instantiate;
220 >                        break;
221 >                case 't':               /* override lamp type */
222                          lamptype = argv[++i];
223                          break;
224 +                case 'u':               /* default lamp type */
225 +                        deflamp = argv[++i];
226 +                        break;
227                  case 'c':               /* default lamp color */
228                          defcolor[0] = atof(argv[++i]);
229                          defcolor[1] = atof(argv[++i]);
# Line 185 | Line 240 | char   *argv[];
240                  }
241          gargc = i;
242          gargv = argv;
243 <                                        /* get lamp data */
189 <        if ((status = loadlamps(lampdat)) < 0)
190 <                exit(1);
191 <        if (status == 0 || (lamptype != NULL &&
192 <                        (lampcolor = matchlamp(lamptype)) == NULL)) {
193 <                lampcolor = defcolor;
194 <                fprintf(stderr, "%s: warning - no lamp data\n", argv[0]);
195 <        }
243 >        initlamps();                    /* get lamp data (if needed) */
244                                          /* convert ies file(s) */
245          if (outfile != NULL) {
246                  if (i == argc)
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",
204 <                                        argv[0]);
205 <                        exit(1);
206 <                }
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 216 | 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  
272 + initlamps()                             /* set up lamps */
273 + {
274 +        float   *lcol;
275 +        int     status;
276 +
277 +        if (lamptype != NULL && !strcmp(lamptype, default_name) &&
278 +                        deflamp == NULL)
279 +                return;                         /* no need for data */
280 +                                                /* else load file */
281 +        if ((status = loadlamps(lampdat)) < 0)
282 +                exit(1);
283 +        if (status == 0) {
284 +                fprintf(stderr, "%s: warning - no lamp data\n", lampdat);
285 +                lamptype = default_name;
286 +                return;
287 +        }
288 +        if (deflamp != NULL) {                  /* match default type */
289 +                if ((lcol = matchlamp(deflamp)) == NULL)
290 +                        fprintf(stderr,
291 +                                "%s: warning - unknown default lamp type\n",
292 +                                        deflamp);
293 +                else
294 +                        copycolor(defcolor, lcol);
295 +        }
296 +        if (lamptype != NULL) {                 /* match selected type */
297 +                if (strcmp(lamptype, default_name)) {
298 +                        if ((lcol = matchlamp(lamptype)) == NULL) {
299 +                                fprintf(stderr,
300 +                                        "%s: warning - unknown lamp type\n",
301 +                                                lamptype);
302 +                                lamptype = default_name;
303 +                        } else
304 +                                copycolor(defcolor, lcol);
305 +                }
306 +                freelamps();                    /* all done with data */
307 +        }
308 +                                                /* else keep lamp data */
309 + }
310 +
311 +
312   char *
313   stradd(dst, src, sep)                   /* add a string at dst */
314   register char   *dst, *src;
# Line 245 | Line 335 | char   *path, *fname, *suffix;
335          else if (abspath(fname))
336                  strcpy(stradd(path, fname, 0), suffix);
337          else
338 <                libname(stradd(path, libdir, '/'), fname, suffix);
338 >                libname(stradd(path, libdir, DIRSEP), fname, suffix);
339  
340          return(path);
341   }
# Line 258 | Line 348 | char   *path, *fname, *suffix;
348          if (abspath(fname))
349                  strcpy(stradd(path, fname, 0), suffix);
350          else
351 <                strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix);
351 >                strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix);
352  
353          return(path);
354   }
# Line 271 | Line 361 | register char  *path;
361          register char   *cp;
362  
363          for (cp = path; *path; path++)
364 <                if (*path == '/')
364 >                if (ISDIRSEP(*path))
365                          cp = path+1;
366          return(cp);
367   }
# Line 284 | Line 374 | char   *path;
374          register char   *p1, *p2;
375  
376          for (p1 = p2 = path; *p2; p2++)
377 <                if (*p2 == '/')
377 >                if (ISDIRSEP(*p2))
378                          p1 = p2;
379 +        if (p1 == path && ISDIRSEP(*p1))
380 +                p1++;
381          *p1 = '\0';
382          return(path);
383   }
# Line 322 | Line 414 | char   *s;
414   }
415  
416  
417 + k_match(kwd, hdl)                       /* header line matches keyword? */
418 + register char   *kwd, *hdl;
419 + {
420 +        if (!*hdl++ == '[')
421 +                return(0);
422 +        while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++)
423 +                if (!*hdl++)
424 +                        return(0);
425 +        return(!*kwd & *hdl == ']');
426 + }
427 +
428 +
429 + char *
430 + keyargs(hdl)                            /* return keyword arguments */
431 + register char   *hdl;
432 + {
433 +        while (*hdl && *hdl++ != ']')
434 +                ;
435 +        while (isspace(*hdl))
436 +                hdl++;
437 +        return(hdl);
438 + }
439 +
440 +
441   putheader(out)                          /* print header */
442   FILE    *out;
443   {
# Line 341 | Line 457 | FILE   *out;
457   ies2rad(inpname, outname)               /* convert IES file */
458   char    *inpname, *outname;
459   {
460 +        SRCINFO srcinfo;
461          char    buf[MAXLINE], tltid[MAXWORD];
462 +        char    geomfile[128];
463          FILE    *inpfp, *outfp;
464 +        int     lineno = 0;
465  
466 +        geomfile[0] = '\0';
467 +        srcinfo.isillum = 0;
468          if (inpname == NULL) {
469                  inpname = "<stdin>";
470                  inpfp = stdin;
# Line 351 | 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 364 | Line 487 | char   *inpname, *outname;
487                  blanktrunc(buf);
488                  if (!buf[0])
489                          continue;
490 +                if (!lineno++ && !strncmp(buf, MAGICID, LMAGICID)) {
491 +                        filerev = atoi(buf+LMAGICID);
492 +                        if (filerev < FIRSTREV)
493 +                                filerev = FIRSTREV;
494 +                        else if (filerev > LASTREV)
495 +                                filerev = LASTREV;
496 +                }
497                  fputs("#<", outfp);
498                  fputs(buf, outfp);
499                  putc('\n', outfp);
500 <                if (lampcolor == NULL)
501 <                        lampcolor = matchlamp(buf);
500 >                if (lampcolor == NULL && checklamp(buf))
501 >                        lampcolor = matchlamp( buf[0] == '[' ?
502 >                                                keyargs(buf) : buf );
503 >                if (keymatch(K_LMG, buf)) {             /* geometry file */
504 >                        strcpy(geomfile, inpname);
505 >                        strcpy(filename(geomfile), keyargs(buf));
506 >                        srcinfo.isillum = 1;
507 >                }
508          }
509          if (lampcolor == NULL) {
510                  fprintf(stderr, "%s: warning - no lamp type\n", inpname);
511 +                fputs("# Unknown lamp type (used default)\n", outfp);
512                  lampcolor = defcolor;
513 <        }
513 >        } else if (lamptype == NULL)
514 >                fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n",
515 >                                lampcolor[3], lampcolor[4], 100.*lampcolor[5]);
516          if (feof(inpfp)) {
517                  fprintf(stderr, "%s: not in IES format\n", inpname);
518                  goto readerr;
519          }
520 <        sscanf(buf+TLTSTRLEN, "%s", tltid);
520 >        atos(tltid, MAXWORD, buf+TLTSTRLEN);
521          if (inpfp == stdin)
522                  buf[0] = '\0';
523          else
# Line 387 | Line 526 | char   *inpname, *outname;
526                  fprintf(stderr, "%s: bad tilt data\n", inpname);
527                  goto readerr;
528          }
529 <        if (dosource(inpfp, outfp, tltid, outname) != 0) {
529 >        if (dosource(&srcinfo, inpfp, outfp, tltid, outname) != 0) {
530                  fprintf(stderr, "%s: bad luminaire data\n", inpname);
531                  goto readerr;
532          }
394        fclose(outfp);
533          fclose(inpfp);
534 +                                        /* cvgeometry closes outfp */
535 +        if (cvgeometry(geomfile, &srcinfo, outname, outfp) != 0) {
536 +                fprintf(stderr, "%s: bad geometry file\n", geomfile);
537 +                return(-1);
538 +        }
539          return(0);
540   readerr:
398        fclose(outfp);
541          fclose(inpfp);
542 +        fclose(outfp);
543          unlink(fullname(buf,outname,T_RAD));
544          return(-1);
545   }
# Line 418 | Line 561 | char   *dir, *tltspec, *dfltname, *tltid;
561                  datin = in;
562                  strcpy(tltname, dfltname);
563          } else {
564 <                if (tltspec[0] == '/')
564 >                if (ISDIRSEP(tltspec[0]))
565                          strcpy(buf, tltspec);
566                  else
567 <                        strcpy(stradd(buf, dir, '/'), tltspec);
567 >                        strcpy(stradd(buf, dir, DIRSEP), tltspec);
568                  if ((datin = fopen(buf, "r")) == NULL) {
569                          perror(buf);
570                          return(-1);
# Line 435 | Line 578 | char   *dir, *tltspec, *dfltname, *tltid;
578                                  fclose(datin);
579                          return(-1);
580                  }
581 <                if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2
581 >                if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles)
582                          || cvdata(datin,datout,1,&nangles,1.,minmax) != 0) {
583                          fprintf(stderr, "%s: data format error\n", tltspec);
584                          fclose(datout);
# Line 475 | Line 618 | char   *dir, *tltspec, *dfltname, *tltid;
618   }
619  
620  
621 < dosource(in, out, mod, name)            /* create source and distribution */
621 > dosource(sinf, in, out, mod, name)      /* create source and distribution */
622 > SRCINFO *sinf;
623   FILE    *in, *out;
624   char    *mod, *name;
625   {
482        SHAPE   srcshape;
626          char    buf[MAXPATH], id[MAXWORD];
627          FILE    *datout;
628          double  mult, bfactor, pfactor, width, length, height, wattage;
# Line 487 | Line 630 | char   *mod, *name;
630          int     nangles[2], pmtype, unitype;
631          double  d1;
632  
633 <        if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf",
634 <                        &mult, &nangles[0], &nangles[1], &pmtype, &unitype,
635 <                        &width, &length, &height, &bfactor, &pfactor,
636 <                        &wattage) != 11) {
633 >        if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult)
634 >                        || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1])
635 >                        || !scnint(in,&pmtype) || !scnint(in,&unitype)
636 >                        || !scnflt(in,&width) || !scnflt(in,&length)
637 >                        || !scnflt(in,&height) || !scnflt(in,&bfactor)
638 >                        || !scnflt(in,&pfactor) || !scnflt(in,&wattage)) {
639                  fprintf(stderr, "dosource: bad lamp specification\n");
640                  return(-1);
641          }
642 +        sinf->mult = multiplier*mult*bfactor*pfactor;
643          if (nangles[0] < 2 || nangles[1] < 1) {
644                  fprintf(stderr, "dosource: too few measured angles\n");
645                  return(-1);
# Line 503 | Line 649 | char   *mod, *name;
649                  length *= F_M;
650                  height *= F_M;
651          }
652 <        if (makeshape(&srcshape, width, length, height) != 0) {
652 >        if (makeshape(sinf, width, length, height) != 0) {
653                  fprintf(stderr, "dosource: illegal source dimensions");
654                  return(-1);
655          }
# Line 511 | Line 657 | char   *mod, *name;
657                  perror(buf);
658                  return(-1);
659          }
660 <        if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) {
660 >        if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) {
661                  fprintf(stderr, "dosource: bad distribution data\n");
662                  fclose(datout);
663                  unlink(fullname(buf,name,T_DST));
# Line 527 | Line 673 | char   *mod, *name;
673          else if (pmtype == PM_B)
674                  fprintf(out, "5 ");
675          else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
676 <                fprintf(out, "8 ");
676 >                fprintf(out, "7 ");
677          else
678 <                fprintf(out, "6 ");
678 >                fprintf(out, "5 ");
679          fprintf(out, "%s %s source.cal ",
680 <                        srcshape.type==SPHERE ? "corr" : "flatcorr",
680 >                        sinf->type==SPHERE ? "corr" :
681 >                        sinf->type==DISK ? "cylcorr" : "boxcorr",
682                          libname(buf,name,T_DST));
683          if (pmtype == PM_B) {
684                  if (FEQ(bounds[1][0],0.))
# Line 548 | Line 695 | char   *mod, *name;
695                                  fprintf(out, "src_phi2 ");
696                          else
697                                  fprintf(out, "src_phi ");
698 <                        fprintf(out, "src_theta -my ");
698 >                        fprintf(out, "src_theta ");
699                          if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
700                                  fprintf(out, "-rz -90 ");
701                  } else
702                          fprintf(out, "src_theta ");
703          }
704 <        fprintf(out, "\n0\n1 %g\n", multiplier*mult*bfactor*pfactor);
705 <        if (putsource(&srcshape, out, id, filename(name),
704 >        if (sinf->type == SPHERE)
705 >                fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area);
706 >        else if (sinf->type == DISK)
707 >                fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult,
708 >                                sinf->l, sinf->h);
709 >        else
710 >                fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult,
711 >                                sinf->l, sinf->w, sinf->h);
712 >        if (putsource(sinf, out, id, filename(name),
713                          bounds[0][0]<90., bounds[0][1]>90.) != 0)
714                  return(-1);
715          return(0);
# Line 563 | Line 717 | char   *mod, *name;
717  
718  
719   putsource(shp, fp, mod, name, dolower, doupper)         /* put out source */
720 < SHAPE   *shp;
720 > SRCINFO *shp;
721   FILE    *fp;
722   char    *mod, *name;
723   int     dolower, doupper;
724   {
725 <        char    buf[MAXWORD];
725 >        int     dosides = doupper && dolower && shp->h > MINDIM;
726 >        char    lname[MAXWORD];
727          
728 <        fprintf(fp, "\n%s %s %s_light\n", mod,
729 <                        illumrad>=MINDIM/2. ? "illum" : "light",
730 <                        name);
728 >        strcat(strcpy(lname, name), "_light");
729 >        fprintf(fp, "\n%s %s %s\n", mod,
730 >                        shp->isillum ? "illum" : "light", lname);
731          fprintf(fp, "0\n0\n3 %g %g %g\n",
732 <                        lampcolor[0]/shp->area,
578 <                        lampcolor[1]/shp->area,
579 <                        lampcolor[2]/shp->area);
580 <        if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) {
581 <                fprintf(fp, "\n%s glow %s_glow\n", mod, name);
582 <                fprintf(fp, "0\n0\n4 %g %g %g 0\n",
583 <                                lampcolor[0]/shp->area,
584 <                                lampcolor[1]/shp->area,
585 <                                lampcolor[2]/shp->area);
586 <        }
732 >                        lampcolor[0], lampcolor[1], lampcolor[2]);
733          switch (shp->type) {
734          case RECT:
589                strcat(strcpy(buf, name), "_light");
735                  if (dolower)
736 <                        putrectsrc(shp, fp, buf, name, 0);
736 >                        putrectsrc(shp, fp, lname, name, 0);
737                  if (doupper)
738 <                        putrectsrc(shp, fp, buf, name, 1);
739 <                if (doupper && dolower && shp->h > MINDIM) {
740 <                        strcat(strcpy(buf, name), "_glow");
596 <                        putsides(shp, fp, buf, name);
597 <                }
738 >                        putrectsrc(shp, fp, lname, name, 1);
739 >                if (dosides)
740 >                        putsides(shp, fp, lname, name);
741                  break;
742          case DISK:
600                strcat(strcpy(buf, name), "_light");
743                  if (dolower)
744 <                        putdisksrc(shp, fp, buf, name, 0);
744 >                        putdisksrc(shp, fp, lname, name, 0);
745                  if (doupper)
746 <                        putdisksrc(shp, fp, buf, name, 1);
747 <                if (doupper && dolower && shp->h > MINDIM) {
748 <                        strcat(strcpy(buf, name), "_glow");
607 <                        putcyl(shp, fp, buf, name);
608 <                }
746 >                        putdisksrc(shp, fp, lname, name, 1);
747 >                if (dosides)
748 >                        putcyl(shp, fp, lname, name);
749                  break;
750          case SPHERE:
751 <                strcat(strcpy(buf, name), "_light");
612 <                putspheresrc(shp, fp, buf, name);
751 >                putspheresrc(shp, fp, lname, name);
752                  break;
753          }
754          return(0);
# Line 617 | Line 756 | int    dolower, doupper;
756  
757  
758   makeshape(shp, width, length, height)           /* make source shape */
759 < register SHAPE  *shp;
759 > register SRCINFO        *shp;
760   double  width, length, height;
761   {
762 <        if (illumrad >= MINDIM/2.) {
762 >        if (illumrad/meters2out >= MINDIM/2.) {
763 >                shp->isillum = 1;
764                  shp->type = SPHERE;
765 <                shp->w = shp->l = shp->h = 2.*illumrad;
765 >                shp->w = shp->l = shp->h = 2.*illumrad / meters2out;
766          } else if (width < MINDIM) {
767                  width = -width;
768                  if (width < MINDIM) {
# Line 656 | Line 796 | double width, length, height;
796                  shp->area = shp->w * shp->l;
797                  break;
798          case DISK:
799 +        case SPHERE:
800                  shp->area = PI/4. * shp->w * shp->w;
801                  break;
661        case SPHERE:
662                shp->area = PI * shp->w * shp->w;
663                break;
802          }
803          return(0);
804   }
805  
806  
807   putrectsrc(shp, fp, mod, name, up)              /* rectangular source */
808 < SHAPE   *shp;
808 > SRCINFO *shp;
809   FILE    *fp;
810   char    *mod, *name;
811   int     up;
# Line 680 | Line 818 | int    up;
818  
819  
820   putsides(shp, fp, mod, name)                    /* put out sides of box */
821 < register SHAPE  *shp;
821 > register SRCINFO        *shp;
822   FILE    *fp;
823   char    *mod, *name;
824   {
# Line 692 | Line 830 | char   *mod, *name;
830          
831  
832   putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */
833 < SHAPE   *shp;
833 > SRCINFO *shp;
834   FILE    *fp;
835   char    *mod, *name, *suffix;
836   int     a, b, c, d;
# Line 706 | Line 844 | int    a, b, c, d;
844  
845  
846   putpoint(shp, fp, p)                            /* put out a point */
847 < register SHAPE  *shp;
847 > register SRCINFO        *shp;
848   FILE    *fp;
849   int     p;
850   {
# Line 720 | Line 858 | int    p;
858  
859  
860   putdisksrc(shp, fp, mod, name, up)              /* put out a disk source */
861 < register SHAPE  *shp;
861 > register SRCINFO        *shp;
862   FILE    *fp;
863   char    *mod, *name;
864   int     up;
# Line 742 | Line 880 | int    up;
880  
881  
882   putcyl(shp, fp, mod, name)                      /* put out a cylinder */
883 < register SHAPE  *shp;
883 > register SRCINFO        *shp;
884   FILE    *fp;
885   char    *mod, *name;
886   {
# Line 755 | Line 893 | char   *mod, *name;
893  
894  
895   putspheresrc(shp, fp, mod, name)                /* put out a sphere source */
896 < SHAPE   *shp;
896 > SRCINFO *shp;
897   FILE    *fp;
898   char    *mod, *name;
899   {
# Line 769 | Line 907 | FILE   *in, *out;
907   int     ndim, npts[];
908   double  mult, lim[][2];
909   {
910 <        register double *pt[4];
910 >        double  *pt[4];
911          register int    i, j;
912          double  val;
913          int     total;
# Line 785 | Line 923 | double mult, lim[][2];
923          for (i = 0; i < ndim; i++) {
924                  pt[i] = (double *)malloc(npts[i]*sizeof(double));
925                  for (j = 0; j < npts[i]; j++)
926 <                        fscanf(in, "%lf", &pt[i][j]);
926 >                        if (!scnflt(in, &pt[i][j]))
927 >                                return(-1);
928                  if (lim != NULL) {
929                          lim[i][0] = pt[i][0];
930                          lim[i][1] = pt[i][npts[i]-1];
# Line 816 | Line 955 | double mult, lim[][2];
955          for (i = 0; i < total; i++) {
956                  if (i%4 == 0)
957                          putc('\n', out);
958 <                if (fscanf(in, "%lf", &val) != 1)
958 >                if (!scnflt(in, &val))
959                          return(-1);
960                  fprintf(out, "\t%g", val*mult);
961          }
962          putc('\n', out);
963 +        return(0);
964 + }
965 +
966 +
967 + char *
968 + getword(fp)                     /* scan a word from fp */
969 + register FILE   *fp;
970 + {
971 +        static char     wrd[MAXWORD];
972 +        register char   *cp;
973 +        register int    c;
974 +
975 +        while (isspace(c=getc(fp)))
976 +                ;
977 +        for (cp = wrd; c != EOF && cp < wrd+MAXWORD-1;
978 +                        *cp++ = c, c = getc(fp))
979 +                if (isspace(c) || c == ',') {
980 +                        while (isspace(c))
981 +                                c = getc(fp);
982 +                        if (c != EOF & c != ',')
983 +                                ungetc(c, fp);
984 +                        *cp = '\0';
985 +                        return(wrd);
986 +                }
987 +        *cp = '\0';
988 +        return(cp > wrd ? wrd : NULL);
989 + }
990 +
991 +
992 + cvtint(ip, wrd)                 /* convert a word to an integer */
993 + int     *ip;
994 + char    *wrd;
995 + {
996 +        if (wrd == NULL || !isint(wrd))
997 +                return(0);
998 +        *ip = atoi(wrd);
999 +        return(1);
1000 + }
1001 +
1002 +
1003 + cvtflt(rp, wrd)                 /* convert a word to a double */
1004 + double  *rp;
1005 + char    *wrd;
1006 + {
1007 +        if (wrd == NULL || !isflt(wrd))
1008 +                return(0);
1009 +        *rp = atof(wrd);
1010 +        return(1);
1011 + }
1012 +
1013 +
1014 + cvgeometry(inpname, sinf, outname, outfp)
1015 + char    *inpname;
1016 + register SRCINFO        *sinf;
1017 + char    *outname;
1018 + FILE    *outfp;                 /* close output file upon return */
1019 + {
1020 +        char    buf[256];
1021 +        register char   *cp;
1022 +
1023 +        if (inpname == NULL || !inpname[0]) {   /* no geometry file */
1024 +                fclose(outfp);
1025 +                return(0);
1026 +        }
1027 +        putc('\n', outfp);
1028 +        strcpy(buf, "mgf2rad ");                /* build mgf2rad command */
1029 +        cp = buf+8;
1030 +        if (!FEQ(sinf->mult, 1.0)) {
1031 +                sprintf(cp, "-m %f ", sinf->mult);
1032 +                cp += strlen(cp);
1033 +        }
1034 +        sprintf(cp, "-g %f %s ",
1035 +                sqrt(sinf->w*sinf->w + sinf->h*sinf->h + sinf->l*sinf->l),
1036 +                        inpname);
1037 +        cp += strlen(cp);
1038 +        if (instantiate) {              /* instantiate octree */
1039 +                strcpy(cp, "| oconv - > ");
1040 +                cp += 12;
1041 +                fullname(cp,outname,T_OCT);
1042 +                if (fdate(inpname) > fdate(outname) &&
1043 +                                system(buf)) {          /* create octree */
1044 +                        fclose(outfp);
1045 +                        return(-1);
1046 +                }
1047 +                fprintf(outfp, "void instance %s_inst\n", outname);
1048 +                if (!FEQ(meters2out, 1.0))
1049 +                        fprintf(outfp, "3 %s -s %f\n",
1050 +                                        libname(buf,outname,T_OCT),
1051 +                                        meters2out);
1052 +                else
1053 +                        fprintf(outfp, "1 %s\n", libname(buf,outname,T_OCT));
1054 +                fprintf(outfp, "0\n0\n");
1055 +                fclose(outfp);
1056 +        } else {                        /* else append to luminaire file */
1057 +                if (!FEQ(meters2out, 1.0)) {    /* apply scalefactor */
1058 +                        sprintf(cp, "| xform -s %f ", meters2out);
1059 +                        cp += strlen(cp);
1060 +                }
1061 +                if (!out2stdout) {
1062 +                        fclose(outfp);
1063 +                        strcpy(cp, ">> ");      /* append works for DOS? */
1064 +                        cp += 3;
1065 +                        fullname(cp,outname,T_RAD);
1066 +                }
1067 +                if (system(buf))
1068 +                        return(-1);
1069 +        }
1070          return(0);
1071   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines