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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines