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.4 by greg, Tue Sep 8 10:06:29 1992 UTC vs.
Revision 2.10 by greg, Thu Dec 16 10:01:30 1993 UTC

# 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"
# Line 39 | Line 40 | static char SCCSid[] = "$SunId$ LBL";
40                                          /* file types */
41   #define T_RAD           ".rad"
42   #define T_DST           ".dat"
43 < #define T_TLT           "+.dat"
43 > #define T_TLT           "%.dat"
44                                          /* shape types */
45   #define RECT            1
46   #define DISK            2
# Line 76 | Line 77 | 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();
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 401 | Line 407 | char   *inpname, *outname;
407          }
408          if (lampcolor == NULL) {
409                  fprintf(stderr, "%s: warning - no lamp type\n", inpname);
410 +                fputs("# Unknown lamp type (used default)\n", outfp);
411                  lampcolor = defcolor;
412 <        }
412 >        } else if (lamptype == NULL)
413 >                fprintf(outfp,"# CIE(x,y) = (%f,%f)\n# Depreciation = %.1f%%\n",
414 >                                lampcolor[3], lampcolor[4], 100.*lampcolor[5]);
415          if (feof(inpfp)) {
416                  fprintf(stderr, "%s: not in IES format\n", inpname);
417                  goto readerr;
418          }
419 <        sscanf(buf+TLTSTRLEN, "%s", tltid);
419 >        atos(tltid, MAXWORD, buf+TLTSTRLEN);
420          if (inpfp == stdin)
421                  buf[0] = '\0';
422          else
# Line 464 | Line 473 | char   *dir, *tltspec, *dfltname, *tltid;
473                                  fclose(datin);
474                          return(-1);
475                  }
476 <                if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2
476 >                if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles)
477                          || cvdata(datin,datout,1,&nangles,1.,minmax) != 0) {
478                          fprintf(stderr, "%s: data format error\n", tltspec);
479                          fclose(datout);
# Line 516 | Line 525 | char   *mod, *name;
525          int     nangles[2], pmtype, unitype;
526          double  d1;
527  
528 <        if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf",
529 <                        &mult, &nangles[0], &nangles[1], &pmtype, &unitype,
530 <                        &width, &length, &height, &bfactor, &pfactor,
531 <                        &wattage) != 11) {
528 >        if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult)
529 >                        || !scnint(in,&nangles[0]) || !scnint(in,&nangles[1])
530 >                        || !scnint(in,&pmtype) || !scnint(in,&unitype)
531 >                        || !scnflt(in,&width) || !scnflt(in,&length)
532 >                        || !scnflt(in,&height) || !scnflt(in,&bfactor)
533 >                        || !scnflt(in,&pfactor) || !scnflt(in,&wattage)) {
534                  fprintf(stderr, "dosource: bad lamp specification\n");
535                  return(-1);
536          }
# Line 556 | Line 567 | char   *mod, *name;
567          else if (pmtype == PM_B)
568                  fprintf(out, "5 ");
569          else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
570 <                fprintf(out, "8 ");
570 >                fprintf(out, "7 ");
571          else
572 <                fprintf(out, "6 ");
572 >                fprintf(out, "5 ");
573          fprintf(out, "%s %s source.cal ",
574                          srcshape.type==SPHERE ? "corr" : "flatcorr",
575                          libname(buf,name,T_DST));
# Line 577 | Line 588 | char   *mod, *name;
588                                  fprintf(out, "src_phi2 ");
589                          else
590                                  fprintf(out, "src_phi ");
591 <                        fprintf(out, "src_theta -my ");
591 >                        fprintf(out, "src_theta ");
592                          if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.))
593                                  fprintf(out, "-rz -90 ");
594                  } else
# Line 608 | Line 619 | int    dolower, doupper;
619                          lampcolor[2]/shp->area);
620          if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) {
621                  fprintf(fp, "\n%s glow %s_glow\n", mod, name);
622 <                fprintf(fp, "0\n0\n4 %g %g %g 0\n",
622 >                fprintf(fp, "0\n0\n4 %g %g %g -1\n",
623                                  lampcolor[0]/shp->area,
624                                  lampcolor[1]/shp->area,
625                                  lampcolor[2]/shp->area);
# Line 812 | Line 823 | double mult, lim[][2];
823          for (i = 0; i < ndim; i++) {
824                  pt[i] = (double *)malloc(npts[i]*sizeof(double));
825                  for (j = 0; j < npts[i]; j++)
826 <                        fscanf(in, "%lf", &pt[i][j]);
826 >                        if (!scnflt(in, &pt[i][j]))
827 >                                return(-1);
828                  if (lim != NULL) {
829                          lim[i][0] = pt[i][0];
830                          lim[i][1] = pt[i][npts[i]-1];
# Line 843 | Line 855 | double mult, lim[][2];
855          for (i = 0; i < total; i++) {
856                  if (i%4 == 0)
857                          putc('\n', out);
858 <                if (fscanf(in, "%lf", &val) != 1)
858 >                if (!scnflt(in, &val))
859                          return(-1);
860                  fprintf(out, "\t%g", val*mult);
861          }
862          putc('\n', out);
863          return(0);
864 + }
865 +
866 +
867 + char *
868 + getword(fp)                     /* scan a word from fp */
869 + register FILE   *fp;
870 + {
871 +        static char     word[MAXWORD];
872 +        register char   *cp;
873 +        register int    c;
874 +
875 +        while (isspace(c=getc(fp)))
876 +                ;
877 +        for (cp = word; c != EOF && cp < word+MAXWORD-1;
878 +                        *cp++ = c, c = getc(fp))
879 +                if (isspace(c) || c == ',') {
880 +                        while (isspace(c))
881 +                                c = getc(fp);
882 +                        if (c != EOF & c != ',')
883 +                                ungetc(c, fp);
884 +                        *cp = '\0';
885 +                        return(word);
886 +                }
887 +        *cp = '\0';
888 +        return(cp > word ? word : NULL);
889 + }
890 +
891 +
892 + cvtint(ip, word)                /* convert a word to an integer */
893 + int     *ip;
894 + char    *word;
895 + {
896 +        if (word == NULL || !isint(word))
897 +                return(0);
898 +        *ip = atoi(word);
899 +        return(1);
900 + }
901 +
902 +
903 + cvtflt(rp, word)                /* convert a word to a double */
904 + double  *rp;
905 + char    *word;
906 + {
907 +        if (word == NULL || !isflt(word))
908 +                return(0);
909 +        *rp = atof(word);
910 +        return(1);
911   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines