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.2 by greg, Fri Dec 14 14:41:14 1990 UTC vs.
Revision 2.8 by greg, Fri Jun 4 14:40:25 1993 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1990 Regents of the University of California */
1 > /* Copyright (c) 1992 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 <ctype.h>
16   #include "color.h"
17 + #include "paths.h"
18  
19   #define PI              3.14159265358979323846
20                                          /* floating comparisons */
# Line 35 | Line 37 | static char SCCSid[] = "$SunId$ LBL";
37                                          /* string lengths */
38   #define MAXLINE         132
39   #define MAXWORD         76
38 #define MAXPATH         128
40                                          /* file types */
41   #define T_RAD           ".rad"
42   #define T_DST           ".dat"
# Line 49 | Line 50 | static char SCCSid[] = "$SunId$ LBL";
50  
51   #define F_M             .3048           /* feet to meters */
52  
53 < #define abspath(p)      ((p)[0] == '/' || (p)[0] == '.')
53 > #define abspath(p)      (ISDIRSEP((p)[0]) || (p)[0] == '.')
54  
55   static char     default_name[] = "default";
56  
# Line 64 | Line 65 | float  defcolor[3] = {1.,1.,1.};       /* default lamp color
65   float   *lampcolor = defcolor;          /* pointer to current lamp color */
66   double  multiplier = 1.0;               /* multiplier for all light sources */
67   char    units[64] = "meters";           /* output units */
67 double  minaspect = 0.0;                /* minimum allowed aspect ratio */
68 int     maxemitters = 1;                /* maximum emitters per hemisphere */
68   double  illumrad = 0.0;                 /* radius for illum sphere */
69  
70   typedef struct {
71          int     type;                           /* RECT, DISK, SPHERE */
72          double  w, l, h;                        /* width, length, height */
73 <        double  area;                           /* effective radiating area */
73 >        double  area;                           /* max. projected area */
74   } SHAPE;                                /* a source shape */
75  
76   int     gargc;                          /* global argc (minus filenames) */
77   char    **gargv;                        /* global argv */
78  
79   extern char     *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(),
80 <                *filename(), *libname(), *fullname(), *malloc();
81 < extern double   atof();
80 >                *filename(), *libname(), *fullname(), *malloc(),
81 >                *getword(), *atos();
82   extern float    *matchlamp();
83  
84 + #define scnint(fp,ip)   cvtint(ip,getword(fp))
85 + #define scnflt(fp,rp)   cvtflt(rp,getword(fp))
86 + #define isint           isflt                   /* IES allows real as integer */
87  
88 +
89   main(argc, argv)
90   int     argc;
91   char    *argv[];
# Line 157 | Line 160 | char   *argv[];
160                  case 'o':               /* output file name */
161                          outfile = argv[++i];
162                          break;
160                case 's':               /* square emitters */
161                        minaspect = .6;
162                        if (argv[i][2] == '/') {
163                                maxemitters = atoi(argv[i]+3);
164                                if (maxemitters < 1)
165                                        goto badopt;
166                        }
167                        break;
163                  case 'i':               /* illum */
164                          illumrad = atof(argv[++i]);
165                          if (illumrad < MINDIM)
# Line 285 | Line 280 | char   *path, *fname, *suffix;
280          else if (abspath(fname))
281                  strcpy(stradd(path, fname, 0), suffix);
282          else
283 <                libname(stradd(path, libdir, '/'), fname, suffix);
283 >                libname(stradd(path, libdir, DIRSEP), fname, suffix);
284  
285          return(path);
286   }
# Line 298 | Line 293 | char   *path, *fname, *suffix;
293          if (abspath(fname))
294                  strcpy(stradd(path, fname, 0), suffix);
295          else
296 <                strcpy(stradd(stradd(path, prefdir, '/'), fname, 0), suffix);
296 >                strcpy(stradd(stradd(path, prefdir, DIRSEP), fname, 0), suffix);
297  
298          return(path);
299   }
# Line 311 | Line 306 | register char  *path;
306          register char   *cp;
307  
308          for (cp = path; *path; path++)
309 <                if (*path == '/')
309 >                if (ISDIRSEP(*path))
310                          cp = path+1;
311          return(cp);
312   }
# Line 324 | Line 319 | char   *path;
319          register char   *p1, *p2;
320  
321          for (p1 = p2 = path; *p2; p2++)
322 <                if (*p2 == '/')
322 >                if (ISDIRSEP(*p2))
323                          p1 = p2;
324          *p1 = '\0';
325          return(path);
# Line 418 | Line 413 | char   *inpname, *outname;
413                  fprintf(stderr, "%s: not in IES format\n", inpname);
414                  goto readerr;
415          }
416 <        sscanf(buf+TLTSTRLEN, "%s", tltid);
416 >        atos(tltid, MAXWORD, buf+TLTSTRLEN);
417          if (inpfp == stdin)
418                  buf[0] = '\0';
419          else
# Line 458 | Line 453 | char   *dir, *tltspec, *dfltname, *tltid;
453                  datin = in;
454                  strcpy(tltname, dfltname);
455          } else {
456 <                if (tltspec[0] == '/')
456 >                if (ISDIRSEP(tltspec[0]))
457                          strcpy(buf, tltspec);
458                  else
459 <                        strcpy(stradd(buf, dir, '/'), tltspec);
459 >                        strcpy(stradd(buf, dir, DIRSEP), tltspec);
460                  if ((datin = fopen(buf, "r")) == NULL) {
461                          perror(buf);
462                          return(-1);
# Line 475 | Line 470 | char   *dir, *tltspec, *dfltname, *tltid;
470                                  fclose(datin);
471                          return(-1);
472                  }
473 <                if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2
473 >                if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles)
474                          || cvdata(datin,datout,1,&nangles,1.,minmax) != 0) {
475                          fprintf(stderr, "%s: data format error\n", tltspec);
476                          fclose(datout);
# Line 527 | Line 522 | char   *mod, *name;
522          int     nangles[2], pmtype, unitype;
523          double  d1;
524  
525 <        if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf",
526 <                        &mult, &nangles[0], &nangles[1], &pmtype, &unitype,
527 <                        &width, &length, &height, &bfactor, &pfactor,
528 <                        &wattage) != 11) {
525 >        if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult)
526 >                        || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1])
527 >                        || !scnint(in,&pmtype) || !scnint(in,&unitype)
528 >                        || !scnflt(in,&width) || !scnflt(in,&length)
529 >                        || !scnflt(in,&height) || !scnflt(in,&bfactor)
530 >                        || !scnflt(in,&pfactor) || !scnflt(in,&wattage)) {
531                  fprintf(stderr, "dosource: bad lamp specification\n");
532                  return(-1);
533          }
# Line 551 | Line 548 | char   *mod, *name;
548                  perror(buf);
549                  return(-1);
550          }
551 <        if (cvdata(in, datout, 2, nangles, 1./683., bounds) != 0) {
551 >        if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) {
552                  fprintf(stderr, "dosource: bad distribution data\n");
553                  fclose(datout);
554                  unlink(fullname(buf,name,T_DST));
# Line 567 | Line 564 | char   *mod, *name;
564          else if (pmtype == PM_B)
565                  fprintf(out, "5 ");
566          else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
567 <                fprintf(out, "8 ");
567 >                fprintf(out, "7 ");
568          else
569 <                fprintf(out, "6 ");
569 >                fprintf(out, "5 ");
570          fprintf(out, "%s %s source.cal ",
571                          srcshape.type==SPHERE ? "corr" : "flatcorr",
572                          libname(buf,name,T_DST));
# Line 588 | Line 585 | char   *mod, *name;
585                                  fprintf(out, "src_phi2 ");
586                          else
587                                  fprintf(out, "src_phi ");
588 <                        fprintf(out, "src_theta -my ");
588 >                        fprintf(out, "src_theta ");
589                          if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
590                                  fprintf(out, "-rz -90 ");
591                  } else
# Line 619 | Line 616 | int    dolower, doupper;
616                          lampcolor[2]/shp->area);
617          if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) {
618                  fprintf(fp, "\n%s glow %s_glow\n", mod, name);
619 <                fprintf(fp, "0\n0\n4 %g %g %g 0\n",
619 >                fprintf(fp, "0\n0\n4 %g %g %g -1\n",
620                                  lampcolor[0]/shp->area,
621                                  lampcolor[1]/shp->area,
622                                  lampcolor[2]/shp->area);
# Line 696 | Line 693 | double width, length, height;
693                  shp->area = shp->w * shp->l;
694                  break;
695          case DISK:
696 +        case SPHERE:
697                  shp->area = PI/4. * shp->w * shp->w;
698                  break;
701        case SPHERE:
702                shp->area = PI * shp->w * shp->w;
703                break;
699          }
700          return(0);
701   }
# Line 809 | Line 804 | FILE   *in, *out;
804   int     ndim, npts[];
805   double  mult, lim[][2];
806   {
807 <        register double *pt[4];
807 >        double  *pt[4];
808          register int    i, j;
809          double  val;
810          int     total;
# Line 825 | Line 820 | double mult, lim[][2];
820          for (i = 0; i < ndim; i++) {
821                  pt[i] = (double *)malloc(npts[i]*sizeof(double));
822                  for (j = 0; j < npts[i]; j++)
823 <                        fscanf(in, "%lf", &pt[i][j]);
823 >                        if (!scnflt(in, &pt[i][j]))
824 >                                return(-1);
825                  if (lim != NULL) {
826                          lim[i][0] = pt[i][0];
827                          lim[i][1] = pt[i][npts[i]-1];
# Line 856 | Line 852 | double mult, lim[][2];
852          for (i = 0; i < total; i++) {
853                  if (i%4 == 0)
854                          putc('\n', out);
855 <                if (fscanf(in, "%lf", &val) != 1)
855 >                if (!scnflt(in, &val))
856                          return(-1);
857                  fprintf(out, "\t%g", val*mult);
858          }
859          putc('\n', out);
860          return(0);
861 + }
862 +
863 +
864 + char *
865 + getword(fp)                     /* scan a word from fp */
866 + register FILE   *fp;
867 + {
868 +        static char     word[MAXWORD];
869 +        register char   *cp;
870 +        register int    c;
871 +
872 +        while (isspace(c=getc(fp)))
873 +                ;
874 +        for (cp = word; c != EOF && cp < word+MAXWORD-1;
875 +                        *cp++ = c, c = getc(fp))
876 +                if (isspace(c) || c == ',') {
877 +                        while (isspace(c))
878 +                                c = getc(fp);
879 +                        if (c != EOF & c != ',')
880 +                                ungetc(c, fp);
881 +                        *cp = '\0';
882 +                        return(word);
883 +                }
884 +        *cp = '\0';
885 +        return(cp > word ? word : NULL);
886 + }
887 +
888 +
889 + cvtint(ip, word)                /* convert a word to an integer */
890 + int     *ip;
891 + char    *word;
892 + {
893 +        if (word == NULL || !isint(word))
894 +                return(0);
895 +        *ip = atoi(word);
896 +        return(1);
897 + }
898 +
899 +
900 + cvtflt(rp, word)                /* convert a word to a double */
901 + double  *rp;
902 + char    *word;
903 + {
904 +        if (word == NULL || !isflt(word))
905 +                return(0);
906 +        *rp = atof(word);
907 +        return(1);
908   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines