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.15 by gregl, Fri Jul 25 11:18:18 1997 UTC vs.
Revision 2.21 by schorsch, Thu Jul 3 22:41:44 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 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 <string.h>
14   #include <math.h>
15   #include <sys/types.h>
16   #include <ctype.h>
# Line 79 | Line 79 | int    filerev = FIRSTREV;
79   #define U_METERS        2
80                                          /* string lengths */
81   #define MAXLINE         132
82 < #define MAXWORD         76
82 > #define RMAXWORD        76
83                                          /* file types */
84   #define T_RAD           ".rad"
85   #define T_DST           ".dat"
# Line 124 | Line 124 | typedef struct {
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 <                *getword(), *atos();
127 > extern char     *stradd(), *tailtrunc(), *filetrunc(),
128 >                *filename(), *libname(), *fullnam(), *getword(), *atos();
129   extern float    *matchlamp();
130   extern time_t   fdate();
131  
# Line 141 | Line 140 | char   *argv[];
140   {
141          char    *outfile = NULL;
142          int     status;
143 <        char    outname[MAXWORD];
143 >        char    outname[RMAXWORD];
144          double  d1;
145          int     i;
146          
# Line 327 | Line 326 | int    sep;
326  
327  
328   char *
329 < fullname(path, fname, suffix)           /* return full path name */
329 > fullnam(path, fname, suffix)            /* return full path name */
330   char    *path, *fname, *suffix;
331   {
332          if (prefdir != NULL && abspath(prefdir))
# Line 458 | Line 457 | ies2rad(inpname, outname)              /* convert IES file */
457   char    *inpname, *outname;
458   {
459          SRCINFO srcinfo;
460 <        char    buf[MAXLINE], tltid[MAXWORD];
460 >        char    buf[MAXLINE], tltid[RMAXWORD];
461          char    geomfile[128];
462          FILE    *inpfp, *outfp;
463          int     lineno = 0;
# Line 474 | Line 473 | char   *inpname, *outname;
473          }
474          if (out2stdout)
475                  outfp = stdout;
476 <        else if ((outfp = fopen(fullname(buf,outname,T_RAD), "w")) == NULL) {
476 >        else if ((outfp = fopen(fullnam(buf,outname,T_RAD), "w")) == NULL) {
477                  perror(buf);
478                  fclose(inpfp);
479                  return(-1);
# Line 517 | Line 516 | char   *inpname, *outname;
516                  fprintf(stderr, "%s: not in IES format\n", inpname);
517                  goto readerr;
518          }
519 <        atos(tltid, MAXWORD, buf+TLTSTRLEN);
519 >        atos(tltid, RMAXWORD, buf+TLTSTRLEN);
520          if (inpfp == stdin)
521                  buf[0] = '\0';
522          else
# Line 540 | Line 539 | char   *inpname, *outname;
539   readerr:
540          fclose(inpfp);
541          fclose(outfp);
542 <        unlink(fullname(buf,outname,T_RAD));
542 >        unlink(fullnam(buf,outname,T_RAD));
543          return(-1);
544   }
545  
# Line 551 | Line 550 | char   *dir, *tltspec, *dfltname, *tltid;
550   {
551          int     nangles, tlt_type;
552          double  minmax[2];
553 <        char    buf[MAXPATH], tltname[MAXWORD];
553 >        char    buf[PATH_MAX], tltname[RMAXWORD];
554          FILE    *datin, *datout;
555  
556          if (!strcmp(tltspec, TLTNONE)) {
# Line 572 | Line 571 | char   *dir, *tltspec, *dfltname, *tltid;
571                  tailtrunc(strcpy(tltname,filename(tltspec)));
572          }
573          if (datin != NULL) {
574 <                if ((datout = fopen(fullname(buf,tltname,T_TLT),"w")) == NULL) {
574 >                if ((datout = fopen(fullnam(buf,tltname,T_TLT),"w")) == NULL) {
575                          perror(buf);
576                          if (datin != in)
577                                  fclose(datin);
# Line 584 | Line 583 | char   *dir, *tltspec, *dfltname, *tltid;
583                          fclose(datout);
584                          if (datin != in)
585                                  fclose(datin);
586 <                        unlink(fullname(buf,tltname,T_TLT));
586 >                        unlink(fullnam(buf,tltname,T_TLT));
587                          return(-1);
588                  }
589                  fclose(datout);
# Line 623 | Line 622 | SRCINFO        *sinf;
622   FILE    *in, *out;
623   char    *mod, *name;
624   {
625 <        char    buf[MAXPATH], id[MAXWORD];
625 >        char    buf[PATH_MAX], id[RMAXWORD];
626          FILE    *datout;
627          double  mult, bfactor, pfactor, width, length, height, wattage;
628          double  bounds[2][2];
629          int     nangles[2], pmtype, unitype;
630          double  d1;
631 +        int     doupper, dolower, dosides;
632  
633          if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult)
634                          || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1])
# Line 653 | Line 653 | char   *mod, *name;
653                  fprintf(stderr, "dosource: illegal source dimensions");
654                  return(-1);
655          }
656 <        if ((datout = fopen(fullname(buf,name,T_DST), "w")) == NULL) {
656 >        if ((datout = fopen(fullnam(buf,name,T_DST), "w")) == NULL) {
657                  perror(buf);
658                  return(-1);
659          }
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));
663 >                unlink(fullnam(buf,name,T_DST));
664                  return(-1);
665          }
666          fclose(datout);
# Line 676 | Line 676 | char   *mod, *name;
676                  fprintf(out, "7 ");
677          else
678                  fprintf(out, "5 ");
679 +        dolower = (bounds[0][0] < 90.);
680 +        doupper = (bounds[0][1] > 90.);
681 +        dosides = (doupper & dolower && sinf->h > MINDIM);
682          fprintf(out, "%s %s source.cal ",
683 <                        sinf->type==SPHERE ? "corr" : "flatcorr",
683 >                        sinf->type==SPHERE ? "corr" :
684 >                        !dosides ? "flatcorr" :
685 >                        sinf->type==DISK ? "cylcorr" : "boxcorr",
686                          libname(buf,name,T_DST));
687          if (pmtype == PM_B) {
688                  if (FEQ(bounds[1][0],0.))
# Line 685 | Line 690 | char   *mod, *name;
690                  else
691                          fprintf(out, "srcB_horiz ");
692                  fprintf(out, "srcB_vert ");
693 <        } else {
693 >        } else /* pmtype == PM_A */ {
694                  if (nangles[1] >= 2) {
695                          d1 = bounds[1][1] - bounds[1][0];
696                          if (d1 <= 90.+FTINY)
697                                  fprintf(out, "src_phi4 ");
698 <                        else if (d1 <= 180.+FTINY)
699 <                                fprintf(out, "src_phi2 ");
700 <                        else
698 >                        else if (d1 <= 180.+FTINY) {
699 >                                if (FEQ(bounds[1][0],90.))
700 >                                        fprintf(out, "src_phi2+90 ");
701 >                                else
702 >                                        fprintf(out, "src_phi2 ");
703 >                        } else
704                                  fprintf(out, "src_phi ");
705                          fprintf(out, "src_theta ");
706                          if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
# Line 700 | Line 708 | char   *mod, *name;
708                  } else
709                          fprintf(out, "src_theta ");
710          }
711 <        fprintf(out, "\n0\n1 %g\n", sinf->mult);
711 >        if (!dosides || sinf->type == SPHERE)
712 >                fprintf(out, "\n0\n1 %g\n", sinf->mult/sinf->area);
713 >        else if (sinf->type == DISK)
714 >                fprintf(out, "\n0\n3 %g %g %g\n", sinf->mult,
715 >                                sinf->w, sinf->h);
716 >        else
717 >                fprintf(out, "\n0\n4 %g %g %g %g\n", sinf->mult,
718 >                                sinf->l, sinf->w, sinf->h);
719          if (putsource(sinf, out, id, filename(name),
720 <                        bounds[0][0]<90., bounds[0][1]>90.) != 0)
720 >                        dolower, doupper, dosides) != 0)
721                  return(-1);
722          return(0);
723   }
724  
725  
726 < putsource(shp, fp, mod, name, dolower, doupper)         /* put out source */
726 > putsource(shp, fp, mod, name, dolower, doupper, dosides) /* put out source */
727   SRCINFO *shp;
728   FILE    *fp;
729   char    *mod, *name;
730   int     dolower, doupper;
731   {
732 <        int     dosides = 0;
718 <        char    buf[MAXWORD];
732 >        char    lname[RMAXWORD];
733          
734 <        fprintf(fp, "\n%s %s %s_light\n", mod,
735 <                        shp->isillum ? "illum" : "light",
736 <                        name);
734 >        strcat(strcpy(lname, name), "_light");
735 >        fprintf(fp, "\n%s %s %s\n", mod,
736 >                        shp->isillum ? "illum" : "light", lname);
737          fprintf(fp, "0\n0\n3 %g %g %g\n",
738 <                        lampcolor[0]/shp->area,
725 <                        lampcolor[1]/shp->area,
726 <                        lampcolor[2]/shp->area);
727 <        if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM)
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 <                }
738 >                        lampcolor[0], lampcolor[1], lampcolor[2]);
739          switch (shp->type) {
740          case RECT:
738                strcat(strcpy(buf, name), "_light");
741                  if (dolower)
742 <                        putrectsrc(shp, fp, buf, name, 0);
742 >                        putrectsrc(shp, fp, lname, name, 0);
743                  if (doupper)
744 <                        putrectsrc(shp, fp, buf, name, 1);
745 <                if (dosides) {
746 <                        strcat(strcpy(buf, name), "_glow");
745 <                        putsides(shp, fp, buf, name);
746 <                }
744 >                        putrectsrc(shp, fp, lname, name, 1);
745 >                if (dosides)
746 >                        putsides(shp, fp, lname, name);
747                  break;
748          case DISK:
749                strcat(strcpy(buf, name), "_light");
749                  if (dolower)
750 <                        putdisksrc(shp, fp, buf, name, 0);
750 >                        putdisksrc(shp, fp, lname, name, 0);
751                  if (doupper)
752 <                        putdisksrc(shp, fp, buf, name, 1);
753 <                if (dosides) {
754 <                        strcat(strcpy(buf, name), "_glow");
756 <                        putcyl(shp, fp, buf, name);
757 <                }
752 >                        putdisksrc(shp, fp, lname, name, 1);
753 >                if (dosides)
754 >                        putcyl(shp, fp, lname, name);
755                  break;
756          case SPHERE:
757 <                strcat(strcpy(buf, name), "_light");
761 <                putspheresrc(shp, fp, buf, name);
757 >                putspheresrc(shp, fp, lname, name);
758                  break;
759          }
760          return(0);
# Line 960 | Line 956 | double mult, lim[][2];
956                                  putc('\n', out);
957                          }
958                  }
959 <                free((char *)pt[i]);
959 >                free((void *)pt[i]);
960          }
961          for (i = 0; i < total; i++) {
962                  if (i%4 == 0)
# Line 978 | Line 974 | char *
974   getword(fp)                     /* scan a word from fp */
975   register FILE   *fp;
976   {
977 <        static char     word[MAXWORD];
977 >        static char     wrd[RMAXWORD];
978          register char   *cp;
979          register int    c;
980  
981          while (isspace(c=getc(fp)))
982                  ;
983 <        for (cp = word; c != EOF && cp < word+MAXWORD-1;
983 >        for (cp = wrd; c != EOF && cp < wrd+RMAXWORD-1;
984                          *cp++ = c, c = getc(fp))
985                  if (isspace(c) || c == ',') {
986                          while (isspace(c))
# Line 992 | Line 988 | register FILE  *fp;
988                          if (c != EOF & c != ',')
989                                  ungetc(c, fp);
990                          *cp = '\0';
991 <                        return(word);
991 >                        return(wrd);
992                  }
993          *cp = '\0';
994 <        return(cp > word ? word : NULL);
994 >        return(cp > wrd ? wrd : NULL);
995   }
996  
997  
998 < cvtint(ip, word)                /* convert a word to an integer */
998 > cvtint(ip, wrd)                 /* convert a word to an integer */
999   int     *ip;
1000 < char    *word;
1000 > char    *wrd;
1001   {
1002 <        if (word == NULL || !isint(word))
1002 >        if (wrd == NULL || !isint(wrd))
1003                  return(0);
1004 <        *ip = atoi(word);
1004 >        *ip = atoi(wrd);
1005          return(1);
1006   }
1007  
1008  
1009 < cvtflt(rp, word)                /* convert a word to a double */
1009 > cvtflt(rp, wrd)                 /* convert a word to a double */
1010   double  *rp;
1011 < char    *word;
1011 > char    *wrd;
1012   {
1013 <        if (word == NULL || !isflt(word))
1013 >        if (wrd == NULL || !isflt(wrd))
1014                  return(0);
1015 <        *rp = atof(word);
1015 >        *rp = atof(wrd);
1016          return(1);
1017   }
1018  
# Line 1048 | Line 1044 | FILE   *outfp;                 /* close output file upon return */
1044          if (instantiate) {              /* instantiate octree */
1045                  strcpy(cp, "| oconv - > ");
1046                  cp += 12;
1047 <                fullname(cp,outname,T_OCT);
1047 >                fullnam(cp,outname,T_OCT);
1048                  if (fdate(inpname) > fdate(outname) &&
1049                                  system(buf)) {          /* create octree */
1050                          fclose(outfp);
# Line 1072 | Line 1068 | FILE   *outfp;                 /* close output file upon return */
1068                          fclose(outfp);
1069                          strcpy(cp, ">> ");      /* append works for DOS? */
1070                          cp += 3;
1071 <                        fullname(cp,outname,T_RAD);
1071 >                        fullnam(cp,outname,T_RAD);
1072                  }
1073                  if (system(buf))
1074                          return(-1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines