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.19 by schorsch, Mon Jun 30 14:59:11 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Convert IES luminaire data to Radiance description
6   *
7   *      07Apr90         Greg Ward
8 + *
9 + *  Fixed correction factor for flat sources 29Oct2001 GW
10   */
11  
12   #include <stdio.h>
13   #include <math.h>
14 + #include <sys/types.h>
15   #include <ctype.h>
16   #include "color.h"
17   #include "paths.h"
# Line 108 | Line 108 | float  defcolor[3] = {1.,1.,1.};       /* default lamp color
108   float   *lampcolor = defcolor;          /* pointer to current lamp color */
109   double  multiplier = 1.0;               /* multiplier for all light sources */
110   char    units[64] = "meters";           /* output units */
111 + int     out2stdout = 0;                 /* put out to stdout r.t. file */
112   int     instantiate = 0;                /* instantiate geometry */
113   double  illumrad = 0.0;                 /* radius for illum sphere */
114  
# Line 123 | Line 124 | int    gargc;                          /* global argc (minus filenames) */
124   char    **gargv;                        /* global argv */
125  
126   extern char     *strcpy(), *strcat(), *stradd(), *tailtrunc(), *filetrunc(),
127 <                *filename(), *libname(), *fullname(), *malloc(),
127 <                *getword(), *atos();
127 >                *filename(), *libname(), *fullnam(), *getword(), *atos();
128   extern float    *matchlamp();
129 + extern time_t   fdate();
130  
131   #define scnint(fp,ip)   cvtint(ip,getword(fp))
132   #define scnflt(fp,rp)   cvtflt(rp,getword(fp))
# Line 203 | Line 204 | char   *argv[];
204                  case 'f':               /* lamp data file */
205                          lampdat = argv[++i];
206                          break;
207 <                case 'o':               /* output file name */
207 >                case 'o':               /* output file root name */
208                          outfile = argv[++i];
209                          break;
210 +                case 's':               /* output to stdout */
211 +                        out2stdout = !out2stdout;
212 +                        break;
213                  case 'i':               /* illum */
214                          illumrad = atof(argv[++i]);
215                          break;
# Line 241 | Line 245 | char   *argv[];
245                          exit(ies2rad(NULL, outfile) == 0 ? 0 : 1);
246                  else if (i == argc-1)
247                          exit(ies2rad(argv[i], outfile) == 0 ? 0 : 1);
248 <                else {
249 <                        fprintf(stderr, "%s: single input file required\n",
246 <                                        argv[0]);
247 <                        exit(1);
248 <                }
248 >                else
249 >                        goto needsingle;
250          } else if (i >= argc) {
251                  fprintf(stderr, "%s: missing output file specification\n",
252                                  argv[0]);
253                  exit(1);
254          }
255 +        if (out2stdout && i != argc-1)
256 +                goto needsingle;
257          status = 0;
258          for ( ; i < argc; i++) {
259                  tailtrunc(strcpy(outname,filename(argv[i])));
# Line 258 | Line 261 | char   *argv[];
261                          status = 1;
262          }
263          exit(status);
264 + needsingle:
265 +        fprintf(stderr, "%s: single input file required\n", argv[0]);
266 +        exit(1);
267   }
268  
269  
# Line 319 | Line 325 | int    sep;
325  
326  
327   char *
328 < fullname(path, fname, suffix)           /* return full path name */
328 > fullnam(path, fname, suffix)            /* return full path name */
329   char    *path, *fname, *suffix;
330   {
331          if (prefdir != NULL && abspath(prefdir))
# Line 464 | Line 470 | char   *inpname, *outname;
470                  perror(inpname);
471                  return(-1);
472          }
473 <        if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) {
473 >        if (out2stdout)
474 >                outfp = stdout;
475 >        else if ((outfp = fopen(fullnam(buf,outname,T_RAD), "w")) == NULL) {
476                  perror(buf);
477                  fclose(inpfp);
478                  return(-1);
# Line 530 | Line 538 | char   *inpname, *outname;
538   readerr:
539          fclose(inpfp);
540          fclose(outfp);
541 <        unlink(fullname(buf,outname,T_RAD));
541 >        unlink(fullnam(buf,outname,T_RAD));
542          return(-1);
543   }
544  
# Line 541 | Line 549 | char   *dir, *tltspec, *dfltname, *tltid;
549   {
550          int     nangles, tlt_type;
551          double  minmax[2];
552 <        char    buf[MAXPATH], tltname[MAXWORD];
552 >        char    buf[PATH_MAX], tltname[MAXWORD];
553          FILE    *datin, *datout;
554  
555          if (!strcmp(tltspec, TLTNONE)) {
# Line 562 | Line 570 | char   *dir, *tltspec, *dfltname, *tltid;
570                  tailtrunc(strcpy(tltname,filename(tltspec)));
571          }
572          if (datin != NULL) {
573 <                if ((datout = fopen(fullname(buf,tltname,T_TLT),"w")) == NULL) {
573 >                if ((datout = fopen(fullnam(buf,tltname,T_TLT),"w")) == NULL) {
574                          perror(buf);
575                          if (datin != in)
576                                  fclose(datin);
# Line 574 | Line 582 | char   *dir, *tltspec, *dfltname, *tltid;
582                          fclose(datout);
583                          if (datin != in)
584                                  fclose(datin);
585 <                        unlink(fullname(buf,tltname,T_TLT));
585 >                        unlink(fullnam(buf,tltname,T_TLT));
586                          return(-1);
587                  }
588                  fclose(datout);
# Line 613 | Line 621 | SRCINFO        *sinf;
621   FILE    *in, *out;
622   char    *mod, *name;
623   {
624 <        char    buf[MAXPATH], id[MAXWORD];
624 >        char    buf[PATH_MAX], id[MAXWORD];
625          FILE    *datout;
626          double  mult, bfactor, pfactor, width, length, height, wattage;
627          double  bounds[2][2];
628          int     nangles[2], pmtype, unitype;
629          double  d1;
630 +        int     doupper, dolower, dosides;
631  
632          if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult)
633                          || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1])
# Line 643 | Line 652 | char   *mod, *name;
652                  fprintf(stderr, "dosource: illegal source dimensions");
653                  return(-1);
654          }
655 <        if ((datout = fopen(fullname(buf,name,T_DST), "w")) == NULL) {
655 >        if ((datout = fopen(fullnam(buf,name,T_DST), "w")) == NULL) {
656                  perror(buf);
657                  return(-1);
658          }
659          if (cvdata(in, datout, 2, nangles, 1./WHTEFFICACY, bounds) != 0) {
660                  fprintf(stderr, "dosource: bad distribution data\n");
661                  fclose(datout);
662 <                unlink(fullname(buf,name,T_DST));
662 >                unlink(fullnam(buf,name,T_DST));
663                  return(-1);
664          }
665          fclose(datout);
# Line 666 | Line 675 | char   *mod, *name;
675                  fprintf(out, "7 ");
676          else
677                  fprintf(out, "5 ");
678 +        dolower = (bounds[0][0] < 90.);
679 +        doupper = (bounds[0][1] > 90.);
680 +        dosides = (doupper & dolower && sinf->h > MINDIM);
681          fprintf(out, "%s %s source.cal ",
682 <                        sinf->type==SPHERE ? "corr" : "flatcorr",
682 >                        sinf->type==SPHERE ? "corr" :
683 >                        !dosides ? "flatcorr" :
684 >                        sinf->type==DISK ? "cylcorr" : "boxcorr",
685                          libname(buf,name,T_DST));
686          if (pmtype == PM_B) {
687                  if (FEQ(bounds[1][0],0.))
# Line 675 | Line 689 | char   *mod, *name;
689                  else
690                          fprintf(out, "srcB_horiz ");
691                  fprintf(out, "srcB_vert ");
692 <        } else {
692 >        } else /* pmtype == PM_A */ {
693                  if (nangles[1] >= 2) {
694                          d1 = bounds[1][1] - bounds[1][0];
695                          if (d1 <= 90.+FTINY)
696                                  fprintf(out, "src_phi4 ");
697 <                        else if (d1 <= 180.+FTINY)
698 <                                fprintf(out, "src_phi2 ");
699 <                        else
697 >                        else if (d1 <= 180.+FTINY) {
698 >                                if (FEQ(bounds[1][0],90.))
699 >                                        fprintf(out, "src_phi2+90 ");
700 >                                else
701 >                                        fprintf(out, "src_phi2 ");
702 >                        } else
703                                  fprintf(out, "src_phi ");
704                          fprintf(out, "src_theta ");
705                          if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
# Line 690 | Line 707 | char   *mod, *name;
707                  } else
708                          fprintf(out, "src_theta ");
709          }
710 <        fprintf(out, "\n0\n1 %g\n", sinf->mult);
710 >        if (!dosides || sinf->type == SPHERE)
711 >                fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area);
712 >        else if (sinf->type == DISK)
713 >                fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult,
714 >                                sinf->w, sinf->h);
715 >        else
716 >                fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult,
717 >                                sinf->l, sinf->w, sinf->h);
718          if (putsource(sinf, out, id, filename(name),
719 <                        bounds[0][0]<90., bounds[0][1]>90.) != 0)
719 >                        dolower, doupper, dosides) != 0)
720                  return(-1);
721          return(0);
722   }
723  
724  
725 < putsource(shp, fp, mod, name, dolower, doupper)         /* put out source */
725 > putsource(shp, fp, mod, name, dolower, doupper, dosides) /* put out source */
726   SRCINFO *shp;
727   FILE    *fp;
728   char    *mod, *name;
729   int     dolower, doupper;
730   {
731 <        char    buf[MAXWORD];
731 >        char    lname[MAXWORD];
732          
733 <        fprintf(fp, "\n%s %s %s_light\n", mod,
734 <                        shp->isillum ? "illum" : "light",
735 <                        name);
733 >        strcat(strcpy(lname, name), "_light");
734 >        fprintf(fp, "\n%s %s %s\n", mod,
735 >                        shp->isillum ? "illum" : "light", lname);
736          fprintf(fp, "0\n0\n3 %g %g %g\n",
737 <                        lampcolor[0]/shp->area,
714 <                        lampcolor[1]/shp->area,
715 <                        lampcolor[2]/shp->area);
716 <        if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM)
717 <                if (shp->isillum) {
718 <                        fprintf(fp, "\nvoid illum %s_glow\n", name);
719 <                        fprintf(fp, "0\n0\n3 0 0 0\n");
720 <                } else {
721 <                        fprintf(fp, "\n%s glow %s_glow\n", mod, name);
722 <                        fprintf(fp, "0\n0\n4 %g %g %g -1\n",
723 <                                        lampcolor[0]/shp->area,
724 <                                        lampcolor[1]/shp->area,
725 <                                        lampcolor[2]/shp->area);
726 <                }
737 >                        lampcolor[0], lampcolor[1], lampcolor[2]);
738          switch (shp->type) {
739          case RECT:
729                strcat(strcpy(buf, name), "_light");
740                  if (dolower)
741 <                        putrectsrc(shp, fp, buf, name, 0);
741 >                        putrectsrc(shp, fp, lname, name, 0);
742                  if (doupper)
743 <                        putrectsrc(shp, fp, buf, name, 1);
744 <                if (doupper && dolower && shp->h > MINDIM) {
745 <                        strcat(strcpy(buf, name), "_glow");
736 <                        putsides(shp, fp, buf, name);
737 <                }
743 >                        putrectsrc(shp, fp, lname, name, 1);
744 >                if (dosides)
745 >                        putsides(shp, fp, lname, name);
746                  break;
747          case DISK:
740                strcat(strcpy(buf, name), "_light");
748                  if (dolower)
749 <                        putdisksrc(shp, fp, buf, name, 0);
749 >                        putdisksrc(shp, fp, lname, name, 0);
750                  if (doupper)
751 <                        putdisksrc(shp, fp, buf, name, 1);
752 <                if (doupper && dolower && shp->h > MINDIM) {
753 <                        strcat(strcpy(buf, name), "_glow");
747 <                        putcyl(shp, fp, buf, name);
748 <                }
751 >                        putdisksrc(shp, fp, lname, name, 1);
752 >                if (dosides)
753 >                        putcyl(shp, fp, lname, name);
754                  break;
755          case SPHERE:
756 <                strcat(strcpy(buf, name), "_light");
752 <                putspheresrc(shp, fp, buf, name);
756 >                putspheresrc(shp, fp, lname, name);
757                  break;
758          }
759          return(0);
# Line 951 | Line 955 | double mult, lim[][2];
955                                  putc('\n', out);
956                          }
957                  }
958 <                free((char *)pt[i]);
958 >                free((void *)pt[i]);
959          }
960          for (i = 0; i < total; i++) {
961                  if (i%4 == 0)
# Line 969 | Line 973 | char *
973   getword(fp)                     /* scan a word from fp */
974   register FILE   *fp;
975   {
976 <        static char     word[MAXWORD];
976 >        static char     wrd[MAXWORD];
977          register char   *cp;
978          register int    c;
979  
980          while (isspace(c=getc(fp)))
981                  ;
982 <        for (cp = word; c != EOF && cp < word+MAXWORD-1;
982 >        for (cp = wrd; c != EOF && cp < wrd+MAXWORD-1;
983                          *cp++ = c, c = getc(fp))
984                  if (isspace(c) || c == ',') {
985                          while (isspace(c))
# Line 983 | Line 987 | register FILE  *fp;
987                          if (c != EOF & c != ',')
988                                  ungetc(c, fp);
989                          *cp = '\0';
990 <                        return(word);
990 >                        return(wrd);
991                  }
992          *cp = '\0';
993 <        return(cp > word ? word : NULL);
993 >        return(cp > wrd ? wrd : NULL);
994   }
995  
996  
997 < cvtint(ip, word)                /* convert a word to an integer */
997 > cvtint(ip, wrd)                 /* convert a word to an integer */
998   int     *ip;
999 < char    *word;
999 > char    *wrd;
1000   {
1001 <        if (word == NULL || !isint(word))
1001 >        if (wrd == NULL || !isint(wrd))
1002                  return(0);
1003 <        *ip = atoi(word);
1003 >        *ip = atoi(wrd);
1004          return(1);
1005   }
1006  
1007  
1008 < cvtflt(rp, word)                /* convert a word to a double */
1008 > cvtflt(rp, wrd)                 /* convert a word to a double */
1009   double  *rp;
1010 < char    *word;
1010 > char    *wrd;
1011   {
1012 <        if (word == NULL || !isflt(word))
1012 >        if (wrd == NULL || !isflt(wrd))
1013                  return(0);
1014 <        *rp = atof(word);
1014 >        *rp = atof(wrd);
1015          return(1);
1016   }
1017  
# Line 1039 | Line 1043 | FILE   *outfp;                 /* close output file upon return */
1043          if (instantiate) {              /* instantiate octree */
1044                  strcpy(cp, "| oconv - > ");
1045                  cp += 12;
1046 <                fullname(cp,outname,T_OCT);
1047 <                if (system(buf)) {              /* create octree */
1046 >                fullnam(cp,outname,T_OCT);
1047 >                if (fdate(inpname) > fdate(outname) &&
1048 >                                system(buf)) {          /* create octree */
1049                          fclose(outfp);
1050                          return(-1);
1051                  }
# Line 1054 | Line 1059 | FILE   *outfp;                 /* close output file upon return */
1059                  fprintf(outfp, "0\n0\n");
1060                  fclose(outfp);
1061          } else {                        /* else append to luminaire file */
1057                fclose(outfp);
1062                  if (!FEQ(meters2out, 1.0)) {    /* apply scalefactor */
1063                          sprintf(cp, "| xform -s %f ", meters2out);
1064                          cp += strlen(cp);
1065                  }
1066 <                strcpy(cp, ">> ");              /* append works for DOS? */
1067 <                cp += 3;
1068 <                fullname(cp,outname,T_RAD);
1066 >                if (!out2stdout) {
1067 >                        fclose(outfp);
1068 >                        strcpy(cp, ">> ");      /* append works for DOS? */
1069 >                        cp += 3;
1070 >                        fullnam(cp,outname,T_RAD);
1071 >                }
1072                  if (system(buf))
1073                          return(-1);
1074          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines