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.5 by greg, Mon Feb 22 15:54:55 1993 UTC vs.
Revision 2.6 by greg, Thu Mar 18 11:21:21 1993 UTC

# Line 76 | 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();
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 407 | 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 464 | 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 516 | 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 812 | 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 843 | 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