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.20 by greg, Mon Jun 30 18:18:22 2003 UTC vs.
Revision 2.26 by greg, Wed Jun 22 19:57:17 2011 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14   #include <math.h>
15   #include <sys/types.h>
16   #include <ctype.h>
17 +
18 + #include "rtio.h"
19   #include "color.h"
20   #include "paths.h"
21  
# Line 74 | Line 76 | int    filerev = FIRSTREV;
76                                          /* photometric types */
77   #define PM_C            1
78   #define PM_B            2
79 + #define PM_A            3
80                                          /* unit types */
81   #define U_FEET          1
82   #define U_METERS        2
83                                          /* string lengths */
84   #define MAXLINE         132
85 < #define MAXWORD         76
85 > #define RMAXWORD        76
86                                          /* file types */
87   #define T_RAD           ".rad"
88   #define T_DST           ".dat"
# Line 124 | Line 127 | typedef struct {
127   int     gargc;                          /* global argc (minus filenames) */
128   char    **gargv;                        /* global argv */
129  
127 extern char     *stradd(), *tailtrunc(), *filetrunc(),
128                *filename(), *libname(), *fullnam(), *getword(), *atos();
129 extern float    *matchlamp();
130 extern time_t   fdate();
130  
131   #define scnint(fp,ip)   cvtint(ip,getword(fp))
132   #define scnflt(fp,rp)   cvtflt(rp,getword(fp))
133   #define isint           isflt                   /* IES allows real as integer */
134  
135  
136 < main(argc, argv)
137 < int     argc;
138 < char    *argv[];
136 > static int ies2rad(char *inpname, char *outname);
137 > static void initlamps(void);
138 > static int dosource(SRCINFO *sinf, FILE *in, FILE *out, char *mod, char *name);
139 > static int dotilt(FILE *in, FILE *out, char *dir, char *tltspec,
140 >                char *dfltname, char *tltid);
141 > static int cvgeometry(char *inpname, SRCINFO *sinf, char *outname, FILE *outfp);
142 > static int cvtint(int *ip, char *wrd);
143 > static int cvdata(FILE *in, FILE *out, int ndim, int npts[], double mult,
144 >                double lim[][2]);
145 > static int cvtflt(double *rp, char *wrd);
146 > static int makeshape(SRCINFO *shp, double width, double length, double height);
147 > static int putsource(SRCINFO *shp, FILE *fp, char *mod, char *name,
148 >                int dolower, int doupper, int dosides);
149 > static void putrectsrc(SRCINFO *shp, FILE *fp, char *mod, char *name, int up);
150 > static void putsides(SRCINFO *shp, FILE *fp, char *mod, char *name);
151 > static void putdisksrc(SRCINFO *shp, FILE *fp, char *mod, char *name, int up);
152 > static void putspheresrc(SRCINFO *shp, FILE *fp, char *mod, char *name);
153 > static void putrect(SRCINFO *shp, FILE *fp, char *mod, char *name, char *suffix,
154 >                int a, int b, int c, int d);
155 > static void putpoint(SRCINFO *shp, FILE *fp, int p);
156 > static void putcyl(SRCINFO *shp, FILE *fp, char *mod, char *name);
157 > static char * tailtrunc(char *name);
158 > static char * filename(char *path);
159 > static char * libname(char *path, char *fname, char *suffix);
160 > static char * getword(FILE *fp);
161 > static char * fullnam(char *path, char *fname, char *suffix);
162 >
163 >
164 > int
165 > main(
166 >        int     argc,
167 >        char    *argv[]
168 > )
169   {
170          char    *outfile = NULL;
171          int     status;
172 <        char    outname[MAXWORD];
172 >        char    outname[RMAXWORD];
173          double  d1;
174          int     i;
175          
# Line 267 | Line 296 | needsingle:
296          exit(1);
297   }
298  
299 <
300 < initlamps()                             /* set up lamps */
299 > void
300 > initlamps(void)                         /* set up lamps */
301   {
302          float   *lcol;
303          int     status;
# Line 309 | Line 338 | initlamps()                            /* set up lamps */
338  
339  
340   char *
341 < stradd(dst, src, sep)                   /* add a string at dst */
342 < register char   *dst, *src;
343 < int     sep;
341 > stradd(                 /* add a string at dst */
342 >        register char   *dst,
343 >        register char   *src,
344 >        int     sep
345 > )
346   {
347          if (src && *src) {
348                  do
# Line 326 | Line 357 | int    sep;
357  
358  
359   char *
360 < fullnam(path, fname, suffix)            /* return full path name */
361 < char    *path, *fname, *suffix;
360 > fullnam(                /* return full path name */
361 >        char    *path,
362 >        char    *fname,
363 >        char    *suffix
364 > )
365   {
366          if (prefdir != NULL && abspath(prefdir))
367                  libname(path, fname, suffix);
# Line 341 | Line 375 | char   *path, *fname, *suffix;
375  
376  
377   char *
378 < libname(path, fname, suffix)            /* return library relative name */
379 < char    *path, *fname, *suffix;
378 > libname(                /* return library relative name */
379 >        char    *path,
380 >        char    *fname,
381 >        char    *suffix
382 > )
383   {
384          if (abspath(fname))
385                  strcpy(stradd(path, fname, 0), suffix);
# Line 354 | Line 391 | char   *path, *fname, *suffix;
391  
392  
393   char *
394 < filename(path)                  /* get final component of pathname */
395 < register char   *path;
394 > filename(                       /* get final component of pathname */
395 >        register char   *path
396 > )
397   {
398          register char   *cp;
399  
# Line 367 | Line 405 | register char  *path;
405  
406  
407   char *
408 < filetrunc(path)                         /* truncate filename at end of path */
409 < char    *path;
408 > filetrunc(                              /* truncate filename at end of path */
409 >        char    *path
410 > )
411   {
412          register char   *p1, *p2;
413  
# Line 383 | Line 422 | char   *path;
422  
423  
424   char *
425 < tailtrunc(name)                         /* truncate tail of filename */
426 < char    *name;
425 > tailtrunc(                              /* truncate tail of filename */
426 >        char    *name
427 > )
428   {
429          register char   *p1, *p2;
430  
# Line 400 | Line 440 | char   *name;
440   }
441  
442  
443 < blanktrunc(s)                           /* truncate spaces at end of line */
444 < char    *s;
443 > void
444 > blanktrunc(                             /* truncate spaces at end of line */
445 >        char    *s
446 > )
447   {
448          register char   *cp;
449  
# Line 413 | Line 455 | char   *s;
455   }
456  
457  
458 < k_match(kwd, hdl)                       /* header line matches keyword? */
459 < register char   *kwd, *hdl;
458 > int
459 > k_match(                        /* header line matches keyword? */
460 >        register char   *kwd,
461 >        register char   *hdl
462 > )
463   {
464          if (!*hdl++ == '[')
465                  return(0);
466          while (islower(*hdl) ? toupper(*hdl) == *kwd++ : *hdl == *kwd++)
467                  if (!*hdl++)
468                          return(0);
469 <        return(!*kwd & *hdl == ']');
469 >        return((!*kwd) & (*hdl == ']'));
470   }
471  
472  
473   char *
474 < keyargs(hdl)                            /* return keyword arguments */
475 < register char   *hdl;
474 > keyargs(                                /* return keyword arguments */
475 >        register char   *hdl
476 > )
477   {
478          while (*hdl && *hdl++ != ']')
479                  ;
# Line 437 | Line 483 | register char  *hdl;
483   }
484  
485  
486 < putheader(out)                          /* print header */
487 < FILE    *out;
486 > void
487 > putheader(                              /* print header */
488 >        FILE    *out
489 > )
490   {
491          register int    i;
492          
# Line 453 | Line 501 | FILE   *out;
501   }
502  
503  
504 < ies2rad(inpname, outname)               /* convert IES file */
505 < char    *inpname, *outname;
504 > int
505 > ies2rad(                /* convert IES file */
506 >        char    *inpname,
507 >        char    *outname
508 > )
509   {
510          SRCINFO srcinfo;
511 <        char    buf[MAXLINE], tltid[MAXWORD];
511 >        char    buf[MAXLINE], tltid[RMAXWORD];
512          char    geomfile[128];
513          FILE    *inpfp, *outfp;
514          int     lineno = 0;
# Line 516 | Line 567 | char   *inpname, *outname;
567                  fprintf(stderr, "%s: not in IES format\n", inpname);
568                  goto readerr;
569          }
570 <        atos(tltid, MAXWORD, buf+TLTSTRLEN);
570 >        atos(tltid, RMAXWORD, buf+TLTSTRLEN);
571          if (inpfp == stdin)
572                  buf[0] = '\0';
573          else
# Line 544 | Line 595 | readerr:
595   }
596  
597  
598 < dotilt(in, out, dir, tltspec, dfltname, tltid)  /* convert tilt data */
599 < FILE    *in, *out;
600 < char    *dir, *tltspec, *dfltname, *tltid;
598 > int
599 > dotilt( /* convert tilt data */
600 >        FILE    *in,
601 >        FILE    *out,
602 >        char    *dir,
603 >        char    *tltspec,
604 >        char    *dfltname,
605 >        char    *tltid
606 > )
607   {
608          int     nangles, tlt_type;
609 <        double  minmax[2];
610 <        char    buf[PATH_MAX], tltname[MAXWORD];
609 >        double  minmax[1][2];
610 >        char    buf[PATH_MAX], tltname[RMAXWORD];
611          FILE    *datin, *datout;
612  
613          if (!strcmp(tltspec, TLTNONE)) {
# Line 595 | Line 652 | char   *dir, *tltspec, *dfltname, *tltid;
652                  switch (tlt_type) {
653                  case TLT_VERT:                  /* vertical */
654                          fprintf(out, "4 noop %s tilt.cal %s\n", buf,
655 <                                minmax[1]>90.+FTINY ? "tilt_ang" : "tilt_ang2");
655 >                                minmax[0][1]>90.+FTINY ? "tilt_ang" : "tilt_ang2");
656                          break;
657                  case TLT_H0:                    /* horiz. in 0 deg. plane */
658                          fprintf(out, "6 noop %s tilt.cal %s -rz 90\n", buf,
659 <                        minmax[1]>90.+FTINY ? "tilt_xang" : "tilt_xang2");
659 >                        minmax[0][1]>90.+FTINY ? "tilt_xang" : "tilt_xang2");
660                          break;
661                  case TLT_H90:
662                          fprintf(out, "4 noop %s tilt.cal %s\n", buf,
663 <                        minmax[1]>90.+FTINY ? "tilt_xang" : "tilt_xang2");
663 >                        minmax[0][1]>90.+FTINY ? "tilt_xang" : "tilt_xang2");
664                          break;
665                  default:
666                          fprintf(stderr,
# Line 617 | Line 674 | char   *dir, *tltspec, *dfltname, *tltid;
674   }
675  
676  
677 < dosource(sinf, in, out, mod, name)      /* create source and distribution */
678 < SRCINFO *sinf;
679 < FILE    *in, *out;
680 < char    *mod, *name;
677 > int
678 > dosource(       /* create source and distribution */
679 >        SRCINFO *sinf,
680 >        FILE    *in,
681 >        FILE    *out,
682 >        char    *mod,
683 >        char    *name
684 > )
685   {
686 <        char    buf[PATH_MAX], id[MAXWORD];
686 >        char    buf[PATH_MAX], id[RMAXWORD];
687          FILE    *datout;
688          double  mult, bfactor, pfactor, width, length, height, wattage;
689          double  bounds[2][2];
# Line 639 | Line 700 | char   *mod, *name;
700                  fprintf(stderr, "dosource: bad lamp specification\n");
701                  return(-1);
702          }
703 +        if (pmtype != PM_C && pmtype != PM_B) {
704 +                fprintf(stderr, "dosource: unsupported photometric type (%d)\n",
705 +                                pmtype);
706 +                return(-1);
707 +        }
708          sinf->mult = multiplier*mult*bfactor*pfactor;
709          if (nangles[0] < 2 || nangles[1] < 1) {
710                  fprintf(stderr, "dosource: too few measured angles\n");
# Line 676 | Line 742 | char   *mod, *name;
742                  fprintf(out, "7 ");
743          else
744                  fprintf(out, "5 ");
745 <        dolower = (bounds[0][0] < 90.);
746 <        doupper = (bounds[0][1] > 90.);
745 >        dolower = (bounds[0][0] < 90.-FTINY);
746 >        doupper = (bounds[0][1] > 90.+FTINY);
747          dosides = (doupper & dolower && sinf->h > MINDIM);
748          fprintf(out, "%s %s source.cal ",
749                          sinf->type==SPHERE ? "corr" :
# Line 690 | Line 756 | char   *mod, *name;
756                  else
757                          fprintf(out, "srcB_horiz ");
758                  fprintf(out, "srcB_vert ");
759 <        } else /* pmtype == PM_A */ {
759 >        } else /* pmtype == PM_C */ {
760                  if (nangles[1] >= 2) {
761                          d1 = bounds[1][1] - bounds[1][0];
762                          if (d1 <= 90.+FTINY)
# Line 723 | Line 789 | char   *mod, *name;
789   }
790  
791  
792 < putsource(shp, fp, mod, name, dolower, doupper, dosides) /* put out source */
793 < SRCINFO *shp;
794 < FILE    *fp;
795 < char    *mod, *name;
796 < int     dolower, doupper;
792 > int
793 > putsource( /* put out source */
794 >        SRCINFO *shp,
795 >        FILE    *fp,
796 >        char    *mod,
797 >        char    *name,
798 >        int     dolower,
799 >        int     doupper,
800 >        int dosides
801 > )
802   {
803 <        char    lname[MAXWORD];
803 >        char    lname[RMAXWORD];
804          
805          strcat(strcpy(lname, name), "_light");
806          fprintf(fp, "\n%s %s %s\n", mod,
# Line 761 | Line 832 | int    dolower, doupper;
832   }
833  
834  
835 < makeshape(shp, width, length, height)           /* make source shape */
836 < register SRCINFO        *shp;
837 < double  width, length, height;
835 > int
836 > makeshape(              /* make source shape */
837 >        register SRCINFO        *shp,
838 >        double  width,
839 >        double  length,
840 >        double  height
841 > )
842   {
843          if (illumrad/meters2out >= MINDIM/2.) {
844                  shp->isillum = 1;
# Line 810 | Line 885 | double width, length, height;
885   }
886  
887  
888 < putrectsrc(shp, fp, mod, name, up)              /* rectangular source */
889 < SRCINFO *shp;
890 < FILE    *fp;
891 < char    *mod, *name;
892 < int     up;
888 > void
889 > putrectsrc(             /* rectangular source */
890 >        SRCINFO *shp,
891 >        FILE    *fp,
892 >        char    *mod,
893 >        char    *name,
894 >        int     up
895 > )
896   {
897          if (up)
898                  putrect(shp, fp, mod, name, ".u", 4, 5, 7, 6);
# Line 823 | Line 901 | int    up;
901   }
902  
903  
904 < putsides(shp, fp, mod, name)                    /* put out sides of box */
905 < register SRCINFO        *shp;
906 < FILE    *fp;
907 < char    *mod, *name;
904 > void
905 > putsides(                       /* put out sides of box */
906 >        register SRCINFO        *shp,
907 >        FILE    *fp,
908 >        char    *mod,
909 >        char    *name
910 > )
911   {
912          putrect(shp, fp, mod, name, ".1", 0, 1, 5, 4);
913          putrect(shp, fp, mod, name, ".2", 1, 3, 7, 5);
# Line 835 | Line 916 | char   *mod, *name;
916   }
917          
918  
919 < putrect(shp, fp, mod, name, suffix, a, b, c, d) /* put out a rectangle */
920 < SRCINFO *shp;
921 < FILE    *fp;
922 < char    *mod, *name, *suffix;
923 < int     a, b, c, d;
919 > void
920 > putrect(        /* put out a rectangle */
921 >        SRCINFO *shp,
922 >        FILE    *fp,
923 >        char    *mod,
924 >        char    *name,
925 >        char    *suffix,
926 >        int     a,
927 >        int b,
928 >        int c,
929 >        int d
930 > )
931   {
932          fprintf(fp, "\n%s polygon %s%s\n0\n0\n12\n", mod, name, suffix);
933          putpoint(shp, fp, a);
# Line 849 | Line 937 | int    a, b, c, d;
937   }
938  
939  
940 < putpoint(shp, fp, p)                            /* put out a point */
941 < register SRCINFO        *shp;
942 < FILE    *fp;
943 < int     p;
940 > void
941 > putpoint(                               /* put out a point */
942 >        register SRCINFO        *shp,
943 >        FILE    *fp,
944 >        int     p
945 > )
946   {
947          static double   mult[2] = {-.5, .5};
948  
# Line 863 | Line 953 | int    p;
953   }
954  
955  
956 < putdisksrc(shp, fp, mod, name, up)              /* put out a disk source */
957 < register SRCINFO        *shp;
958 < FILE    *fp;
959 < char    *mod, *name;
960 < int     up;
956 > void
957 > putdisksrc(             /* put out a disk source */
958 >        register SRCINFO        *shp,
959 >        FILE    *fp,
960 >        char    *mod,
961 >        char    *name,
962 >        int     up
963 > )
964   {
965          if (up) {
966                  fprintf(fp, "\n%s ring %s.u\n", mod, name);
# Line 885 | Line 978 | int    up;
978   }
979  
980  
981 < putcyl(shp, fp, mod, name)                      /* put out a cylinder */
982 < register SRCINFO        *shp;
983 < FILE    *fp;
984 < char    *mod, *name;
981 > void
982 > putcyl(                 /* put out a cylinder */
983 >        register SRCINFO        *shp,
984 >        FILE    *fp,
985 >        char    *mod,
986 >        char    *name
987 > )
988   {
989          fprintf(fp, "\n%s cylinder %s.c\n", mod, name);
990          fprintf(fp, "0\n0\n7\n");
# Line 898 | Line 994 | char   *mod, *name;
994   }
995  
996  
997 < putspheresrc(shp, fp, mod, name)                /* put out a sphere source */
998 < SRCINFO *shp;
999 < FILE    *fp;
1000 < char    *mod, *name;
997 > void
998 > putspheresrc(           /* put out a sphere source */
999 >        SRCINFO *shp,
1000 >        FILE    *fp,
1001 >        char    *mod,
1002 >        char    *name
1003 > )
1004   {
1005          fprintf(fp, "\n%s sphere %s.s\n", mod, name);
1006          fprintf(fp, "0\n0\n4 0 0 0 %g\n", .5*shp->w*meters2out);
1007   }
1008  
1009  
1010 < cvdata(in, out, ndim, npts, mult, lim)          /* convert data */
1011 < FILE    *in, *out;
1012 < int     ndim, npts[];
1013 < double  mult, lim[][2];
1010 > int
1011 > cvdata(         /* convert data */
1012 >        FILE    *in,
1013 >        FILE    *out,
1014 >        int     ndim,
1015 >        int     npts[],
1016 >        double  mult,
1017 >        double  lim[][2]
1018 > )
1019   {
1020          double  *pt[4];
1021          register int    i, j;
# Line 971 | Line 1075 | double mult, lim[][2];
1075  
1076  
1077   char *
1078 < getword(fp)                     /* scan a word from fp */
1079 < register FILE   *fp;
1078 > getword(                        /* scan a word from fp */
1079 >        register FILE   *fp
1080 > )
1081   {
1082 <        static char     wrd[MAXWORD];
1082 >        static char     wrd[RMAXWORD];
1083          register char   *cp;
1084          register int    c;
1085  
1086          while (isspace(c=getc(fp)))
1087                  ;
1088 <        for (cp = wrd; c != EOF && cp < wrd+MAXWORD-1;
1088 >        for (cp = wrd; c != EOF && cp < wrd+RMAXWORD-1;
1089                          *cp++ = c, c = getc(fp))
1090                  if (isspace(c) || c == ',') {
1091                          while (isspace(c))
1092                                  c = getc(fp);
1093 <                        if (c != EOF & c != ',')
1093 >                        if ((c != EOF) & (c != ','))
1094                                  ungetc(c, fp);
1095                          *cp = '\0';
1096                          return(wrd);
# Line 995 | Line 1100 | register FILE  *fp;
1100   }
1101  
1102  
1103 < cvtint(ip, wrd)                 /* convert a word to an integer */
1104 < int     *ip;
1105 < char    *wrd;
1103 > int
1104 > cvtint(                 /* convert a word to an integer */
1105 >        int     *ip,
1106 >        char    *wrd
1107 > )
1108   {
1109          if (wrd == NULL || !isint(wrd))
1110                  return(0);
# Line 1006 | Line 1113 | char   *wrd;
1113   }
1114  
1115  
1116 < cvtflt(rp, wrd)                 /* convert a word to a double */
1117 < double  *rp;
1118 < char    *wrd;
1116 > int
1117 > cvtflt(                 /* convert a word to a double */
1118 >        double  *rp,
1119 >        char    *wrd
1120 > )
1121   {
1122          if (wrd == NULL || !isflt(wrd))
1123                  return(0);
# Line 1017 | Line 1126 | char   *wrd;
1126   }
1127  
1128  
1129 < cvgeometry(inpname, sinf, outname, outfp)
1130 < char    *inpname;
1131 < register SRCINFO        *sinf;
1132 < char    *outname;
1133 < FILE    *outfp;                 /* close output file upon return */
1129 > int
1130 > cvgeometry(
1131 >        char    *inpname,
1132 >        register SRCINFO        *sinf,
1133 >        char    *outname,
1134 >        FILE    *outfp                  /* close output file upon return */
1135 > )
1136   {
1137          char    buf[256];
1138          register char   *cp;
# Line 1034 | Line 1145 | FILE   *outfp;                 /* close output file upon return */
1145          strcpy(buf, "mgf2rad ");                /* build mgf2rad command */
1146          cp = buf+8;
1147          if (!FEQ(sinf->mult, 1.0)) {
1148 <                sprintf(cp, "-m %f ", sinf->mult);
1148 >                sprintf(cp, "-e %f ", sinf->mult);
1149                  cp += strlen(cp);
1150          }
1151          sprintf(cp, "-g %f %s ",

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines