11 |
|
*/ |
12 |
|
|
13 |
|
#include <stdio.h> |
14 |
+ |
#include <math.h> |
15 |
|
#include <ctype.h> |
16 |
|
#include "color.h" |
17 |
|
#include "paths.h" |
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[]; |
413 |
|
fprintf(stderr, "%s: not in IES format\n", inpname); |
414 |
|
goto readerr; |
415 |
|
} |
416 |
< |
sscanf(buf+TLTSTRLEN, "%s", tltid); |
416 |
> |
atos(tltid, MAXWORD, buf+TLTSTRLEN); |
417 |
|
if (inpfp == stdin) |
418 |
|
buf[0] = '\0'; |
419 |
|
else |
470 |
|
fclose(datin); |
471 |
|
return(-1); |
472 |
|
} |
473 |
< |
if (fscanf(datin, "%d %d", &tlt_type, &nangles) != 2 |
473 |
> |
if (!scnint(datin,&tlt_type) || !scnint(datin,&nangles) |
474 |
|
|| cvdata(datin,datout,1,&nangles,1.,minmax) != 0) { |
475 |
|
fprintf(stderr, "%s: data format error\n", tltspec); |
476 |
|
fclose(datout); |
522 |
|
int nangles[2], pmtype, unitype; |
523 |
|
double d1; |
524 |
|
|
525 |
< |
if (fscanf(in, "%*d %*f %lf %d %d %d %d %lf %lf %lf %lf %lf %lf", |
526 |
< |
&mult, &nangles[0], &nangles[1], &pmtype, &unitype, |
527 |
< |
&width, &length, &height, &bfactor, &pfactor, |
528 |
< |
&wattage) != 11) { |
525 |
> |
if (!isint(getword(in)) || !isflt(getword(in)) || !scnflt(in,&mult) |
526 |
> |
|| !scnint(in,&nangles[0]) || !scnint(in,&nangles[1]) |
527 |
> |
|| !scnint(in,&pmtype) || !scnint(in,&unitype) |
528 |
> |
|| !scnflt(in,&width) || !scnflt(in,&length) |
529 |
> |
|| !scnflt(in,&height) || !scnflt(in,&bfactor) |
530 |
> |
|| !scnflt(in,&pfactor) || !scnflt(in,&wattage)) { |
531 |
|
fprintf(stderr, "dosource: bad lamp specification\n"); |
532 |
|
return(-1); |
533 |
|
} |
564 |
|
else if (pmtype == PM_B) |
565 |
|
fprintf(out, "5 "); |
566 |
|
else if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
567 |
< |
fprintf(out, "8 "); |
567 |
> |
fprintf(out, "7 "); |
568 |
|
else |
569 |
< |
fprintf(out, "6 "); |
569 |
> |
fprintf(out, "5 "); |
570 |
|
fprintf(out, "%s %s source.cal ", |
571 |
|
srcshape.type==SPHERE ? "corr" : "flatcorr", |
572 |
|
libname(buf,name,T_DST)); |
585 |
|
fprintf(out, "src_phi2 "); |
586 |
|
else |
587 |
|
fprintf(out, "src_phi "); |
588 |
< |
fprintf(out, "src_theta -my "); |
588 |
> |
fprintf(out, "src_theta "); |
589 |
|
if (FEQ(bounds[1][0],90.) && FEQ(bounds[1][1],270.)) |
590 |
|
fprintf(out, "-rz -90 "); |
591 |
|
} else |
616 |
|
lampcolor[2]/shp->area); |
617 |
|
if (doupper && dolower && shp->type != SPHERE && shp->h > MINDIM) { |
618 |
|
fprintf(fp, "\n%s glow %s_glow\n", mod, name); |
619 |
< |
fprintf(fp, "0\n0\n4 %g %g %g 0\n", |
619 |
> |
fprintf(fp, "0\n0\n4 %g %g %g -1\n", |
620 |
|
lampcolor[0]/shp->area, |
621 |
|
lampcolor[1]/shp->area, |
622 |
|
lampcolor[2]/shp->area); |
820 |
|
for (i = 0; i < ndim; i++) { |
821 |
|
pt[i] = (double *)malloc(npts[i]*sizeof(double)); |
822 |
|
for (j = 0; j < npts[i]; j++) |
823 |
< |
fscanf(in, "%lf", &pt[i][j]); |
823 |
> |
if (!scnflt(in, &pt[i][j])) |
824 |
> |
return(-1); |
825 |
|
if (lim != NULL) { |
826 |
|
lim[i][0] = pt[i][0]; |
827 |
|
lim[i][1] = pt[i][npts[i]-1]; |
852 |
|
for (i = 0; i < total; i++) { |
853 |
|
if (i%4 == 0) |
854 |
|
putc('\n', out); |
855 |
< |
if (fscanf(in, "%lf", &val) != 1) |
855 |
> |
if (!scnflt(in, &val)) |
856 |
|
return(-1); |
857 |
|
fprintf(out, "\t%g", val*mult); |
858 |
|
} |
859 |
|
putc('\n', out); |
860 |
|
return(0); |
861 |
+ |
} |
862 |
+ |
|
863 |
+ |
|
864 |
+ |
char * |
865 |
+ |
getword(fp) /* scan a word from fp */ |
866 |
+ |
register FILE *fp; |
867 |
+ |
{ |
868 |
+ |
static char word[MAXWORD]; |
869 |
+ |
register char *cp; |
870 |
+ |
register int c; |
871 |
+ |
|
872 |
+ |
while (isspace(c=getc(fp))) |
873 |
+ |
; |
874 |
+ |
for (cp = word; c != EOF && cp < word+MAXWORD-1; |
875 |
+ |
*cp++ = c, c = getc(fp)) |
876 |
+ |
if (isspace(c) || c == ',') { |
877 |
+ |
while (isspace(c)) |
878 |
+ |
c = getc(fp); |
879 |
+ |
if (c != EOF & c != ',') |
880 |
+ |
ungetc(c, fp); |
881 |
+ |
*cp = '\0'; |
882 |
+ |
return(word); |
883 |
+ |
} |
884 |
+ |
*cp = '\0'; |
885 |
+ |
return(cp > word ? word : NULL); |
886 |
+ |
} |
887 |
+ |
|
888 |
+ |
|
889 |
+ |
cvtint(ip, word) /* convert a word to an integer */ |
890 |
+ |
int *ip; |
891 |
+ |
char *word; |
892 |
+ |
{ |
893 |
+ |
if (word == NULL || !isint(word)) |
894 |
+ |
return(0); |
895 |
+ |
*ip = atoi(word); |
896 |
+ |
return(1); |
897 |
+ |
} |
898 |
+ |
|
899 |
+ |
|
900 |
+ |
cvtflt(rp, word) /* convert a word to a double */ |
901 |
+ |
double *rp; |
902 |
+ |
char *word; |
903 |
+ |
{ |
904 |
+ |
if (word == NULL || !isflt(word)) |
905 |
+ |
return(0); |
906 |
+ |
*rp = atof(word); |
907 |
+ |
return(1); |
908 |
|
} |